blob: 84c20f681d0aa0ac7cca0f81db9417727d5cc859 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800332 // Parameters of select command.
333 private static final int SELECT_COMMAND = 0xA4;
334 private static final int SELECT_P1 = 0x04;
335 private static final int SELECT_P2 = 0;
336 private static final int SELECT_P3 = 0x10;
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 /** The singleton instance. */
339 private static PhoneInterfaceManager sInstance;
340
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800343 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700344 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800345 private AppOpsManager mAppOps;
346 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800347 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800348 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700349 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 /** User Activity */
352 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
354
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700355 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
356
Derek Tan97ebb422014-09-05 16:55:38 -0700357 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
358 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800359 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800360 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700361
Michelecea4cf22018-12-21 15:00:11 -0800362 // String to store multi SIM allowed
363 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
364
Derek Tan740e1672017-06-27 14:56:27 -0700365 // The AID of ISD-R.
366 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
367
yinxub1bed742017-04-17 11:45:04 -0700368 private NetworkScanRequestTracker mNetworkScanRequestTracker;
369
David Kelly5e06a7f2018-03-12 14:10:59 +0000370 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
371 private static final int MANUFACTURER_CODE_LENGTH = 8;
372
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800373 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
374
Derek Tan89e89d42014-07-08 17:00:10 -0700375 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700376 * Experiment flag to enable erase modem config on reset network, default value is false
377 */
378 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
379 "reset_network_erase_modem_config_enabled";
380
381 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700382 * A request object to use for transmitting data to an ICC.
383 */
384 private static final class IccAPDUArgument {
385 public int channel, cla, command, p1, p2, p3;
386 public String data;
387
388 public IccAPDUArgument(int channel, int cla, int command,
389 int p1, int p2, int p3, String data) {
390 this.channel = channel;
391 this.cla = cla;
392 this.command = command;
393 this.p1 = p1;
394 this.p2 = p2;
395 this.p3 = p3;
396 this.data = data;
397 }
398 }
399
400 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class ManualNetworkSelectionArgument {
404 public OperatorInfo operatorInfo;
405 public boolean persistSelection;
406
407 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
408 this.operatorInfo = operatorInfo;
409 this.persistSelection = persistSelection;
410 }
411 }
412
413 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
415 * request after sending. The main thread will notify the request when it is complete.
416 */
417 private static final class MainThreadRequest {
418 /** The argument to use for the request */
419 public Object argument;
420 /** The result of the request that is run on the main thread */
421 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800422 // The subscriber id that this request applies to. Defaults to
423 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
424 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425
Nathan Harold92bed182018-10-12 18:16:49 -0700426 // In cases where subId is unavailable, the caller needs to specify the phone.
427 public Phone phone;
428
vagdeviaf9a5b92018-08-15 16:01:53 -0700429 public WorkSource workSource;
430
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 public MainThreadRequest(Object argument) {
432 this.argument = argument;
433 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800434
Nathan Harold92bed182018-10-12 18:16:49 -0700435 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
436 this.argument = argument;
437 if (phone != null) {
438 this.phone = phone;
439 }
440 this.workSource = workSource;
441 }
442
vagdeviaf9a5b92018-08-15 16:01:53 -0700443 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 if (subId != null) {
446 this.subId = subId;
447 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 }
451
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800452 private static final class IncomingThirdPartyCallArgs {
453 public final ComponentName component;
454 public final String callId;
455 public final String callerDisplayName;
456
457 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
458 String callerDisplayName) {
459 this.component = component;
460 this.callId = callId;
461 this.callerDisplayName = callerDisplayName;
462 }
463 }
464
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 /**
466 * A handler that processes messages on the main thread in the phone process. Since many
467 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
468 * inbound binder threads to the main thread in the phone process. The Binder thread
469 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
470 * on, which will be notified when the operation completes and will contain the result of the
471 * request.
472 *
473 * <p>If a MainThreadRequest object is provided in the msg.obj field,
474 * note that request.result must be set to something non-null for the calling thread to
475 * unblock.
476 */
477 private final class MainThreadHandler extends Handler {
478 @Override
479 public void handleMessage(Message msg) {
480 MainThreadRequest request;
481 Message onCompleted;
482 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800485 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
487 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 case CMD_HANDLE_USSD_REQUEST: {
489 request = (MainThreadRequest) msg.obj;
490 final Phone phone = getPhoneFromRequest(request);
491 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
492 String ussdRequest = ussdObject.first;
493 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700494
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 if (!isUssdApiAllowed(request.subId)) {
496 // Carrier does not support use of this API, return failure.
497 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
498 UssdResponse response = new UssdResponse(ussdRequest, null);
499 Bundle returnData = new Bundle();
500 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
501 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700502
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 request.result = true;
504 notifyRequester(request);
505 return;
506 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700507
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 try {
509 request.result = phone != null
510 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
511 } catch (CallStateException cse) {
512 request.result = false;
513 }
514 // Wake up the requesting thread
515 notifyRequester(request);
516 break;
pkanwar32d516d2016-10-14 19:37:38 -0700517 }
518
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700521 final Phone phone = getPhoneFromRequest(request);
522 request.result = phone != null ?
523 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
524 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800533 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 if (uiccCard == null) {
535 loge("iccTransmitApduLogicalChannel: No UICC");
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
540 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 iccArgument.channel, iccArgument.cla, iccArgument.command,
543 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 break;
547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
555 if (ar.result == null) {
556 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800557 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800559 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 } else {
561 loge("iccTransmitApduLogicalChannel: Unknown exception");
562 }
563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
568 request = (MainThreadRequest) msg.obj;
569 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800570 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 if (uiccCard == null) {
572 loge("iccTransmitApduBasicChannel: No UICC");
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 } else {
576 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
577 request);
578 uiccCard.iccTransmitApduBasicChannel(
579 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
580 iccArgument.p3, iccArgument.data, onCompleted);
581 }
582 break;
583
584 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
587 if (ar.exception == null && ar.result != null) {
588 request.result = ar.result;
589 } else {
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
591 if (ar.result == null) {
592 loge("iccTransmitApduBasicChannel: Empty response");
593 } else if (ar.exception instanceof CommandException) {
594 loge("iccTransmitApduBasicChannel: CommandException: " +
595 ar.exception);
596 } else {
597 loge("iccTransmitApduBasicChannel: Unknown exception");
598 }
599 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 break;
602
603 case CMD_EXCHANGE_SIM_IO:
604 request = (MainThreadRequest) msg.obj;
605 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800606 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 if (uiccCard == null) {
608 loge("iccExchangeSimIO: No UICC");
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 } else {
612 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
613 request);
614 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
615 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
616 iccArgument.data, onCompleted);
617 }
618 break;
619
620 case EVENT_EXCHANGE_SIM_IO_DONE:
621 ar = (AsyncResult) msg.obj;
622 request = (MainThreadRequest) ar.userObj;
623 if (ar.exception == null && ar.result != null) {
624 request.result = ar.result;
625 } else {
626 request.result = new IccIoResult(0x6f, 0, (byte[])null);
627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 break;
630
Derek Tan4d5e5c12014-02-04 11:54:58 -0800631 case CMD_SEND_ENVELOPE:
632 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800633 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 if (uiccCard == null) {
635 loge("sendEnvelopeWithStatus: No UICC");
636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
640 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
641 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 break;
643
644 case EVENT_SEND_ENVELOPE_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800649 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700650 request.result = new IccIoResult(0x6F, 0, (byte[])null);
651 if (ar.result == null) {
652 loge("sendEnvelopeWithStatus: Empty response");
653 } else if (ar.exception instanceof CommandException) {
654 loge("sendEnvelopeWithStatus: CommandException: " +
655 ar.exception);
656 } else {
657 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
658 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 case CMD_OPEN_CHANNEL:
664 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800665 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800666 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 if (uiccCard == null) {
668 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800669 request.result = new IccOpenLogicalChannelResponse(-1,
670 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800674 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
675 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case EVENT_OPEN_CHANNEL_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 int[] result = (int[]) ar.result;
685 int channelId = result[0];
686 byte[] selectResponse = null;
687 if (result.length > 1) {
688 selectResponse = new byte[result.length - 1];
689 for (int i = 1; i < result.length; ++i) {
690 selectResponse[i - 1] = (byte) result[i];
691 }
692 }
693 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 if (ar.result == null) {
697 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 if (ar.exception != null) {
700 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
701 }
702
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700704 if (ar.exception instanceof CommandException) {
705 CommandException.Error error =
706 ((CommandException) (ar.exception)).getCommandError();
707 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700709 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 }
712 }
713 openChannelResp = new IccOpenLogicalChannelResponse(
714 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700716 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
720 case CMD_CLOSE_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800722 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 if (uiccCard == null) {
724 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900725 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
729 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
730 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 break;
732
733 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800734 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
735 break;
736
737 case CMD_NV_READ_ITEM:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800740 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
741 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800742 break;
743
744 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800747 if (ar.exception == null && ar.result != null) {
748 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800750 request.result = "";
751 if (ar.result == null) {
752 loge("nvReadItem: Empty response");
753 } else if (ar.exception instanceof CommandException) {
754 loge("nvReadItem: CommandException: " +
755 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800757 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 }
759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
Jake Hambye994d462014-02-03 13:10:13 -0800763 case CMD_NV_WRITE_ITEM:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
766 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800767 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700768 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800769 break;
770
771 case EVENT_NV_WRITE_ITEM_DONE:
772 handleNullReturnEvent(msg, "nvWriteItem");
773 break;
774
775 case CMD_NV_WRITE_CDMA_PRL:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800778 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800779 break;
780
781 case EVENT_NV_WRITE_CDMA_PRL_DONE:
782 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
783 break;
784
chen xu6dac5ab2018-10-26 17:39:23 -0700785 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800786 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700787 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800788 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
chen xu6dac5ab2018-10-26 17:39:23 -0700791 case EVENT_RESET_MODEM_CONFIG_DONE:
792 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
Sooraj Sasindran37444802020-08-11 10:40:43 -0700795 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
798 request);
799 Phone phone = getPhoneFromRequest(request);
800 if (phone != null) {
801 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
802 } else {
803 loge("isNRDualConnectivityEnabled: No phone object");
804 request.result = false;
805 notifyRequester(request);
806 }
807 break;
808 }
809
810 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
811 ar = (AsyncResult) msg.obj;
812 request = (MainThreadRequest) ar.userObj;
813 if (ar.exception == null && ar.result != null) {
814 request.result = ar.result;
815 } else {
816 // request.result must be set to something non-null
817 // for the calling thread to unblock
818 if (request.result != null) {
819 request.result = ar.result;
820 } else {
821 request.result = false;
822 }
823 if (ar.result == null) {
824 loge("isNRDualConnectivityEnabled: Empty response");
825 } else if (ar.exception instanceof CommandException) {
826 loge("isNRDualConnectivityEnabled: CommandException: "
827 + ar.exception);
828 } else {
829 loge("isNRDualConnectivityEnabled: Unknown exception");
830 }
831 }
832 notifyRequester(request);
833 break;
834
835 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
838 Phone phone = getPhoneFromRequest(request);
839 if (phone != null) {
840 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
841 request.workSource);
842 } else {
843 loge("enableNrDualConnectivity: No phone object");
844 request.result =
845 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
846 notifyRequester(request);
847 }
848 break;
849 }
850
851 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result =
856 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
857 } else {
858 request.result =
859 TelephonyManager
860 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
861 if (ar.exception instanceof CommandException) {
862 CommandException.Error error =
863 ((CommandException) (ar.exception)).getCommandError();
864 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
865 request.result =
866 TelephonyManager
867 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
868 }
869 loge("enableNrDualConnectivity" + ": CommandException: "
870 + ar.exception);
871 } else {
872 loge("enableNrDualConnectivity" + ": Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877 }
878
SongFerngWang3ef3e072020-12-21 16:41:52 +0800879 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800881 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
882 request);
883 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800884 break;
885
SongFerngWang3ef3e072020-12-21 16:41:52 +0800886 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result; // Integer
891 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530892 // request.result must be set to something non-null
893 // for the calling thread to unblock
894 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800896 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800898 loge("getAllowedNetworkTypesBitmask: CommandException: "
899 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 }
903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 break;
906
SongFerngWang3ef3e072020-12-21 16:41:52 +0800907 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
910 request);
911 Pair<Integer, Long> reasonWithNetworkTypes =
912 (Pair<Integer, Long>) request.argument;
913 getPhoneFromRequest(request).setAllowedNetworkTypes(
914 reasonWithNetworkTypes.first,
915 reasonWithNetworkTypes.second,
916 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 break;
918
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
920 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 break;
922
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000923 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
924 request = (MainThreadRequest)msg.obj;
925 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000927 break;
928
929 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
930 ar = (AsyncResult)msg.obj;
931 request = (MainThreadRequest)ar.userObj;
932 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000934 break;
935
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800936 case CMD_SET_VOICEMAIL_NUMBER:
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
939 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800940 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
941 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800942 break;
943
944 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
945 handleNullReturnEvent(msg, "setVoicemailNumber");
946 break;
947
Stuart Scott54788802015-03-30 13:18:01 -0700948 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
951 request);
952 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
953 break;
954
955 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
956 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
957 break;
958
Shishir Agrawal302c8692015-06-19 13:49:39 -0700959 case CMD_PERFORM_NETWORK_SCAN:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
962 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
963 break;
964
Hall Liu27d24262020-09-18 19:04:59 -0700965 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700968 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
969 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
970 request.argument;
971 int callForwardingReason = args.first;
972 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800973 break;
Hall Liu27d24262020-09-18 19:04:59 -0700974 }
975 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700978 TelephonyManager.CallForwardingInfoCallback callback =
979 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
980 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800981 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700982 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800983 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
984 for (CallForwardInfo callForwardInfo : callForwardInfos) {
985 // Service Class is a bit mask per 3gpp 27.007. Search for
986 // any service for voice call.
987 if ((callForwardInfo.serviceClass
988 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700989 callForwardingInfo = new CallForwardingInfo(true,
990 callForwardInfo.reason,
991 callForwardInfo.number,
992 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800993 break;
994 }
995 }
996 // Didn't find a call forward info for voice call.
997 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700998 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
999 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001000 }
Hall Liu27d24262020-09-18 19:04:59 -07001001 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001002 } else {
1003 if (ar.result == null) {
1004 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1005 }
1006 if (ar.exception != null) {
1007 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1008 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001009 int errorCode = TelephonyManager
1010 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001011 if (ar.exception instanceof CommandException) {
1012 CommandException.Error error =
1013 ((CommandException) (ar.exception)).getCommandError();
1014 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001015 errorCode = TelephonyManager
1016 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001020 }
1021 }
Hall Liu27d24262020-09-18 19:04:59 -07001022 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 }
Shuo Qian4a594052020-01-23 11:59:30 -08001024 break;
Hall Liu27d24262020-09-18 19:04:59 -07001025 }
Shuo Qian4a594052020-01-23 11:59:30 -08001026
Hall Liu27d24262020-09-18 19:04:59 -07001027 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001030 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001031 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001032 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1033 request.argument).first;
1034 request.phone.setCallForwardingOption(
1035 callForwardingInfoToSet.isEnabled()
1036 ? CommandsInterface.CF_ACTION_ENABLE
1037 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001038 callForwardingInfoToSet.getReason(),
1039 callForwardingInfoToSet.getNumber(),
1040 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1041 break;
Hall Liu27d24262020-09-18 19:04:59 -07001042 }
Shuo Qian4a594052020-01-23 11:59:30 -08001043
Hall Liu27d24262020-09-18 19:04:59 -07001044 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001047 Consumer<Integer> callback =
1048 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1049 request.argument).second;
1050 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001051 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001052 int errorCode = TelephonyManager.CallForwardingInfoCallback
1053 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001054 if (ar.exception instanceof CommandException) {
1055 CommandException.Error error =
1056 ((CommandException) (ar.exception)).getCommandError();
1057 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001058 errorCode = TelephonyManager.CallForwardingInfoCallback
1059 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001061 errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001063 }
1064 }
1065 callback.accept(errorCode);
1066 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001067 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001068 }
Shuo Qian4a594052020-01-23 11:59:30 -08001069 break;
Hall Liu27d24262020-09-18 19:04:59 -07001070 }
Shuo Qian4a594052020-01-23 11:59:30 -08001071
Hall Liu27d24262020-09-18 19:04:59 -07001072 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001073 request = (MainThreadRequest) msg.obj;
1074 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1075 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1076 break;
Hall Liu27d24262020-09-18 19:04:59 -07001077 }
Shuo Qian4a594052020-01-23 11:59:30 -08001078
Hall Liu27d24262020-09-18 19:04:59 -07001079 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001082 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001083 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1084 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001085 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001086 // Service Class is a bit mask per 3gpp 27.007.
1087 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001088 if (callForwardResults.length > 1
1089 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001090 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001091 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001092 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1093 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001095 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001096 }
1097 } else {
1098 if (ar.result == null) {
1099 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1100 }
1101 if (ar.exception != null) {
1102 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1103 }
1104 if (ar.exception instanceof CommandException) {
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 callForwardingStatus =
1109 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1110 }
1111 }
1112 }
Hall Liu27d24262020-09-18 19:04:59 -07001113 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 break;
Hall Liu27d24262020-09-18 19:04:59 -07001115 }
Shuo Qian4a594052020-01-23 11:59:30 -08001116
Hall Liu27d24262020-09-18 19:04:59 -07001117 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001118 request = (MainThreadRequest) msg.obj;
1119 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001120 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1121 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001122 break;
Hall Liu27d24262020-09-18 19:04:59 -07001123 }
Shuo Qian4a594052020-01-23 11:59:30 -08001124
Hall Liu27d24262020-09-18 19:04:59 -07001125 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001128 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1129 Consumer<Integer> callback =
1130 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1131 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001132 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001133 if (ar.exception instanceof CommandException) {
1134 CommandException.Error error =
1135 ((CommandException) (ar.exception)).getCommandError();
1136 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1137 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1138 } else {
1139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1140 }
1141 } else {
1142 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1143 }
1144 } else {
1145 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1146 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001147 }
Shuo Qian4a594052020-01-23 11:59:30 -08001148 break;
Hall Liu27d24262020-09-18 19:04:59 -07001149 }
Shuo Qian4a594052020-01-23 11:59:30 -08001150
Shishir Agrawal302c8692015-06-19 13:49:39 -07001151 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 CellNetworkScanResult cellScanResult;
1155 if (ar.exception == null && ar.result != null) {
1156 cellScanResult = new CellNetworkScanResult(
1157 CellNetworkScanResult.STATUS_SUCCESS,
1158 (List<OperatorInfo>) ar.result);
1159 } else {
1160 if (ar.result == null) {
1161 loge("getCellNetworkScanResults: Empty response");
1162 }
1163 if (ar.exception != null) {
1164 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1165 }
1166 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1167 if (ar.exception instanceof CommandException) {
1168 CommandException.Error error =
1169 ((CommandException) (ar.exception)).getCommandError();
1170 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1171 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1172 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1173 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1174 }
1175 }
1176 cellScanResult = new CellNetworkScanResult(errorCode, null);
1177 }
1178 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001179 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 break;
1181
1182 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1183 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001184 ManualNetworkSelectionArgument selArg =
1185 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001186 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1187 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001188 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1189 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001190 break;
1191
1192 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
1195 if (ar.exception == null) {
1196 request.result = true;
1197 } else {
1198 request.result = false;
1199 loge("setNetworkSelectionModeManual " + ar.exception);
1200 }
1201 notifyRequester(request);
1202 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 break;
1204
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001205 case CMD_GET_MODEM_ACTIVITY_INFO:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001208 if (defaultPhone != null) {
1209 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001210 } else {
1211 ResultReceiver result = (ResultReceiver) request.argument;
1212 Bundle bundle = new Bundle();
1213 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001214 new ModemActivityInfo(0, 0, 0,
1215 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001216 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001217 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001218 break;
1219
Hall Liud0f208c2020-10-14 16:54:44 -07001220 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001221 ar = (AsyncResult) msg.obj;
1222 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001223 ResultReceiver result = (ResultReceiver) request.argument;
1224
Hall Liud0f208c2020-10-14 16:54:44 -07001225 ModemActivityInfo ret = null;
1226 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001228 // Update the last modem activity info and the result of the request.
1229 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1230 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001231 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 int[] txTimeMs = info.getTransmitTimeMillis();
1233 int[] lastModemTxTimeMs = mLastModemActivityInfo
1234 .getTransmitTimeMillis();
1235 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1236 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1237 }
Hall Liu49656c02020-10-09 19:00:11 -07001238 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001239 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1240 + mLastModemActivityInfo.getSleepTimeMillis());
1241 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1242 + mLastModemActivityInfo.getIdleTimeMillis());
1243 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1244 mLastModemActivityInfo.setReceiveTimeMillis(
1245 info.getReceiveTimeMillis()
1246 + mLastModemActivityInfo.getReceiveTimeMillis());
1247 }
Hall Liu49656c02020-10-09 19:00:11 -07001248 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001249 mLastModemActivityInfo.getSleepTimeMillis(),
1250 mLastModemActivityInfo.getIdleTimeMillis(),
1251 mLastModemActivityInfo.getTransmitTimeMillis(),
1252 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 } else {
1254 if (ar.result == null) {
1255 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001256 error = TelephonyManager.ModemActivityInfoException
1257 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001258 } else if (ar.exception instanceof CommandException) {
1259 loge("queryModemActivityInfo: CommandException: " +
1260 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001261 error = TelephonyManager.ModemActivityInfoException
1262 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001263 } else {
1264 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001265 error = TelephonyManager.ModemActivityInfoException
1266 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 }
1268 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001269 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001270 if (ret != null) {
1271 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1272 } else {
1273 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1274 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001275 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001276 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001278 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001279
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 case CMD_SET_ALLOWED_CARRIERS:
1281 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001282 CarrierRestrictionRules argument =
1283 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001285 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 break;
1287
1288 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
1291 if (ar.exception == null && ar.result != null) {
1292 request.result = ar.result;
1293 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001294 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1295 if (ar.exception instanceof CommandException) {
1296 loge("setAllowedCarriers: CommandException: " + ar.exception);
1297 CommandException.Error error =
1298 ((CommandException) (ar.exception)).getCommandError();
1299 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1300 request.result =
1301 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1302 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 } else {
1304 loge("setAllowedCarriers: Unknown exception");
1305 }
1306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001307 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 break;
1309
1310 case CMD_GET_ALLOWED_CARRIERS:
1311 request = (MainThreadRequest) msg.obj;
1312 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001313 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001314 break;
1315
1316 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
1319 if (ar.exception == null && ar.result != null) {
1320 request.result = ar.result;
1321 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001322 request.result = new IllegalStateException(
1323 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001324 if (ar.result == null) {
1325 loge("getAllowedCarriers: Empty response");
1326 } else if (ar.exception instanceof CommandException) {
1327 loge("getAllowedCarriers: CommandException: " +
1328 ar.exception);
1329 } else {
1330 loge("getAllowedCarriers: Unknown exception");
1331 }
1332 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001333 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001334 break;
1335
Nathan Haroldb3014052017-01-25 15:57:32 -08001336 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
1339 if (ar.exception == null && ar.result != null) {
1340 request.result = ar.result;
1341 } else {
1342 request.result = new IllegalArgumentException(
1343 "Failed to retrieve Forbidden Plmns");
1344 if (ar.result == null) {
1345 loge("getForbiddenPlmns: Empty response");
1346 } else {
1347 loge("getForbiddenPlmns: Unknown exception");
1348 }
1349 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001351 break;
1352
1353 case CMD_GET_FORBIDDEN_PLMNS:
1354 request = (MainThreadRequest) msg.obj;
1355 uiccCard = getUiccCardFromRequest(request);
1356 if (uiccCard == null) {
1357 loge("getForbiddenPlmns() UiccCard is null");
1358 request.result = new IllegalArgumentException(
1359 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001360 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001361 break;
1362 }
1363 Integer appType = (Integer) request.argument;
1364 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1365 if (uiccApp == null) {
1366 loge("getForbiddenPlmns() no app with specified type -- "
1367 + appType);
1368 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371 } else {
1372 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1373 + " specified type -- " + appType);
1374 }
1375 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1376 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1377 onCompleted);
1378 break;
1379
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001380 case CMD_SWITCH_SLOTS:
1381 request = (MainThreadRequest) msg.obj;
1382 int[] physicalSlots = (int[]) request.argument;
1383 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1384 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1385 break;
1386
1387 case EVENT_SWITCH_SLOTS_DONE:
1388 ar = (AsyncResult) msg.obj;
1389 request = (MainThreadRequest) ar.userObj;
1390 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
1392 break;
1393 case CMD_GET_NETWORK_SELECTION_MODE:
1394 request = (MainThreadRequest) msg.obj;
1395 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1396 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1397 break;
1398
1399 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception != null) {
1403 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1404 } else {
1405 int mode = ((int[]) ar.result)[0];
1406 if (mode == 0) {
1407 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1408 } else {
1409 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1410 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001411 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
1413 break;
1414 case CMD_GET_CDMA_ROAMING_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1417 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1418 break;
1419 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception != null) {
1423 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1424 } else {
1425 request.result = ((int[]) ar.result)[0];
1426 }
1427 notifyRequester(request);
1428 break;
1429 case CMD_SET_CDMA_ROAMING_MODE:
1430 request = (MainThreadRequest) msg.obj;
1431 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1432 int mode = (int) request.argument;
1433 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1434 break;
1435 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
1438 request.result = ar.exception == null;
1439 notifyRequester(request);
1440 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001441 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1444 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1445 break;
1446 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception != null) {
1450 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1451 } else {
1452 request.result = ((int[]) ar.result)[0];
1453 }
1454 notifyRequester(request);
1455 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001456 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1457 request = (MainThreadRequest) msg.obj;
1458 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1459 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001460 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1461 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001462 break;
1463 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
1466 request.result = ar.exception == null;
1467 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001468 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 case CMD_GET_ALL_CELL_INFO:
1470 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001471 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001472 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001473 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 case EVENT_GET_ALL_CELL_INFO_DONE:
1475 ar = (AsyncResult) msg.obj;
1476 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001477 // If a timeout occurs, the response will be null
1478 request.result = (ar.exception == null && ar.result != null)
1479 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001480 synchronized (request) {
1481 request.notifyAll();
1482 }
1483 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 case CMD_REQUEST_CELL_INFO_UPDATE:
1485 request = (MainThreadRequest) msg.obj;
1486 request.phone.requestCellInfoUpdate(request.workSource,
1487 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1488 break;
1489 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1490 ar = (AsyncResult) msg.obj;
1491 request = (MainThreadRequest) ar.userObj;
1492 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1493 try {
1494 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001495 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001496 cb.onError(
1497 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1498 ar.exception.getClass().getName(),
1499 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001500 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001501 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001502 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001503 } else {
1504 // use the result as returned
1505 cb.onCellInfo((List<CellInfo>) ar.result);
1506 }
1507 } catch (RemoteException re) {
1508 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1509 }
1510 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001511 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001512 request = (MainThreadRequest) msg.obj;
1513 WorkSource ws = (WorkSource) request.argument;
1514 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001515 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001516 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001517 }
1518 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 if (ar.exception == null) {
1522 request.result = ar.result;
1523 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001524 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001526 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001527 }
1528
1529 synchronized (request) {
1530 request.notifyAll();
1531 }
1532 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001533 }
chen xu6dac5ab2018-10-26 17:39:23 -07001534 case CMD_MODEM_REBOOT:
1535 request = (MainThreadRequest) msg.obj;
1536 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001537 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001538 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001539 case EVENT_CMD_MODEM_REBOOT_DONE:
1540 handleNullReturnEvent(msg, "rebootModem");
1541 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001542 case CMD_REQUEST_ENABLE_MODEM:
1543 request = (MainThreadRequest) msg.obj;
1544 boolean enable = (boolean) request.argument;
1545 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001546 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001547 PhoneConfigurationManager.getInstance()
1548 .enablePhone(request.phone, enable, onCompleted);
1549 break;
1550 case EVENT_ENABLE_MODEM_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001554 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001555 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001556 if ((boolean) request.result) {
1557 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1558 updateModemStateMetrics();
1559 } else {
1560 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1561 + ar.exception);
1562 }
1563 notifyRequester(request);
1564 break;
1565 case CMD_GET_MODEM_STATUS:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1568 PhoneConfigurationManager.getInstance()
1569 .getPhoneStatusFromModem(request.phone, onCompleted);
1570 break;
1571 case EVENT_GET_MODEM_STATUS_DONE:
1572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 int id = request.phone.getPhoneId();
1575 if (ar.exception == null && ar.result != null) {
1576 request.result = ar.result;
1577 //update the cache as modem status has changed
1578 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1579 (boolean) request.result);
1580 } else {
1581 // Return true if modem status cannot be retrieved. For most cases,
1582 // modem status is on. And for older version modems, GET_MODEM_STATUS
1583 // and disable modem are not supported. Modem is always on.
1584 // TODO: this should be fixed in R to support a third
1585 // status UNKNOWN b/131631629
1586 request.result = true;
1587 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1588 + ar.exception);
1589 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001590 notifyRequester(request);
1591 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001592 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1595 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1596 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1597 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1598 break;
1599 }
1600 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1604 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1605 args.second.accept(ar.exception == null);
1606 notifyRequester(request);
1607 break;
1608 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001609 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1610 request = (MainThreadRequest) msg.obj;
1611 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1612 Phone phone = getPhoneFromRequest(request);
1613 if (phone != null) {
1614 phone.getSystemSelectionChannels(onCompleted);
1615 } else {
1616 loge("getSystemSelectionChannels: No phone object");
1617 request.result = new ArrayList<RadioAccessSpecifier>();
1618 notifyRequester(request);
1619 }
1620 break;
1621 }
1622 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception == null && ar.result != null) {
1626 request.result = ar.result;
1627 } else {
1628 request.result = new IllegalArgumentException(
1629 "Failed to retrieve system selection channels");
1630 if (ar.result == null) {
1631 loge("getSystemSelectionChannels: Empty response");
1632 } else {
1633 loge("getSystemSelectionChannels: Unknown exception");
1634 }
1635 }
1636 notifyRequester(request);
1637 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001638 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1639 ar = (AsyncResult) msg.obj;
1640 request = (MainThreadRequest) ar.userObj;
1641 if (ar.exception == null && ar.result != null) {
1642 request.result = ar.result;
1643 } else {
1644 request.result = -1;
1645 loge("Failed to set Forbidden Plmns");
1646 if (ar.result == null) {
1647 loge("setForbidenPlmns: Empty response");
1648 } else if (ar.exception != null) {
1649 loge("setForbiddenPlmns: Exception: " + ar.exception);
1650 request.result = -1;
1651 } else {
1652 loge("setForbiddenPlmns: Unknown exception");
1653 }
1654 }
1655 notifyRequester(request);
1656 break;
1657 case CMD_SET_FORBIDDEN_PLMNS:
1658 request = (MainThreadRequest) msg.obj;
1659 uiccCard = getUiccCardFromRequest(request);
1660 if (uiccCard == null) {
1661 loge("setForbiddenPlmns: UiccCard is null");
1662 request.result = -1;
1663 notifyRequester(request);
1664 break;
1665 }
1666 Pair<Integer, List<String>> setFplmnsArgs =
1667 (Pair<Integer, List<String>>) request.argument;
1668 appType = setFplmnsArgs.first;
1669 List<String> fplmns = setFplmnsArgs.second;
1670 uiccApp = uiccCard.getApplicationByType(appType);
1671 if (uiccApp == null) {
1672 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1673 request.result = -1;
1674 loge("Failed to get UICC App");
1675 notifyRequester(request);
1676 } else {
1677 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1678 ((SIMRecords) uiccApp.getIccRecords())
1679 .setForbiddenPlmns(onCompleted, fplmns);
1680 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001681 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001682 case CMD_ERASE_MODEM_CONFIG:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1685 defaultPhone.eraseModemConfig(onCompleted);
1686 break;
1687 case EVENT_ERASE_MODEM_CONFIG_DONE:
1688 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001689 break;
zoey chene02881a2019-12-30 16:11:23 +08001690
1691 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1692 request = (MainThreadRequest) msg.obj;
1693 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1694 Pair<String, String> changed = (Pair<String, String>) request.argument;
1695 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1696 changed.first, changed.second, onCompleted);
1697 break;
1698 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 if (ar.exception == null) {
1702 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1703 } else {
1704 request.result = msg.arg1;
1705 }
1706 notifyRequester(request);
1707 break;
1708
1709 case CMD_SET_ICC_LOCK_ENABLED:
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1712 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1713 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1714 enabled.first, enabled.second, onCompleted);
1715 break;
1716 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 if (ar.exception == null) {
1720 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1721 } else {
1722 request.result = msg.arg1;
1723 }
1724 notifyRequester(request);
1725 break;
1726
Peter Wangdafb9ac2020-01-15 14:13:38 -08001727 case MSG_NOTIFY_USER_ACTIVITY:
1728 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001729 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001730 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1731 getDefaultPhone().getContext().sendBroadcastAsUser(
1732 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1733 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001734
1735 case CMD_SET_DATA_THROTTLING: {
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1738 DataThrottlingRequest dataThrottlingRequest =
1739 (DataThrottlingRequest) request.argument;
1740 Phone phone = getPhoneFromRequest(request);
1741 if (phone != null) {
1742 phone.setDataThrottling(onCompleted,
1743 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1744 dataThrottlingRequest.getCompletionDurationMillis());
1745 } else {
1746 loge("setDataThrottling: No phone object");
1747 request.result =
1748 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1749 notifyRequester(request);
1750 }
1751
1752 break;
1753 }
1754 case EVENT_SET_DATA_THROTTLING_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757
1758 if (ar.exception == null) {
1759 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1760 } else if (ar.exception instanceof CommandException) {
1761 loge("setDataThrottling: CommandException: " + ar.exception);
1762 CommandException.Error error =
1763 ((CommandException) (ar.exception)).getCommandError();
1764
1765 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1766 request.result = TelephonyManager
1767 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1768 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1769 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1770 } else {
1771 request.result =
1772 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1773 }
1774 } else {
1775 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1776 }
1777 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1778 notifyRequester(request);
1779 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001780
1781 case CMD_SET_SIM_POWER: {
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1784 request = (MainThreadRequest) msg.obj;
1785 int stateToSet =
1786 ((Pair<Integer, IIntegerConsumer>)
1787 request.argument).first;
1788 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1789 break;
1790 }
1791 case EVENT_SET_SIM_POWER_DONE: {
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 IIntegerConsumer callback =
1795 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1796 if (ar.exception != null) {
1797 loge("setSimPower exception: " + ar.exception);
1798 int errorCode = TelephonyManager.CallForwardingInfoCallback
1799 .RESULT_ERROR_UNKNOWN;
1800 if (ar.exception instanceof CommandException) {
1801 CommandException.Error error =
1802 ((CommandException) (ar.exception)).getCommandError();
1803 if (error == CommandException.Error.SIM_ERR) {
1804 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1805 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1806 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1807 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1808 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1809 } else {
1810 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1811 }
1812 }
1813 try {
1814 callback.accept(errorCode);
1815 } catch (RemoteException e) {
1816 // Ignore if the remote process is no longer available to call back.
1817 Log.w(LOG_TAG, "setSimPower: callback not available.");
1818 }
1819 } else {
1820 try {
1821 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1822 } catch (RemoteException e) {
1823 // Ignore if the remote process is no longer available to call back.
1824 Log.w(LOG_TAG, "setSimPower: callback not available.");
1825 }
1826 }
1827 break;
1828 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001829 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1830 request = (MainThreadRequest) msg.obj;
1831
1832 final Phone phone = getPhoneFromRequest(request);
1833 if (phone == null || phone.getServiceStateTracker() == null) {
1834 request.result = new IllegalStateException("Phone or SST is null");
1835 notifyRequester(request);
1836 break;
1837 }
1838
1839 Pair<Integer, SignalStrengthUpdateRequest> pair =
1840 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1841 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1842 request);
1843 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1844 request.subId, pair.first /*callingUid*/,
1845 pair.second /*request*/, onCompleted);
1846 break;
1847 }
1848 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1849 ar = (AsyncResult) msg.obj;
1850 request = (MainThreadRequest) ar.userObj;
1851 // request.result will be the exception of ar if present, true otherwise.
1852 // Be cautious not to leave result null which will wait() forever
1853 request.result = ar.exception != null ? ar.exception : true;
1854 notifyRequester(request);
1855 break;
1856 }
1857 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1858 request = (MainThreadRequest) msg.obj;
1859
1860 Phone phone = getPhoneFromRequest(request);
1861 if (phone == null || phone.getServiceStateTracker() == null) {
1862 request.result = new IllegalStateException("Phone or SST is null");
1863 notifyRequester(request);
1864 break;
1865 }
1866
1867 Pair<Integer, SignalStrengthUpdateRequest> pair =
1868 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1869 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1870 request);
1871 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1872 request.subId, pair.first /*callingUid*/,
1873 pair.second /*request*/, onCompleted);
1874 break;
1875 }
1876 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1877 ar = (AsyncResult) msg.obj;
1878 request = (MainThreadRequest) ar.userObj;
1879 request.result = ar.exception != null ? ar.exception : true;
1880 notifyRequester(request);
1881 break;
1882 }
Jordan Liu109698e2020-11-24 14:50:34 -08001883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 default:
1885 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1886 break;
1887 }
1888 }
Jake Hambye994d462014-02-03 13:10:13 -08001889
Pengquan Menga1bb6272018-09-06 09:59:22 -07001890 private void notifyRequester(MainThreadRequest request) {
1891 synchronized (request) {
1892 request.notifyAll();
1893 }
1894 }
1895
Jake Hambye994d462014-02-03 13:10:13 -08001896 private void handleNullReturnEvent(Message msg, String command) {
1897 AsyncResult ar = (AsyncResult) msg.obj;
1898 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1899 if (ar.exception == null) {
1900 request.result = true;
1901 } else {
1902 request.result = false;
1903 if (ar.exception instanceof CommandException) {
1904 loge(command + ": CommandException: " + ar.exception);
1905 } else {
1906 loge(command + ": Unknown exception");
1907 }
1908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001909 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
1913 /**
1914 * Posts the specified command to be executed on the main thread,
1915 * waits for the request to complete, and returns the result.
1916 * @see #sendRequestAsync
1917 */
1918 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001919 return sendRequest(
1920 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001921 }
1922
1923 /**
1924 * Posts the specified command to be executed on the main thread,
1925 * waits for the request to complete, and returns the result.
1926 * @see #sendRequestAsync
1927 */
1928 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1929 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001930 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001931 }
1932
1933 /**
1934 * Posts the specified command to be executed on the main thread,
1935 * waits for the request to complete, and returns the result.
1936 * @see #sendRequestAsync
1937 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001938 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001939 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001940 }
1941
1942 /**
1943 * Posts the specified command to be executed on the main thread,
1944 * waits for the request to complete, and returns the result.
1945 * @see #sendRequestAsync
1946 */
Nathan Harold92bed182018-10-12 18:16:49 -07001947 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1948 return sendRequest(command, argument, subId, null, workSource);
1949 }
1950
1951 /**
1952 * Posts the specified command to be executed on the main thread,
1953 * waits for the request to complete, and returns the result.
1954 * @see #sendRequestAsync
1955 */
1956 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1957 return sendRequest(
1958 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1959 }
1960
1961 /**
1962 * Posts the specified command to be executed on the main thread,
1963 * waits for the request to complete, and returns the result.
1964 * @see #sendRequestAsync
1965 */
1966 private Object sendRequest(
1967 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1969 throw new RuntimeException("This method will deadlock if called from the main thread.");
1970 }
1971
Nathan Harold92bed182018-10-12 18:16:49 -07001972 MainThreadRequest request = null;
1973 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1974 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1975 } else if (phone != null) {
1976 request = new MainThreadRequest(argument, phone, workSource);
1977 } else {
1978 request = new MainThreadRequest(argument, subId, workSource);
1979 }
1980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 Message msg = mMainThreadHandler.obtainMessage(command, request);
1982 msg.sendToTarget();
1983
1984 // Wait for the request to complete
1985 synchronized (request) {
1986 while (request.result == null) {
1987 try {
1988 request.wait();
1989 } catch (InterruptedException e) {
1990 // Do nothing, go back and wait until the request is complete
1991 }
1992 }
1993 }
1994 return request.result;
1995 }
1996
1997 /**
1998 * Asynchronous ("fire and forget") version of sendRequest():
1999 * Posts the specified command to be executed on the main thread, and
2000 * returns immediately.
2001 * @see #sendRequest
2002 */
2003 private void sendRequestAsync(int command) {
2004 mMainThreadHandler.sendEmptyMessage(command);
2005 }
2006
2007 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002008 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002009 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002010 */
2011 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002012 sendRequestAsync(command, argument, null, null);
2013 }
2014
2015 /**
2016 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2017 * @see {@link #sendRequest(int,Object)}
2018 */
2019 private void sendRequestAsync(
2020 int command, Object argument, Phone phone, WorkSource workSource) {
2021 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002022 Message msg = mMainThreadHandler.obtainMessage(command, request);
2023 msg.sendToTarget();
2024 }
2025
2026 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 * Initialize the singleton PhoneInterfaceManager instance.
2028 * This is only done once, at startup, from PhoneApp.onCreate().
2029 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002030 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 synchronized (PhoneInterfaceManager.class) {
2032 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002033 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 } else {
2035 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2036 }
2037 return sInstance;
2038 }
2039 }
2040
2041 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002042 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002045 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002046 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2048 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002049 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002050 mTelephonySharedPreferences =
2051 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002052 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002053 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002054 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 publish();
2057 }
2058
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002059 private Phone getDefaultPhone() {
2060 Phone thePhone = getPhone(getDefaultSubscription());
2061 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2062 }
2063
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 private void publish() {
2065 if (DBG) log("publish: " + this);
2066
Peter Wangc035ce42020-01-08 21:00:22 -08002067 TelephonyFrameworkInitializer
2068 .getTelephonyServiceManager()
2069 .getTelephonyServiceRegisterer()
2070 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 }
2072
Stuart Scott584921c2015-01-15 17:10:34 -08002073 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002074 if (request.phone != null) {
2075 return request.phone;
2076 } else {
2077 return getPhoneFromSubId(request.subId);
2078 }
2079 }
2080
2081 private Phone getPhoneFromSubId(int subId) {
2082 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2083 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002084 }
2085
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002086 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2087 Phone phone = getPhoneFromRequest(request);
2088 return phone == null ? null :
2089 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2090 }
2091
Wink Saville36469e72014-06-11 15:17:00 -07002092 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002093 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002094 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096
Naina Nallurid63128d2019-09-17 14:10:30 -07002097 private void sendEraseModemConfig(Phone phone) {
2098 if (phone != null) {
2099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2100 mApp, phone.getSubId(), "eraseModemConfig");
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2104 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
2108 }
2109 }
2110
Peter Wang44b186e2020-01-13 23:33:09 -08002111 private boolean isImsAvailableOnDevice() {
2112 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2113 if (pm == null) {
2114 // For some reason package manger is not available.. This will fail internally anyway,
2115 // so do not throw error and allow.
2116 return true;
2117 }
2118 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2119 }
2120
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002122 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
Wink Savilleb564aae2014-10-23 10:18:09 -07002125 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 if (DBG) log("dial: " + number);
2127 // No permission check needed here: This is just a wrapper around the
2128 // ACTION_DIAL intent, which is available to any app since it puts up
2129 // the UI before it does anything.
2130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131 final long identity = Binder.clearCallingIdentity();
2132 try {
2133 String url = createTelUrl(number);
2134 if (url == null) {
2135 return;
2136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138 // PENDING: should we just silently fail if phone is offhook or ringing?
2139 PhoneConstants.State state = mCM.getState(subId);
2140 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2141 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2142 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2143 mApp.startActivity(intent);
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148 }
2149
2150 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002151 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
2153
Wink Savilleb564aae2014-10-23 10:18:09 -07002154 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 if (DBG) log("call: " + number);
2156
2157 // This is just a wrapper around the ACTION_CALL intent, but we still
2158 // need to do a permission check since we're calling startActivity()
2159 // from the context of the phone app.
2160 enforceCallPermission();
2161
Jordan Liu1617b712019-07-10 15:06:26 -07002162 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 != AppOpsManager.MODE_ALLOWED) {
2164 return;
2165 }
2166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 String url = createTelUrl(number);
2170 if (url == null) {
2171 return;
2172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 boolean isValid = false;
2175 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2176 if (slist != null) {
2177 for (SubscriptionInfo subInfoRecord : slist) {
2178 if (subInfoRecord.getSubscriptionId() == subId) {
2179 isValid = true;
2180 break;
2181 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002182 }
Wink Saville08874612014-08-31 19:19:58 -07002183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184 if (!isValid) {
2185 return;
2186 }
Wink Saville08874612014-08-31 19:19:58 -07002187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2189 intent.putExtra(SUBSCRIPTION_KEY, subId);
2190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2191 mApp.startActivity(intent);
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002198 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002199 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2200 }
2201
Wink Savilleb564aae2014-10-23 10:18:09 -07002202 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002203 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002204 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2205 }
2206
Wink Savilleb564aae2014-10-23 10:18:09 -07002207 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209
2210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2213 checkSimPin.start();
2214 return checkSimPin.unlockSim(null, pin);
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
2217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219
Wink Savilleb564aae2014-10-23 10:18:09 -07002220 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2226 checkSimPuk.start();
2227 return checkSimPuk.unlockSim(puk, pin);
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
2233 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002234 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 * a synchronous one.
2236 */
2237 private static class UnlockSim extends Thread {
2238
2239 private final IccCard mSimCard;
2240
2241 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002242 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2243 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244
2245 // For replies from SimCard interface
2246 private Handler mHandler;
2247
2248 // For async handler to identify request type
2249 private static final int SUPPLY_PIN_COMPLETE = 100;
2250
2251 public UnlockSim(IccCard simCard) {
2252 mSimCard = simCard;
2253 }
2254
2255 @Override
2256 public void run() {
2257 Looper.prepare();
2258 synchronized (UnlockSim.this) {
2259 mHandler = new Handler() {
2260 @Override
2261 public void handleMessage(Message msg) {
2262 AsyncResult ar = (AsyncResult) msg.obj;
2263 switch (msg.what) {
2264 case SUPPLY_PIN_COMPLETE:
2265 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2266 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002267 mRetryCount = msg.arg1;
2268 if (ar.exception != null) {
2269 if (ar.exception instanceof CommandException &&
2270 ((CommandException)(ar.exception)).getCommandError()
2271 == CommandException.Error.PASSWORD_INCORRECT) {
2272 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002273 } //When UiccCardApp dispose,handle message and return exception
2274 else if (ar.exception instanceof CommandException &&
2275 ((CommandException) (ar.exception)).getCommandError()
2276 == CommandException.Error.ABORTED) {
2277 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002278 } else {
2279 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2280 }
2281 } else {
2282 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 mDone = true;
2285 UnlockSim.this.notifyAll();
2286 }
2287 break;
2288 }
2289 }
2290 };
2291 UnlockSim.this.notifyAll();
2292 }
2293 Looper.loop();
2294 }
2295
2296 /*
2297 * Use PIN or PUK to unlock SIM card
2298 *
2299 * If PUK is null, unlock SIM card with PIN
2300 *
2301 * If PUK is not null, unlock SIM card with PUK and set PIN code
2302 */
Wink Saville9de0f752013-10-22 19:04:03 -07002303 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304
2305 while (mHandler == null) {
2306 try {
2307 wait();
2308 } catch (InterruptedException e) {
2309 Thread.currentThread().interrupt();
2310 }
2311 }
2312 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2313
2314 if (puk == null) {
2315 mSimCard.supplyPin(pin, callback);
2316 } else {
2317 mSimCard.supplyPuk(puk, pin, callback);
2318 }
2319
2320 while (!mDone) {
2321 try {
2322 Log.d(LOG_TAG, "wait for done");
2323 wait();
2324 } catch (InterruptedException e) {
2325 // Restore the interrupted status
2326 Thread.currentThread().interrupt();
2327 }
2328 }
2329 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002330 int[] resultArray = new int[2];
2331 resultArray[0] = mResult;
2332 resultArray[1] = mRetryCount;
2333 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335 }
2336
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002337 /**
2338 * This method has been removed due to privacy and stability concerns.
2339 */
2340 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002342 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2343 return;
Wink Saville36469e72014-06-11 15:17:00 -07002344 }
2345
Nathan Harold1f889d82020-06-04 17:05:26 -07002346 @Override
2347 public void updateServiceLocationWithPackageName(String callingPackage) {
2348 mApp.getSystemService(AppOpsManager.class)
2349 .checkPackage(Binder.getCallingUid(), callingPackage);
2350
Nathan Haroldf096d982020-11-18 17:18:06 -08002351 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002352 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2353 // Callers targeting S have no business invoking this method.
2354 return;
2355 }
2356
2357 LocationAccessPolicy.LocationPermissionResult locationResult =
2358 LocationAccessPolicy.checkLocationPermission(mApp,
2359 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2360 .setCallingPackage(callingPackage)
2361 .setCallingFeatureId(null)
2362 .setCallingPid(Binder.getCallingPid())
2363 .setCallingUid(Binder.getCallingUid())
2364 .setMethod("updateServiceLocation")
2365 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2366 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2367 .build());
2368 // Apps that lack location permission have no business calling this method;
2369 // however, because no permission was declared in the public API, denials must
2370 // all be "soft".
2371 switch (locationResult) {
2372 case DENIED_HARD: /* fall through */
2373 case DENIED_SOFT:
2374 return;
2375 }
2376
2377 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 final long identity = Binder.clearCallingIdentity();
2379 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002380 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002382 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002389 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002390 @Override
2391 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002392 return isRadioOnWithFeature(callingPackage, null);
2393 }
2394
2395
2396 @Override
2397 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2398 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2399 callingFeatureId);
2400 }
2401
2402 @Deprecated
2403 @Override
2404 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2405 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002406 }
2407
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002408 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002409 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2410 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002412 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 return false;
2414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415
2416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 return isRadioOnForSubscriber(subId);
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
2421 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002422 }
2423
2424 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 final Phone phone = getPhone(subId);
2428 if (phone != null) {
2429 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2430 } else {
2431 return false;
2432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437
2438 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002439 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 }
Wink Saville36469e72014-06-11 15:17:00 -07002441
Wink Savilleb564aae2014-10-23 10:18:09 -07002442 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444
2445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 final Phone phone = getPhone(subId);
2448 if (phone != null) {
2449 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2450 }
2451 } finally {
2452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002453 }
Wink Saville36469e72014-06-11 15:17:00 -07002454 }
2455
2456 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002457 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002458 }
2459
Wink Savilleb564aae2014-10-23 10:18:09 -07002460 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002461 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462
2463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 final Phone phone = getPhone(subId);
2466 if (phone == null) {
2467 return false;
2468 }
2469 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2470 toggleRadioOnOffForSubscriber(subId);
2471 }
2472 return true;
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 }
Wink Saville36469e72014-06-11 15:17:00 -07002477
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002478 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002479 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002480 /*
2481 * If any of the Radios are available, it will need to be
2482 * shutdown. So return true if any Radio is available.
2483 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2487 Phone phone = PhoneFactory.getPhone(i);
2488 if (phone != null && phone.isRadioAvailable()) return true;
2489 }
2490 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2491 return false;
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002494 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002495 }
2496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002498 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 enforceModifyPermission();
2500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2504 logv("Shutting down Phone " + i);
2505 shutdownRadioUsingPhoneId(i);
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002509 }
2510 }
2511
2512 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002513 Phone phone = PhoneFactory.getPhone(phoneId);
2514 if (phone != null && phone.isRadioAvailable()) {
2515 phone.shutdownRadio();
2516 }
2517 }
2518
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2525 if (defaultPhone != null) {
2526 defaultPhone.setRadioPower(turnOn);
2527 return true;
2528 } else {
2529 loge("There's no default phone.");
2530 return false;
2531 }
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002534 }
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
Wink Savilleb564aae2014-10-23 10:18:09 -07002537 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 final Phone phone = getPhone(subId);
2543 if (phone != null) {
2544 phone.setRadioPower(turnOn);
2545 return true;
2546 } else {
2547 return false;
2548 }
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553
Wink Saville36469e72014-06-11 15:17:00 -07002554 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002555 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 public boolean enableDataConnectivity() {
2557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558
2559 final long identity = Binder.clearCallingIdentity();
2560 try {
2561 int subId = mSubscriptionController.getDefaultDataSubId();
2562 final Phone phone = getPhone(subId);
2563 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002564 phone.getDataEnabledSettings().setDataEnabled(
2565 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 return true;
2567 } else {
2568 return false;
2569 }
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 }
2574
Wink Saville36469e72014-06-11 15:17:00 -07002575 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002576 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 public boolean disableDataConnectivity() {
2578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579
2580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 int subId = mSubscriptionController.getDefaultDataSubId();
2583 final Phone phone = getPhone(subId);
2584 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002585 phone.getDataEnabledSettings().setDataEnabled(
2586 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587 return true;
2588 } else {
2589 return false;
2590 }
2591 } finally {
2592 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 }
2595
Sanket Padawe356d7632015-06-22 14:03:32 -07002596 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002597 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002602 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 } else {
2604 return false;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
2611 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002612 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002613 }
2614
pkanwarae03a6b2016-11-06 20:37:09 -08002615 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 enforceCallPermission();
2617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2621 return;
2622 }
2623 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2624 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
pkanwar32d516d2016-10-14 19:37:38 -07002628 };
2629
Wink Savilleb564aae2014-10-23 10:18:09 -07002630 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2636 return false;
2637 }
2638 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002645 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002648 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 Phone phone = PhoneFactory.getPhone(slotIndex);
2652 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2653 PhoneConstantConversions.convertCallState(phone.getState());
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
Sanket Padawe356d7632015-06-22 14:03:32 -07002659 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002660 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002661 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2662 }
2663
2664 @Override
2665 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002668 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 if (phone != null) {
2670 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2671 } else {
2672 return PhoneConstantConversions.convertDataState(
2673 PhoneConstants.DataState.DISCONNECTED);
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002681 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002682 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2683 }
2684
2685 @Override
2686 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 final long identity = Binder.clearCallingIdentity();
2688 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002689 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 if (phone != null) {
2691 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2692 } else {
2693 return TelephonyManager.DATA_ACTIVITY_NONE;
2694 }
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002701 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002702 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002703 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002704
2705 LocationAccessPolicy.LocationPermissionResult locationResult =
2706 LocationAccessPolicy.checkLocationPermission(mApp,
2707 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2708 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002709 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002710 .setCallingPid(Binder.getCallingPid())
2711 .setCallingUid(Binder.getCallingUid())
2712 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002713 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002714 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2715 .build());
2716 switch (locationResult) {
2717 case DENIED_HARD:
2718 throw new SecurityException("Not allowed to access cell location");
2719 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002720 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2721 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002724 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002728 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002729 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
Svetoslav64fad262015-04-14 14:35:21 -07002733 }
2734
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002736 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002737 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2738 // registered cell info, so return a NULL country instead.
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002741 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2742 // Get default phone in this case.
2743 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2744 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002745 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002747 if (phone == null) return "";
2748 ServiceStateTracker sst = phone.getServiceStateTracker();
2749 if (sst == null) return "";
2750 LocaleTracker lt = sst.getLocaleTracker();
2751 if (lt == null) return "";
2752 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2753 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2754 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002758 }
2759
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002760 /**
2761 * This method was removed due to potential issues caused by performing partial
2762 * updates of service state, and lack of a credible use case.
2763 *
2764 * This has the ability to break the telephony implementation by disabling notification of
2765 * changes in device connectivity. DO NOT USE THIS!
2766 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002767 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 public void enableLocationUpdates() {
2769 mApp.enforceCallingOrSelfPermission(
2770 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002773 /**
2774 * This method was removed due to potential issues caused by performing partial
2775 * updates of service state, and lack of a credible use case.
2776 *
2777 * This has the ability to break the telephony implementation by disabling notification of
2778 * changes in device connectivity. DO NOT USE THIS!
2779 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 @Override
2781 public void disableLocationUpdates() {
2782 mApp.enforceCallingOrSelfPermission(
2783 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 }
2785
2786 @Override
2787 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002788 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2789 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002790 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002791 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2792 throw new SecurityException(
2793 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2794 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002795
Jordan Liu1617b712019-07-10 15:06:26 -07002796 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2798 return null;
2799 }
Svetoslav64fad262015-04-14 14:35:21 -07002800
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002801 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002803 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002804 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805
Nathan Haroldf180aac2018-06-01 18:43:55 -07002806 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2807 for (CellInfo ci : info) {
2808 if (ci instanceof CellInfoGsm) {
2809 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2810 } else if (ci instanceof CellInfoWcdma) {
2811 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002814 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002817 private List<CellInfo> getCachedCellInfo() {
2818 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2819 for (Phone phone : PhoneFactory.getPhones()) {
2820 List<CellInfo> info = phone.getAllCellInfo();
2821 if (info != null) cellInfos.addAll(info);
2822 }
2823 return cellInfos;
2824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825
2826 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002827 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002828 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002829 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002830
2831 LocationAccessPolicy.LocationPermissionResult locationResult =
2832 LocationAccessPolicy.checkLocationPermission(mApp,
2833 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2834 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002835 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002836 .setCallingPid(Binder.getCallingPid())
2837 .setCallingUid(Binder.getCallingUid())
2838 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002839 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002840 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2841 .build());
2842 switch (locationResult) {
2843 case DENIED_HARD:
2844 throw new SecurityException("Not allowed to access cell info");
2845 case DENIED_SOFT:
2846 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
Nathan Haroldf096d982020-11-18 17:18:06 -08002849 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002850 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2851 return getCachedCellInfo();
2852 }
2853
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002854 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002855 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2859 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002860 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002861 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 if (info != null) cellInfos.addAll(info);
2863 }
2864 return cellInfos;
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
2868 }
2869
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002870 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002871 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2872 String callingFeatureId) {
2873 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2874 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002875 }
2876
2877 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002878 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2879 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002880 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002881 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002882 }
2883
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002884 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2885 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002886 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002887 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002888
2889 LocationAccessPolicy.LocationPermissionResult locationResult =
2890 LocationAccessPolicy.checkLocationPermission(mApp,
2891 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2892 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002893 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002894 .setCallingPid(Binder.getCallingPid())
2895 .setCallingUid(Binder.getCallingUid())
2896 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002897 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2898 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002899 .build());
2900 switch (locationResult) {
2901 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002902 if (TelephonyPermissions
2903 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002904 // Safetynet logging for b/154934934
2905 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2906 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002907 throw new SecurityException("Not allowed to access cell info");
2908 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002909 if (TelephonyPermissions
2910 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002911 // Safetynet logging for b/154934934
2912 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2913 }
Nathan Harold5320c422019-05-09 10:26:08 -07002914 try {
2915 cb.onCellInfo(new ArrayList<CellInfo>());
2916 } catch (RemoteException re) {
2917 // Drop without consequences
2918 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002919 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002920 }
2921
Nathan Harolda939a962019-05-09 10:13:47 -07002922
2923 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002924 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2925
2926 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2927 }
2928
2929 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002931 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941
Shishir Agrawala9f32182016-04-12 12:00:16 -07002942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002943 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002944 Phone phone = PhoneFactory.getPhone(slotIndex);
2945 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002946 return null;
2947 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002948 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002949 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002950 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002951 return null;
2952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 return phone.getImei();
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002960 }
2961
2962 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002963 public String getTypeAllocationCodeForSlot(int slotIndex) {
2964 Phone phone = PhoneFactory.getPhone(slotIndex);
2965 String tac = null;
2966 if (phone != null) {
2967 String imei = phone.getImei();
2968 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2969 }
2970 return tac;
2971 }
2972
2973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002974 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002975 Phone phone = PhoneFactory.getPhone(slotIndex);
2976 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002977 return null;
2978 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979
Jeff Davidson913390f2018-02-23 17:11:49 -08002980 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002981 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002982 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002983 return null;
2984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 return phone.getMeid();
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Jack Yu2af8d712017-03-15 17:14:14 -07002992 }
2993
2994 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002995 public String getManufacturerCodeForSlot(int slotIndex) {
2996 Phone phone = PhoneFactory.getPhone(slotIndex);
2997 String manufacturerCode = null;
2998 if (phone != null) {
2999 String meid = phone.getMeid();
3000 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3001 }
3002 return manufacturerCode;
3003 }
3004
3005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003006 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3007 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003008 Phone phone = PhoneFactory.getPhone(slotIndex);
3009 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003010 return null;
3011 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003012 int subId = phone.getSubId();
3013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003014 mApp, subId, callingPackage, callingFeatureId,
3015 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003016 return null;
3017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 return phone.getDeviceSvn();
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003025 }
3026
fionaxu43304da2017-11-27 22:51:16 -08003027 @Override
3028 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 final Phone phone = getPhone(subId);
3032 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
fionaxu43304da2017-11-27 22:51:16 -08003036 }
3037
3038 @Override
3039 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 final Phone phone = getPhone(subId);
3043 return phone == null ? null : phone.getCarrierName();
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
fionaxu43304da2017-11-27 22:51:16 -08003047 }
3048
calvinpanffe225e2018-11-01 19:43:06 +08003049 @Override
chen xu0026ca62019-03-06 15:28:50 -08003050 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 final Phone phone = getPhone(subId);
3054 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003055 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
3059 }
3060
3061 @Override
chen xu0026ca62019-03-06 15:28:50 -08003062 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003066 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
3070 }
3071
chen xu651eec72018-11-11 19:03:44 -08003072 @Override
chen xu864e11c2018-12-06 22:10:03 -08003073 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3074 if (!isSubscriptionMccMnc) {
3075 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3076 }
chen xu651eec72018-11-11 19:03:44 -08003077 final Phone phone = PhoneFactory.getPhone(slotIndex);
3078 if (phone == null) {
3079 return TelephonyManager.UNKNOWN_CARRIER_ID;
3080 }
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
3087 }
3088
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 //
3090 // Internal helper methods.
3091 //
3092
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003093 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3095 *
3096 * @throws SecurityException if the caller does not have the required permission
3097 */
3098 private void enforceModifyPermission() {
3099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3100 }
3101
Shuo Qiancd19c462020-01-16 20:51:11 -08003102 /**
3103 * Make sure the caller is system.
3104 *
3105 * @throws SecurityException if the caller is not system.
3106 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003107 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003108 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3109 throw new SecurityException("Caller must be system");
3110 }
3111 }
3112
Shuo Qian3b6ee772019-11-13 17:43:31 -08003113 private void enforceActiveEmergencySessionPermission() {
3114 mApp.enforceCallingOrSelfPermission(
3115 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3116 }
3117
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 /**
3119 * Make sure the caller has the CALL_PHONE permission.
3120 *
3121 * @throws SecurityException if the caller does not have the required permission
3122 */
3123 private void enforceCallPermission() {
3124 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3125 }
3126
paulhu5a773602019-08-23 19:17:33 +08003127 private void enforceSettingsPermission() {
3128 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003129 }
3130
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 private String createTelUrl(String number) {
3132 if (TextUtils.isEmpty(number)) {
3133 return null;
3134 }
3135
Jake Hambye994d462014-02-03 13:10:13 -08003136 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 }
3138
Ihab Awadf9e92732013-12-05 18:02:52 -08003139 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3141 }
3142
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003143 private static void logv(String msg) {
3144 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3145 }
3146
Ihab Awadf9e92732013-12-05 18:02:52 -08003147 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3149 }
3150
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003151 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003153 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003154 }
3155
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003157 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = PhoneFactory.getPhone(slotIndex);
3161 if (phone == null) {
3162 return PhoneConstants.PHONE_TYPE_NONE;
3163 } else {
3164 return phone.getPhoneType();
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
3170
3171 /**
3172 * Returns the CDMA ERI icon index to display
3173 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003175 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3176 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3177 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003178 }
3179
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003181 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3182 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003184 mApp, subId, callingPackage, callingFeatureId,
3185 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003186 return -1;
3187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = getPhone(subId);
3192 if (phone != null) {
3193 return phone.getCdmaEriIconIndex();
3194 } else {
3195 return -1;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
3202 /**
3203 * Returns the CDMA ERI icon mode,
3204 * 0 - ON
3205 * 1 - FLASHING
3206 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003208 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3209 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3210 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003211 }
3212
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003214 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3215 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003217 mApp, subId, callingPackage, callingFeatureId,
3218 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003219 return -1;
3220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221
3222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 final Phone phone = getPhone(subId);
3225 if (phone != null) {
3226 return phone.getCdmaEriIconMode();
3227 } else {
3228 return -1;
3229 }
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 }
3234
3235 /**
3236 * Returns the CDMA ERI text,
3237 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003238 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003239 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3240 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3241 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003242 }
3243
Sanket Padawe356d7632015-06-22 14:03:32 -07003244 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003245 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3246 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003248 mApp, subId, callingPackage, callingFeatureId,
3249 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003250 return null;
3251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 final Phone phone = getPhone(subId);
3256 if (phone != null) {
3257 return phone.getCdmaEriText();
3258 } else {
3259 return null;
3260 }
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 }
3265
3266 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003267 * Returns the CDMA MDN.
3268 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003269 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003270 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3272 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 return phone.getLine1Number();
3279 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003280 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 return null;
3282 }
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003285 }
3286 }
3287
3288 /**
3289 * Returns the CDMA MIN.
3290 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003292 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3294 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 final Phone phone = getPhone(subId);
3299 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3300 return phone.getCdmaMin();
3301 } else {
3302 return null;
3303 }
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003306 }
3307 }
3308
Hall Liud892bec2018-11-30 14:51:45 -08003309 @Override
3310 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3311 INumberVerificationCallback callback, String callingPackage) {
3312 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3313 != PERMISSION_GRANTED) {
3314 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3315 }
3316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3317
3318 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3319 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003320 throw new SecurityException("Calling package must be configured in the device config: "
3321 + "calling package: " + callingPackage
3322 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003323 }
3324
3325 if (range == null) {
3326 throw new NullPointerException("Range must be non-null");
3327 }
3328
3329 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003330 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003331
3332 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3333 }
3334
Junda Liuca05d5d2014-08-14 22:36:34 -07003335 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 * Returns true if CDMA provisioning needs to run.
3337 */
3338 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 final long identity = Binder.clearCallingIdentity();
3340 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003341 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 }
3346
3347 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003348 * Sets the voice mail number of a given subId.
3349 */
3350 @Override
3351 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003352 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3353 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3358 new Pair<String, String>(alphaTag, number), new Integer(subId));
3359 return success;
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003363 }
3364
Ta-wei Yen87c49842016-05-13 21:19:52 -07003365 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003366 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003368 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3369 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003370 if (!TextUtils.equals(callingPackage, systemDialer)) {
3371 throw new SecurityException("caller must be system dialer");
3372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3377 if (phoneAccountHandle == null) {
3378 return null;
3379 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003383 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003384 }
3385
3386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003387 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3388 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003389 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003391 mApp, subId, callingPackage, callingFeatureId,
3392 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003393 return null;
3394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003396 final long identity = Binder.clearCallingIdentity();
3397 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003398 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003402 }
3403
3404 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003405 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3406 VisualVoicemailSmsFilterSettings settings) {
3407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003416 }
3417
3418 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003419 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3420 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003429 }
3430
3431 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003432 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3433 String callingPackage, int subId) {
3434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003435
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003443 }
3444
3445 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003446 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003452 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003456 }
3457
3458 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003459 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3460 String callingAttributionTag, int subId, String number, int port, String text,
3461 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003463 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003464 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003465 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003466 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3467 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003468 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003469
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003470 /**
fionaxu0152e512016-11-14 13:36:14 -08003471 * Sets the voice activation state of a given subId.
3472 */
3473 @Override
3474 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3476 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 final Phone phone = getPhone(subId);
3481 if (phone != null) {
3482 phone.setVoiceActivationState(activationState);
3483 } else {
3484 loge("setVoiceActivationState fails with invalid subId: " + subId);
3485 }
3486 } finally {
3487 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003488 }
3489 }
3490
3491 /**
3492 * Sets the data activation state of a given subId.
3493 */
3494 @Override
3495 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3497 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 final Phone phone = getPhone(subId);
3502 if (phone != null) {
3503 phone.setDataActivationState(activationState);
3504 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003505 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 }
3507 } finally {
3508 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003509 }
3510 }
3511
3512 /**
3513 * Returns the voice activation state of a given subId.
3514 */
3515 @Override
3516 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003518
fionaxu0152e512016-11-14 13:36:14 -08003519 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 if (phone != null) {
3523 return phone.getVoiceActivationState();
3524 } else {
3525 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3526 }
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003529 }
3530 }
3531
3532 /**
3533 * Returns the data activation state of a given subId.
3534 */
3535 @Override
3536 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538
fionaxu0152e512016-11-14 13:36:14 -08003539 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 if (phone != null) {
3543 return phone.getDataActivationState();
3544 } else {
3545 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3546 }
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003549 }
3550 }
3551
3552 /**
Wink Saville36469e72014-06-11 15:17:00 -07003553 * Returns the unread count of voicemails for a subId
3554 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3557 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 mApp, subId, callingPackage, callingFeatureId,
3560 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003561 return 0;
3562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 final Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.getVoiceMessageCount();
3568 } else {
3569 return 0;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
3575
3576 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003577 * returns true, if the device is in a state where both voice and data
3578 * are supported simultaneously. This can change based on location or network condition.
3579 */
3580 @Override
3581 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 final Phone phone = getPhone(subId);
3585 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003589 }
3590
3591 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003592 * Send the dialer code if called from the current default dialer or the caller has
3593 * carrier privilege.
3594 * @param inputCode The dialer code to send
3595 */
3596 @Override
3597 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003599 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003600 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3601 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003602 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003603 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
fionaxu235cc5e2017-03-06 22:25:57 -08003613 }
3614
Pengquan Menga1bb6272018-09-06 09:59:22 -07003615 @Override
3616 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003617 TelephonyPermissions
3618 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3619 mApp, subId, "getNetworkSelectionMode");
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 if (!isActiveSubscription(subId)) {
3623 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3624 }
3625 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3626 } finally {
3627 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003628 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003629 }
3630
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003632 public boolean isInEmergencySmsMode() {
3633 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 for (Phone phone : PhoneFactory.getPhones()) {
3637 if (phone.isInEmergencySmsMode()) {
3638 return true;
3639 }
3640 }
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 return false;
3645 }
3646
shilu366312e2019-12-17 09:28:10 -08003647 /**
3648 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3649 * @param subId The subscription to use to check the configuration.
3650 * @param c The callback that will be used to send the result.
3651 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003652 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003653 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3654 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003655 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3656 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003657
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003658 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3659 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3660 "IMS not available on device.");
3661 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 final long token = Binder.clearCallingIdentity();
3663 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003664 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003667 } catch (ImsException e) {
3668 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 } finally {
3670 Binder.restoreCallingIdentity(token);
3671 }
3672 }
3673
shilu366312e2019-12-17 09:28:10 -08003674 /**
3675 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3676 * @param subId The subscription to use to check the configuration.
3677 * @param c The callback that will be used to send the result.
3678 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003680 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003681 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3682 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3684 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3685 }
Meng Wangafbc5852019-09-19 17:37:13 -07003686 final long token = Binder.clearCallingIdentity();
3687 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003688 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003689 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3690 .removeRegistrationCallbackForSubscription(c, subId);
3691 } catch (ImsException e) {
3692 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3693 + "is inactive, ignoring unregister.");
3694 // If the subscription is no longer active, just return, since the callback
3695 // will already have been removed internally.
3696 } finally {
3697 Binder.restoreCallingIdentity(token);
3698 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 }
3700
Brad Ebingera34a6c22019-10-22 17:36:18 -07003701 /**
3702 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3703 */
3704 @Override
3705 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3706 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3707 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3709 "IMS not available on device.");
3710 }
3711 final long token = Binder.clearCallingIdentity();
3712 try {
3713 Phone phone = getPhone(subId);
3714 if (phone == null) {
3715 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3716 + subId + "'");
3717 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3718 }
3719 phone.getImsRegistrationState(regState -> {
3720 try {
3721 consumer.accept((regState == null)
3722 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3723 } catch (RemoteException e) {
3724 // Ignore if the remote process is no longer available to call back.
3725 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3726 }
3727 });
3728 } finally {
3729 Binder.restoreCallingIdentity(token);
3730 }
3731 }
3732
3733 /**
3734 * Get the transport type for the IMS service registration state.
3735 */
3736 @Override
3737 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003738 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3739 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003740 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3742 "IMS not available on device.");
3743 }
3744 final long token = Binder.clearCallingIdentity();
3745 try {
3746 Phone phone = getPhone(subId);
3747 if (phone == null) {
3748 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3749 + subId + "'");
3750 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3751 }
3752 phone.getImsRegistrationTech(regTech -> {
3753 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3754 int regTechConverted = (regTech == null)
3755 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3756 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3757 regTechConverted);
3758 try {
3759 consumer.accept(regTechConverted);
3760 } catch (RemoteException e) {
3761 // Ignore if the remote process is no longer available to call back.
3762 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3763 }
3764 });
3765 } finally {
3766 Binder.restoreCallingIdentity(token);
3767 }
3768 }
3769
shilu366312e2019-12-17 09:28:10 -08003770 /**
3771 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3772 * @param subId The subscription to use to check the configuration.
3773 * @param c The callback that will be used to send the result.
3774 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003776 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3777 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003778 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3779 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003780 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3781 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3782 "IMS not available on device.");
3783 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3785 final long token = Binder.clearCallingIdentity();
3786 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003789 } catch (ImsException e) {
3790 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 } finally {
3792 Binder.restoreCallingIdentity(token);
3793 }
3794 }
3795
shilu366312e2019-12-17 09:28:10 -08003796 /**
3797 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3798 * @param subId The subscription to use to check the configuration.
3799 * @param c The callback that will be used to send the result.
3800 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003802 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003803 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3804 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3807 }
Meng Wangafbc5852019-09-19 17:37:13 -07003808
3809 final long token = Binder.clearCallingIdentity();
3810 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003811 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003812 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003813 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003814 } catch (ImsException e) {
3815 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3816 + "is inactive, ignoring unregister.");
3817 // If the subscription is no longer active, just return, since the callback
3818 // will already have been removed internally.
3819 } finally {
3820 Binder.restoreCallingIdentity(token);
3821 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 }
3823
3824 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003825 public boolean isCapable(int subId, int capability, int regTech) {
3826 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3828 final long token = Binder.clearCallingIdentity();
3829 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003830 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003832 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3834 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003835 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003836 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3837 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 } finally {
3839 Binder.restoreCallingIdentity(token);
3840 }
3841 }
3842
3843 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003844 public boolean isAvailable(int subId, int capability, int regTech) {
3845 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 final long token = Binder.clearCallingIdentity();
3847 try {
3848 Phone phone = getPhone(subId);
3849 if (phone == null) return false;
3850 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003851 } catch (com.android.ims.ImsException e) {
3852 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3853 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 } finally {
3855 Binder.restoreCallingIdentity(token);
3856 }
3857 }
3858
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003859 /**
3860 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3861 * subscription.
3862 * @param subId The subscription to use to check the configuration.
3863 * @param callback The callback that will be used to send the result.
3864 * @param capability The MmTelFeature capability that will be used to send the result.
3865 * @param transportType The transport type of the MmTelFeature capability.
3866 */
3867 @Override
3868 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3869 int transportType) {
3870 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3871 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3872 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3873 "IMS not available on device.");
3874 }
3875 final long token = Binder.clearCallingIdentity();
3876 try {
3877 int slotId = getSlotIndex(subId);
3878 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3879 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3880 + subId + "'");
3881 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3882 }
3883 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3884 transportType, aBoolean -> {
3885 try {
3886 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3887 } catch (RemoteException e) {
3888 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3889 + "running. Ignore");
3890 }
3891 });
3892 } finally {
3893 Binder.restoreCallingIdentity(token);
3894 }
3895 }
3896
shilu366312e2019-12-17 09:28:10 -08003897 /**
3898 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3899 * @param subId The subscription to use to check the configuration.
3900 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 @Override
3902 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003903 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3904 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003905
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3907 final long token = Binder.clearCallingIdentity();
3908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003911 } catch (ImsException e) {
3912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(token);
3915 }
3916 }
3917
3918 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003919 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003921 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003925 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003927 } catch (ImsException e) {
3928 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
3932 }
3933
shilu366312e2019-12-17 09:28:10 -08003934 /**
3935 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3936 * @param subId The subscription to use to check the configuration.
3937 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003939 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003940 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3941 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003945 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3946 } catch (ImsException e) {
3947 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
3951 }
3952
3953 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003954 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003956 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003961 } catch (ImsException e) {
3962 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
3966 }
3967
shilu366312e2019-12-17 09:28:10 -08003968 /**
3969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3970 * @param subId The subscription to use to check the configuration.
3971 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 @Override
3973 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003974 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3975 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003979 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003981 } catch (ImsException e) {
3982 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 } finally {
3984 Binder.restoreCallingIdentity(identity);
3985 }
3986 }
3987
3988 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003989 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003991 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (ImsException e) {
3997 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
4001 }
4002
shilu366312e2019-12-17 09:28:10 -08004003 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004004 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4005 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4006 * @param subId The subscription to use to check the configuration.
4007 */
4008 @Override
4009 public boolean isCrossSimCallingEnabledByUser(int subId) {
4010 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4011 mApp, subId, "isCrossSimCallingEnabledByUser");
4012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4015 return ImsManager.getInstance(mApp,
4016 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4017 } catch (ImsException e) {
4018 throw new ServiceSpecificException(e.getCode());
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
4022 }
4023
4024 /**
4025 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4026 * Requires MODIFY_PHONE_STATE permission.
4027 * @param subId The subscription to use to check the configuration.
4028 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4029 * false otherwise
4030 */
4031 @Override
4032 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4034 "setCrossSimCallingEnabled");
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4038 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4039 .setCrossSimCallingEnabled(isEnabled);
4040 } catch (ImsException e) {
4041 throw new ServiceSpecificException(e.getCode());
4042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
4045 }
4046
4047 /**
shilu366312e2019-12-17 09:28:10 -08004048 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4049 * @param subId The subscription to use to check the configuration.
4050 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 @Override
4052 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004053 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4054 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004058 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004060 } catch (ImsException e) {
4061 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 } finally {
4063 Binder.restoreCallingIdentity(identity);
4064 }
4065 }
4066
4067 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004068 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004070 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004074 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004076 } catch (ImsException e) {
4077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
4081 }
4082
4083 @Override
4084 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4086 "setVoWiFiNonPersistent");
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004090 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004091 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004092 } catch (ImsException e) {
4093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
4097 }
4098
shilu366312e2019-12-17 09:28:10 -08004099 /**
4100 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4101 * @param subId The subscription to use to check the configuration.
4102 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 @Override
4104 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004105 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4106 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
4113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
4117 }
4118
4119 @Override
4120 public void setVoWiFiModeSetting(int subId, int mode) {
4121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4122 "setVoWiFiModeSetting");
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (ImsException e) {
4129 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
4133 }
4134
4135 @Override
4136 public int getVoWiFiRoamingModeSetting(int subId) {
4137 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
4151 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4153 "setVoWiFiRoamingModeSetting");
4154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
4160 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
4164 }
4165
4166 @Override
4167 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4169 "setRttCapabilityEnabled");
4170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004173 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4174 } catch (ImsException e) {
4175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
4179 }
4180
shilu366312e2019-12-17 09:28:10 -08004181 /**
4182 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4183 * @param subId The subscription to use to check the configuration.
4184 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 @Override
4186 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004187 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4188 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004192 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004194 } catch (ImsException e) {
4195 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 } finally {
4197 Binder.restoreCallingIdentity(identity);
4198 }
4199 }
4200
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004201 @Override
4202 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4203 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4204 final long identity = Binder.clearCallingIdentity();
4205 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004206 if (!isImsAvailableOnDevice()) {
4207 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4208 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004209 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004211 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004212 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004213 } catch (ImsException e) {
4214 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
4218 }
4219
4220 @Override
4221 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4222 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4223 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004224 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4225 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4226 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004227 try {
4228 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004229 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004230 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004231 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004232 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4233 + "is inactive, ignoring unregister.");
4234 // If the subscription is no longer active, just return, since the callback will already
4235 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
4239 }
4240
allenwtsu99c623b2020-01-03 18:24:23 +08004241
4242 private void checkModifyPhoneStatePermission(int subId, String message) {
4243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4244 message);
4245 }
4246
4247 private boolean isImsProvisioningRequired(int subId, int capability,
4248 boolean isMmtelCapability) {
4249 Phone phone = getPhone(subId);
4250 if (phone == null) {
4251 loge("phone instance null for subid " + subId);
4252 return false;
4253 }
4254 if (isMmtelCapability) {
4255 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4256 return false;
4257 }
4258 } else {
4259 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4260 return false;
4261 }
4262 }
4263 return true;
4264 }
4265
4266 @Override
4267 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4268 boolean isProvisioned) {
4269 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4270
4271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4274 if (!isImsProvisioningRequired(subId, capability, false)) {
4275 return;
4276 }
4277
4278 // this capability requires provisioning, route to the correct API.
4279 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4280 switch (capability) {
4281 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4282 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4283 ims.setEabProvisioned(isProvisioned);
4284 break;
4285 default: {
4286 throw new IllegalArgumentException("Tried to set provisioning for "
4287 + "rcs capability '" + capability + "', which does not require "
4288 + "provisioning.");
4289 }
4290 }
4291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294
4295 }
4296
4297
4298 @Override
4299 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4300 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4304 if (!isImsProvisioningRequired(subId, capability, false)) {
4305 return true;
4306 }
4307
4308 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4309 switch (capability) {
4310 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4311 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4312 return ims.isEabProvisionedOnDevice();
4313
4314 default: {
4315 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4316 + "capability '" + capability + "', which does not require "
4317 + "provisioning.");
4318 }
4319 }
4320
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 }
4325
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004326 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004327 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4328 boolean isProvisioned) {
4329 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4330 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4331 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4332 }
allenwtsu99c623b2020-01-03 18:24:23 +08004333 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004334 final long identity = Binder.clearCallingIdentity();
4335 try {
4336 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004337 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004338 return;
4339 }
4340
4341 // this capability requires provisioning, route to the correct API.
4342 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4343 switch (capability) {
4344 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4345 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4346 ims.setVolteProvisioned(isProvisioned);
4347 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4348 ims.setWfcProvisioned(isProvisioned);
4349 }
4350 break;
4351 }
4352 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4353 // There is currently no difference in VT provisioning type.
4354 ims.setVtProvisioned(isProvisioned);
4355 break;
4356 }
4357 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4358 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4359 // change the capability of the feature instead if needed.
4360 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4361 == isProvisioned) {
4362 // No change in provisioning.
4363 return;
4364 }
4365 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4366 try {
4367 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004368 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004369 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4370 + ", Exception" + e.getMessage());
4371 }
4372 break;
4373 }
4374 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004375 throw new IllegalArgumentException("Tried to set provisioning for "
4376 + "MmTel capability '" + capability + "', which does not require "
4377 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004378 }
4379 }
4380
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
4386 @Override
4387 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4388 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4389 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4390 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4391 }
4392 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004396 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004397 return true;
4398 }
4399
4400 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4401 switch (capability) {
4402 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4403 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4404 return ims.isVolteProvisionedOnDevice();
4405 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4406 return ims.isWfcProvisionedOnDevice();
4407 }
4408 // This should never happen, since we are checking tech above to make sure it
4409 // is either LTE or IWLAN.
4410 throw new IllegalArgumentException("Invalid radio technology for voice "
4411 + "capability.");
4412 }
4413 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4414 // There is currently no difference in VT provisioning type.
4415 return ims.isVtProvisionedOnDevice();
4416 }
4417 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4418 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4419 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4420 }
4421 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004422 throw new IllegalArgumentException(
4423 "Tried to get provisioning for MmTel capability '" + capability
4424 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004425 }
4426 }
4427
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
4431 }
4432
4433 @Override
4434 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4435 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4436 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4437 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4438 }
4439 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4440 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4441 return (provisionedBits & capability) > 0;
4442 }
4443
4444 @Override
4445 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4446 boolean isProvisioned) {
4447 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4448 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4449 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4450 }
4451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4452 "setProvisioningStatusForCapability");
4453 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4454 // If the current provisioning status for capability already matches isProvisioned,
4455 // do nothing.
4456 if (((provisionedBits & capability) > 0) == isProvisioned) {
4457 return;
4458 }
4459 if (isProvisioned) {
4460 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4461 } else {
4462 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4463 }
4464 }
4465
4466 /**
4467 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4468 * technology. The bitfield should mirror the bitfield defined by
4469 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4470 */
4471 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4472 String key = getMmTelProvisioningKey(subId, tech);
4473 // Default is no capabilities are provisioned.
4474 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4475 }
4476
4477 /**
4478 * Sets the MmTel capability provisioning bitfield (defined by
4479 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4480 * technology specified.
4481 *
4482 * Note: This is a synchronous command and should not be called on UI thread.
4483 */
4484 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4485 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4486 String key = getMmTelProvisioningKey(subId, tech);
4487 editor.putInt(key, newField);
4488 editor.commit();
4489 }
4490
4491 private static String getMmTelProvisioningKey(int subId, int tech) {
4492 // resulting key is provision_ims_mmtel_{subId}_{tech}
4493 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4494 }
4495
4496 /**
4497 * Query CarrierConfig to see if the specified capability requires provisioning for the
4498 * carrier associated with the subscription id.
4499 */
4500 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4501 int capability) {
4502 CarrierConfigManager configManager = new CarrierConfigManager(context);
4503 PersistableBundle c = configManager.getConfigForSubId(subId);
4504 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004505 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004506 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4507 false);
4508 boolean requireVoiceVtProvisioning = c.getBoolean(
4509 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4510
4511 // First check to make sure that the capability requires provisioning.
4512 switch (capability) {
4513 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4514 // intentional fallthrough
4515 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4516 if (requireVoiceVtProvisioning) {
4517 // Voice and Video requires provisioning
4518 return true;
4519 }
4520 break;
4521 }
4522 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4523 if (requireUtProvisioning) {
4524 // UT requires provisioning
4525 return true;
4526 }
4527 break;
4528 }
4529 }
4530 return false;
4531 }
4532
allenwtsu99c623b2020-01-03 18:24:23 +08004533 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4534 int capability) {
4535 CarrierConfigManager configManager = new CarrierConfigManager(context);
4536 PersistableBundle c = configManager.getConfigForSubId(subId);
4537
4538 boolean requireRcsProvisioning = c.getBoolean(
4539 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4540
4541 // First check to make sure that the capability requires provisioning.
4542 switch (capability) {
4543 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4544 // intentional fallthrough
4545 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4546 if (requireRcsProvisioning) {
4547 // OPTION or PRESENCE requires provisioning
4548 return true;
4549 }
4550 break;
4551 }
4552 }
4553 return false;
4554 }
4555
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004556 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004558 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4559 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4560 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004561 enforceReadPrivilegedPermission("getImsProvisioningInt");
4562 final long identity = Binder.clearCallingIdentity();
4563 try {
4564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004565 int slotId = getSlotIndex(subId);
4566 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4567 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4568 + subId + "' for key:" + key);
4569 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4570 }
4571 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004572 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004573 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4574 + subId + "' for key:" + key);
4575 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
4579 }
4580
4581 @Override
4582 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004583 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4584 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4585 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004586 enforceReadPrivilegedPermission("getImsProvisioningString");
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 int slotId = getSlotIndex(subId);
4591 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4592 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4593 + subId + "' for key:" + key);
4594 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4595 }
4596 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004597 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4599 + subId + "' for key:" + key);
4600 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
4604 }
4605
4606 @Override
4607 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4609 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4610 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4612 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004616 int slotId = getSlotIndex(subId);
4617 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4618 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4619 + subId + "' for key:" + key);
4620 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4621 }
4622 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004623 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004624 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4625 + "' for key:" + key);
4626 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
4630 }
4631
4632 @Override
4633 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4635 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4636 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4638 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 int slotId = getSlotIndex(subId);
4643 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4644 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4645 + subId + "' for key:" + key);
4646 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4647 }
4648 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004649 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4651 + "' for key:" + key);
4652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
4656 }
4657
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 int slotId = SubscriptionManager.getSlotIndex(subId);
4660 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4662 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 }
4664 return slotId;
4665 }
4666
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 private int getSlotIndex(int subId) {
4668 int slotId = SubscriptionManager.getSlotIndex(subId);
4669 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4670 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4671 }
4672 return slotId;
4673 }
4674
Wink Saville36469e72014-06-11 15:17:00 -07004675 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004676 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004677 */
4678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004679 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4680 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004681 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004682 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004683 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004684 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004685 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004686 mApp, subId, callingPackage, callingFeatureId,
4687 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004688 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4689 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 final Phone phone = getPhone(subId);
4694 if (phone != null) {
4695 return phone.getServiceState().getDataNetworkType();
4696 } else {
4697 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4698 }
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004702 }
4703
4704 /**
4705 * Returns the data network type
4706 */
4707 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004708 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4709 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4710 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004711 }
4712
4713 /**
4714 * Returns the data network type for a subId
4715 */
4716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004717 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4718 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004720 mApp, subId, callingPackage, callingFeatureId,
4721 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004722 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4723 }
4724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 final Phone phone = getPhone(subId);
4728 if (phone != null) {
4729 return phone.getServiceState().getDataNetworkType();
4730 } else {
4731 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4732 }
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004736 }
4737
4738 /**
Wink Saville36469e72014-06-11 15:17:00 -07004739 * Returns the Voice network type for a subId
4740 */
4741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004742 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4743 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004745 mApp, subId, callingPackage, callingFeatureId,
4746 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004747 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4748 }
4749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 final long identity = Binder.clearCallingIdentity();
4751 try {
4752 final Phone phone = getPhone(subId);
4753 if (phone != null) {
4754 return phone.getServiceState().getVoiceNetworkType();
4755 } else {
4756 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4757 }
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004761 }
4762
4763 /**
4764 * @return true if a ICC card is present
4765 */
4766 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004767 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004768 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4769 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004770 }
4771
4772 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004773 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004774 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004775 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004776 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 final long identity = Binder.clearCallingIdentity();
4778 try {
4779 final Phone phone = PhoneFactory.getPhone(slotIndex);
4780 if (phone != null) {
4781 return phone.getIccCard().hasIccCard();
4782 } else {
4783 return false;
4784 }
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004788 }
4789
4790 /**
4791 * Return if the current radio is LTE on CDMA. This
4792 * is a tri-state return value as for a period of time
4793 * the mode may be unknown.
4794 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004795 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004796 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004797 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004798 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004800 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4801 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4802 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004803 }
4804
Sanket Padawe356d7632015-06-22 14:03:32 -07004805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004806 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4807 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004808 try {
4809 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4810 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004811 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4812 }
4813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 final Phone phone = getPhone(subId);
4817 if (phone == null) {
4818 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4819 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004820 return TelephonyProperties.lte_on_cdma_device()
4821 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 }
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004825 }
Wink Saville36469e72014-06-11 15:17:00 -07004826 }
4827
Wink Saville36469e72014-06-11 15:17:00 -07004828 /**
4829 * {@hide}
4830 * Returns Default subId, 0 in the case of single standby.
4831 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004832 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004833 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004834 }
4835
Shishir Agrawala9f32182016-04-12 12:00:16 -07004836 private int getSlotForDefaultSubscription() {
4837 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4838 }
4839
Wink Savilleb564aae2014-10-23 10:18:09 -07004840 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004841 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004842 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004843
Pengquan Menge92a50d2018-09-21 15:54:48 -07004844 private boolean isActiveSubscription(int subId) {
4845 return mSubscriptionController.isActiveSubId(subId);
4846 }
4847
Ihab Awadf2177b72013-11-25 13:33:23 -08004848 /**
4849 * @see android.telephony.TelephonyManager.WifiCallingChoices
4850 */
4851 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004854 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4856 getWhenToMakeWifiCallsDefaultPreference());
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004860 }
4861
4862 /**
4863 * @see android.telephony.TelephonyManager.WifiCallingChoices
4864 */
4865 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004869 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004874 }
4875
Sailesh Nepald1e68152013-12-12 19:08:02 -08004876 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004877 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004878 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004879 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004880
Jordan Liu4c733742019-02-28 12:03:40 -08004881 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4882 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4883 if (phoneId == -1) {
4884 throw new IllegalArgumentException("Given slot index: " + slotIndex
4885 + " does not correspond to an active phone");
4886 }
4887 return PhoneFactory.getPhone(phoneId);
4888 }
4889
Shishir Agrawal566b7612013-10-28 14:41:00 -07004890 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004891 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4892 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4894 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004896 if (DBG) {
4897 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4898 }
4899 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4900 p2);
4901 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004902
Jordan Liu4c733742019-02-28 12:03:40 -08004903
4904 @Override
4905 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4906 int slotIndex, String callingPackage, String aid, int p2) {
4907 enforceModifyPermission();
4908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4909 if (DBG) {
4910 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4911 }
4912 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4913 callingPackage, aid, p2);
4914 }
4915
4916 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4917 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 if (TextUtils.equals(ISDR_AID, aid)) {
4921 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004922 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4923 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 if (bestComponent == null
4925 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4926 loge("The calling package is not allowed to access ISD-R.");
4927 throw new SecurityException(
4928 "The calling package is not allowed to access ISD-R.");
4929 }
Derek Tan740e1672017-06-27 14:56:27 -07004930 }
Derek Tan740e1672017-06-27 14:56:27 -07004931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004933 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4934 null /* workSource */);
4935 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 return response;
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004940 }
4941
4942 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004943 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4945 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004946 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4947 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4948 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004949
Jordan Liu4c733742019-02-28 12:03:40 -08004950 @Override
4951 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4952 enforceModifyPermission();
4953 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4954 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4955 channel);
4956 }
4957
4958 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 if (channel < 0) {
4962 return false;
4963 }
Jordan Liu4c733742019-02-28 12:03:40 -08004964 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4965 null /* workSource */);
4966 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 return success;
4968 } finally {
4969 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004970 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004971 }
4972
4973 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004974 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004975 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4977 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004978 if (DBG) {
4979 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4980 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4981 + p3 + " data=" + data);
4982 }
4983 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4984 command, p1, p2, p3, data);
4985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004986
Jordan Liu4c733742019-02-28 12:03:40 -08004987 @Override
4988 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4989 int command, int p1, int p2, int p3, String data) {
4990 enforceModifyPermission();
4991 if (DBG) {
4992 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4993 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4994 + p3 + " data=" + data);
4995 }
4996 return iccTransmitApduLogicalChannelWithPermission(
4997 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4998 data);
4999 }
5000
5001 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5002 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 final long identity = Binder.clearCallingIdentity();
5004 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005005 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 return "";
5007 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005010 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5011 null /* workSource */);
5012 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 // Append the returned status code to the end of the response payload.
5015 String s = Integer.toHexString(
5016 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5017 if (response.payload != null) {
5018 s = IccUtils.bytesToHexString(response.payload) + s;
5019 }
5020 return s;
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005023 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005024 }
Jake Hambye994d462014-02-03 13:10:13 -08005025
Evan Charltonc66da362014-05-16 14:06:40 -07005026 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005027 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5028 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5030 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005032 if (DBG) {
5033 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5034 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5035 }
5036 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5037 cla, command, p1, p2, p3, data);
5038 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005039
Jordan Liu4c733742019-02-28 12:03:40 -08005040 @Override
5041 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5042 int command, int p1, int p2, int p3, String data) {
5043 enforceModifyPermission();
5044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5045 if (DBG) {
5046 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5047 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5048 + " data=" + data);
5049 }
5050
5051 return iccTransmitApduBasicChannelWithPermission(
5052 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5053 p2, p3, data);
5054 }
5055
5056 // open APDU basic channel assuming the caller has sufficient permissions
5057 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5058 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5062 && TextUtils.equals(ISDR_AID, data)) {
5063 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005064 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5065 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 if (bestComponent == null
5067 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5068 loge("The calling package is not allowed to select ISD-R.");
5069 throw new SecurityException(
5070 "The calling package is not allowed to select ISD-R.");
5071 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005072 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005075 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5076 null /* workSource */);
5077 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 // Append the returned status code to the end of the response payload.
5080 String s = Integer.toHexString(
5081 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5082 if (response.payload != null) {
5083 s = IccUtils.bytesToHexString(response.payload) + s;
5084 }
5085 return s;
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005088 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005089 }
5090
5091 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005092 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5095 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 if (DBG) {
5100 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5101 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5102 }
5103
5104 IccIoResult response =
5105 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5106 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5107 subId);
5108
5109 if (DBG) {
5110 log("Exchange SIM_IO [R]" + response);
5111 }
5112
5113 byte[] result = null;
5114 int length = 2;
5115 if (response.payload != null) {
5116 length = 2 + response.payload.length;
5117 result = new byte[length];
5118 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5119 } else {
5120 result = new byte[length];
5121 }
5122
5123 result[length - 1] = (byte) response.sw2;
5124 result[length - 2] = (byte) response.sw1;
5125 return result;
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005128 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005129 }
5130
Nathan Haroldb3014052017-01-25 15:57:32 -08005131 /**
5132 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5133 * on a particular subscription
5134 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005135 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5136 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005138 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005139 return null;
5140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 if (appType != TelephonyManager.APPTYPE_USIM
5145 && appType != TelephonyManager.APPTYPE_SIM) {
5146 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5147 return null;
5148 }
5149 Object response = sendRequest(
5150 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5151 if (response instanceof String[]) {
5152 return (String[]) response;
5153 }
yincheng zhao2737e882019-09-06 17:06:54 -07005154 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005156 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005159 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005160 }
5161
yincheng zhao2737e882019-09-06 17:06:54 -07005162 /**
5163 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5164 * subscription.
5165 *
5166 * @param subId the id of the subscription.
5167 * @param appType the uicc app type, must be USIM or SIM.
5168 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5169 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005170 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005171 * @return number of fplmns that is successfully written to the SIM.
5172 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005173 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5174 String callingFeatureId) {
5175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5176 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005177 if (DBG) logv("no permissions for setForbiddenplmns");
5178 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5179 }
5180 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5181 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5182 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5183 }
5184 if (fplmns == null) {
5185 throw new IllegalArgumentException("Fplmn List provided is null");
5186 }
5187 for (String fplmn : fplmns) {
5188 if (!CellIdentity.isValidPlmn(fplmn)) {
5189 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5190 }
5191 }
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 Object response = sendRequest(
5195 CMD_SET_FORBIDDEN_PLMNS,
5196 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5197 subId);
5198 return (int) response;
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005205 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5207 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 final long identity = Binder.clearCallingIdentity();
5210 try {
5211 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5212 if (response.payload == null) {
5213 return "";
5214 }
Evan Charltonc66da362014-05-16 14:06:40 -07005215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 // Append the returned status code to the end of the response payload.
5217 String s = Integer.toHexString(
5218 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5219 s = IccUtils.bytesToHexString(response.payload) + s;
5220 return s;
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
Evan Charltonc66da362014-05-16 14:06:40 -07005224 }
5225
Jake Hambye994d462014-02-03 13:10:13 -08005226 /**
5227 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5228 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5229 *
5230 * @param itemID the ID of the item to read
5231 * @return the NV item as a String, or null on error.
5232 */
5233 @Override
5234 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005235 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5237 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238
5239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005242 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5244 return value;
5245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Jake Hambye994d462014-02-03 13:10:13 -08005248 }
5249
5250 /**
5251 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5252 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5253 *
5254 * @param itemID the ID of the item to read
5255 * @param itemValue the value to write, as a String
5256 * @return true on success; false on any failure
5257 */
5258 @Override
5259 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5262 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263
5264 final long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5267 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005268 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5270 return success;
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Jake Hambye994d462014-02-03 13:10:13 -08005274 }
5275
5276 /**
5277 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5278 * Used for device configuration by some CDMA operators.
5279 *
5280 * @param preferredRoamingList byte array containing the new PRL
5281 * @return true on success; false on any failure
5282 */
5283 @Override
5284 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5286 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287
5288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5291 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5292 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5293 return success;
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Jake Hambye994d462014-02-03 13:10:13 -08005297 }
5298
5299 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005300 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005301 * Used for device configuration by some CDMA operators.
5302 *
chen xu6dac5ab2018-10-26 17:39:23 -07005303 * @param slotIndex - device slot.
5304 *
Jake Hambye994d462014-02-03 13:10:13 -08005305 * @return true on success; false on any failure
5306 */
5307 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005308 public boolean resetModemConfig(int slotIndex) {
5309 Phone phone = PhoneFactory.getPhone(slotIndex);
5310 if (phone != null) {
5311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5312 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313
chen xu6dac5ab2018-10-26 17:39:23 -07005314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5317 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5318 return success;
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
5321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 }
chen xu6dac5ab2018-10-26 17:39:23 -07005323 return false;
5324 }
5325
5326 /**
5327 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5328 *
5329 * @param slotIndex - device slot.
5330 *
5331 * @return true on success; false on any failure
5332 */
5333 @Override
5334 public boolean rebootModem(int slotIndex) {
5335 Phone phone = PhoneFactory.getPhone(slotIndex);
5336 if (phone != null) {
5337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5338 mApp, phone.getSubId(), "rebootModem");
5339
5340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5343 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5344 return success;
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
5348 }
5349 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005350 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005351
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005352 public String[] getPcscfAddress(String apnType, String callingPackage,
5353 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005354 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5356 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005357 return new String[0];
5358 }
5359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 final long identity = Binder.clearCallingIdentity();
5361 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005362 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
Wink Saville36469e72014-06-11 15:17:00 -07005366 }
5367
Brad Ebinger51f743a2017-01-23 13:50:20 -08005368 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005369 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5370 * {@link #disableIms(int)}.
5371 * @param slotIndex device slot.
5372 */
5373 public void resetIms(int slotIndex) {
5374 enforceModifyPermission();
5375
5376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 if (mImsResolver == null) {
5379 // may happen if the does not support IMS.
5380 return;
5381 }
5382 mImsResolver.disableIms(slotIndex);
5383 mImsResolver.enableIms(slotIndex);
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
5386 }
5387 }
5388
5389 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005390 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5391 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005392 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005393 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005394 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395
5396 final long identity = Binder.clearCallingIdentity();
5397 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005398 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005399 // may happen if the device does not support IMS.
5400 return;
5401 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005402 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005406 }
5407
5408 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005409 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5410 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005411 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005412 public void disableIms(int slotId) {
5413 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414
5415 final long identity = Binder.clearCallingIdentity();
5416 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005417 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005418 // may happen if the device does not support IMS.
5419 return;
5420 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005421 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005425 }
5426
5427 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005428 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5429 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005430 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005431 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005432 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -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 Ebinger67b3e042020-09-11 12:45:11 -07005438 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5439 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005440 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005441 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005445 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005446 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005447 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5448 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005449 @Override
5450 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005451 enforceModifyPermission();
5452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005456 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
5460 }
5461
5462 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005463 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005464 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005465 */
5466 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468
5469 final long identity = Binder.clearCallingIdentity();
5470 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005471 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005472 // may happen if the device does not support IMS.
5473 return null;
5474 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005475 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 } finally {
5477 Binder.restoreCallingIdentity(identity);
5478 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005479 }
5480
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005481 /**
5482 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005483 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005484 */
5485 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005491 // may happen if the device does not support IMS.
5492 return null;
5493 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005494 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005498 }
5499
Brad Ebinger884c07b2018-02-15 16:17:40 -08005500 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005501 * Sets the ImsService Package Name that Telephony will bind to.
5502 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005503 * @param slotIndex the slot ID that the ImsService should bind for.
5504 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005505 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005506 * @param featureTypes An integer array of feature types associated with a packageName.
5507 * @param packageName The name of the package that the current configuration will be replaced
5508 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005509 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005510 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005511 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5512 int[] featureTypes, String packageName) {
5513 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5514 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5516 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005517 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 final long identity = Binder.clearCallingIdentity();
5520 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005521 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005522 // may happen if the device does not support IMS.
5523 return false;
5524 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005525 Map<Integer, String> featureConfig = new HashMap<>();
5526 for (int featureType : featureTypes) {
5527 featureConfig.put(featureType, packageName);
5528 }
5529 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5530 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005534 }
5535
5536 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005537 * Clears any carrier ImsService overrides for the slot index specified that were previously
5538 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5539 *
5540 * This should only be used for testing.
5541 *
5542 * @param slotIndex the slot ID that the ImsService should bind for.
5543 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5544 */
5545 @Override
5546 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5547 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5548 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5549 "clearCarrierImsServiceOverride");
5550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5551 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5552 "clearCarrierImsServiceOverride");
5553
5554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 if (mImsResolver == null) {
5557 // may happen if the device does not support IMS.
5558 return false;
5559 }
5560 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
5564 }
5565
5566 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005567 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005568 *
5569 * @param slotId The slot that the ImsService is associated with.
5570 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5571 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005572 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005573 * @return the package name of the ImsService configuration.
5574 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005575 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5576 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005577 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005578 TelephonyPermissions
5579 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5580 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5581 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 final long identity = Binder.clearCallingIdentity();
5584 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005585 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005586 // may happen if the device does not support IMS.
5587 return "";
5588 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005589 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005590 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5591 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005595 }
5596
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005597 /**
5598 * Get the MmTelFeature state associated with the requested subscription id.
5599 * @param subId The subscription that the MmTelFeature is associated with.
5600 * @param callback A callback with an integer containing the
5601 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5602 */
5603 @Override
5604 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5605 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5606 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5607 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5608 "IMS not available on device.");
5609 }
5610 final long token = Binder.clearCallingIdentity();
5611 try {
5612 int slotId = getSlotIndex(subId);
5613 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5614 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5615 + subId + "'");
5616 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5617 }
5618 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5619 try {
5620 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5621 } catch (RemoteException e) {
5622 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5623 + "Ignore");
5624 }
5625 });
5626 } finally {
5627 Binder.restoreCallingIdentity(token);
5628 }
5629 }
5630
Daniel Brightbb5840b2021-01-12 15:48:18 -08005631 /**
5632 * Sets the ims registration state on all valid {@link Phone}s.
5633 */
5634 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005639 // NOTE: Before S, this method only set the default phone.
5640 for (final Phone phone : PhoneFactory.getPhones()) {
5641 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5642 phone.setImsRegistrationState(registered);
5643 }
5644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Wink Saville36469e72014-06-11 15:17:00 -07005648 }
5649
5650 /**
Stuart Scott54788802015-03-30 13:18:01 -07005651 * Set the network selection mode to automatic.
5652 *
5653 */
5654 @Override
5655 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5657 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
shilufc958392020-01-20 11:36:01 -08005661 if (!isActiveSubscription(subId)) {
5662 return;
5663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5665 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Stuart Scott54788802015-03-30 13:18:01 -07005669 }
5670
Jack Yud10cdd42020-09-28 20:28:01 -07005671 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005672 * Ask the radio to connect to the input network and change selection mode to manual.
5673 *
5674 * @param subId the id of the subscription.
5675 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5676 * the operator to attach to.
5677 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5678 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5679 * normal network selection next time.
5680 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005681 */
5682 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005683 public boolean setNetworkSelectionModeManual(
5684 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5686 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005687
5688 if (!isActiveSubscription(subId)) {
5689 return false;
5690 }
5691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005694 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005696 if (DBG) {
5697 log("setNetworkSelectionModeManual: subId: " + subId
5698 + " operator: " + operatorInfo);
5699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005704 }
shilu84f6e8b2019-12-19 13:58:01 -08005705 /**
5706 * Get the manual network selection
5707 *
5708 * @param subId the id of the subscription.
5709 *
5710 * @return the previously saved user selected PLMN
5711 */
5712 @Override
5713 public String getManualNetworkSelectionPlmn(int subId) {
5714 TelephonyPermissions
5715 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5716 mApp, subId, "getManualNetworkSelectionPlmn");
5717
5718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005721 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005722 }
5723
5724 final Phone phone = getPhone(subId);
5725 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005726 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005727 }
5728 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5729 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5730 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
5734 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005735
5736 /**
5737 * Scans for available networks.
5738 */
5739 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005740 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5741 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5743 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005744 LocationAccessPolicy.LocationPermissionResult locationResult =
5745 LocationAccessPolicy.checkLocationPermission(mApp,
5746 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5747 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005748 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005749 .setCallingPid(Binder.getCallingPid())
5750 .setCallingUid(Binder.getCallingUid())
5751 .setMethod("getCellNetworkScanResults")
5752 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005753 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5754 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005755 .build());
5756 switch (locationResult) {
5757 case DENIED_HARD:
5758 throw new SecurityException("Not allowed to access scan results -- location");
5759 case DENIED_SOFT:
5760 return null;
5761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
Pengquan Menga1bb6272018-09-06 09:59:22 -07005763 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 try {
5765 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005766 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005771 }
5772
5773 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005774 * Get the call forwarding info, given the call forwarding reason.
5775 */
5776 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005777 public void getCallForwarding(int subId, int callForwardingReason,
5778 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005779 enforceReadPrivilegedPermission("getCallForwarding");
5780 long identity = Binder.clearCallingIdentity();
5781 try {
5782 if (DBG) {
5783 log("getCallForwarding: subId " + subId
5784 + " callForwardingReason" + callForwardingReason);
5785 }
Hall Liu27d24262020-09-18 19:04:59 -07005786
5787 Phone phone = getPhone(subId);
5788 if (phone == null) {
5789 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005790 callback.onError(
5791 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005792 } catch (RemoteException e) {
5793 // ignore
5794 }
5795 return;
5796 }
5797
5798 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5799 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5800 @Override
5801 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5802 try {
5803 callback.onCallForwardingInfoAvailable(info);
5804 } catch (RemoteException e) {
5805 // ignore
5806 }
5807 }
5808
5809 @Override
5810 public void onError(int error) {
5811 try {
5812 callback.onError(error);
5813 } catch (RemoteException e) {
5814 // ignore
5815 }
5816 }
5817 });
5818 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
5822 }
5823
5824 /**
5825 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5826 * reason, the number to forward, and the timeout before the forwarding is attempted.
5827 */
5828 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005829 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5830 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005831 enforceModifyPermission();
5832 long identity = Binder.clearCallingIdentity();
5833 try {
5834 if (DBG) {
5835 log("setCallForwarding: subId " + subId
5836 + " callForwardingInfo" + callForwardingInfo);
5837 }
Hall Liu27d24262020-09-18 19:04:59 -07005838
5839 Phone phone = getPhone(subId);
5840 if (phone == null) {
5841 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005842 callback.accept(
5843 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005844 } catch (RemoteException e) {
5845 // ignore
5846 }
5847 return;
5848 }
5849
5850 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5851 FunctionalUtils.ignoreRemoteException(callback::accept));
5852
5853 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
5857 }
5858
5859 /**
Hall Liu27d24262020-09-18 19:04:59 -07005860 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005861 */
5862 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005863 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005864 enforceReadPrivilegedPermission("getCallForwarding");
5865 long identity = Binder.clearCallingIdentity();
5866 try {
Hall Liu27d24262020-09-18 19:04:59 -07005867
5868 Phone phone = getPhone(subId);
5869 if (phone == null) {
5870 try {
5871 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5872 } catch (RemoteException e) {
5873 // ignore
5874 }
5875 return;
5876 }
5877
5878 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5879
Shuo Qian4a594052020-01-23 11:59:30 -08005880 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005881 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
5885 }
5886
5887 /**
Hall Liu27d24262020-09-18 19:04:59 -07005888 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005889 */
5890 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005891 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005892 enforceModifyPermission();
5893 long identity = Binder.clearCallingIdentity();
5894 try {
Hall Liu27d24262020-09-18 19:04:59 -07005895 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5896
5897 Phone phone = getPhone(subId);
5898 if (phone == null) {
5899 try {
5900 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5901 } catch (RemoteException e) {
5902 // ignore
5903 }
5904 return;
5905 }
5906
5907 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5908 FunctionalUtils.ignoreRemoteException(callback::accept));
5909
5910 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
5914 }
5915
5916 /**
yinxub1bed742017-04-17 11:45:04 -07005917 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005918 *
yinxub1bed742017-04-17 11:45:04 -07005919 * @param subId id of the subscription
5920 * @param request contains the radio access networks with bands/channels to scan
5921 * @param messenger callback messenger for scan results or errors
5922 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005923 * @return the id of the requested scan which can be used to stop the scan.
5924 */
5925 @Override
5926 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005927 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5929 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005930 LocationAccessPolicy.LocationPermissionResult locationResult =
5931 LocationAccessPolicy.checkLocationPermission(mApp,
5932 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5933 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005934 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005935 .setCallingPid(Binder.getCallingPid())
5936 .setCallingUid(Binder.getCallingUid())
5937 .setMethod("requestNetworkScan")
5938 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005939 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5940 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005941 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005942 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005943 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5944 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005945 if (e != null) {
5946 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5947 throw e;
5948 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005949 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005950 return TelephonyScanManager.INVALID_SCAN_ID;
5951 }
5952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 }
Hall Liu912dfd32019-04-25 14:02:26 -07005954 int callingUid = Binder.getCallingUid();
5955 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 return mNetworkScanRequestTracker.startNetworkScan(
5959 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005960 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
yinxu504e1392017-04-12 16:03:22 -07005964 }
5965
Hall Liub2ac8ef2019-02-28 15:56:23 -08005966 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005967 NetworkScanRequest request, int subId, String callingPackage) {
5968 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005969 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5970 boolean hasNetworkScanPermission =
5971 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5972 == PERMISSION_GRANTED;
5973
5974 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5975 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5976 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005977 }
5978
5979 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5980 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005981 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5982 return new SecurityException("Specific channels must not be"
5983 + " scanned without location access.");
5984 }
5985 }
5986 }
5987
Hall Liub2ac8ef2019-02-28 15:56:23 -08005988 return null;
5989 }
5990
yinxu504e1392017-04-12 16:03:22 -07005991 /**
5992 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005993 *
5994 * @param subId id of the subscription
5995 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005996 */
5997 @Override
5998 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
Hall Liu912dfd32019-04-25 14:02:26 -07006002 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 final long identity = Binder.clearCallingIdentity();
6004 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006005 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
yinxu504e1392017-04-12 16:03:22 -07006009 }
6010
6011 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006012 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006013 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006014 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006015 */
6016 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006017 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006018 TelephonyPermissions
6019 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006020 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021
6022 final long identity = Binder.clearCallingIdentity();
6023 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006024 if (DBG) log("getAllowedNetworkTypesBitmask");
6025 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6026 int networkTypesBitmask = (result != null ? result[0] : -1);
6027 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6028 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006032 }
6033
6034 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006035 * Get the allowed network types for certain reason.
6036 *
6037 * @param subId the id of the subscription.
6038 * @param reason the reason the allowed network type change is taking place
6039 * @return the allowed network types.
6040 */
6041 @Override
6042 public long getAllowedNetworkTypesForReason(int subId,
6043 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6044 TelephonyPermissions
6045 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6046 mApp, subId, "getAllowedNetworkTypesForReason");
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
6053 }
6054
6055 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006056 * Enable/Disable E-UTRA-NR Dual Connectivity
6057 * @param subId subscription id of the sim card
6058 * @param nrDualConnectivityState expected NR dual connectivity state
6059 * This can be passed following states
6060 * <ol>
6061 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6062 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6063 * <li>Disable NR dual connectivity and force secondary cell to be released
6064 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6065 * </ol>
6066 * @return operation result.
6067 */
6068 @Override
6069 public int setNrDualConnectivityState(int subId,
6070 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6072 mApp, subId, "enableNRDualConnectivity");
6073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6077 nrDualConnectivityState, subId,
6078 workSource);
6079 if (DBG) log("enableNRDualConnectivity result: " + result);
6080 return result;
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
6084 }
6085
6086 /**
6087 * Is E-UTRA-NR Dual Connectivity enabled
6088 * @return true if dual connectivity is enabled else false
6089 */
6090 @Override
6091 public boolean isNrDualConnectivityEnabled(int subId) {
6092 TelephonyPermissions
6093 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6094 mApp, subId, "isNRDualConnectivityEnabled");
6095 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6099 null, subId, workSource);
6100 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6101 return isEnabled;
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
6104 }
6105 }
6106
6107 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006108 * get carrier bandwidth per primary and secondary carrier
6109 * @param subId subscription id of the sim card
6110 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6111 */
6112 @Override
6113 public CarrierBandwidth getCarrierBandwidth(int subId) {
6114 TelephonyPermissions
6115 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6116 mApp, subId, "isNRDualConnectivityEnabled");
6117 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6118 final long identity = Binder.clearCallingIdentity();
6119 try {
6120 CarrierBandwidth carrierBandwidth =
6121 getPhoneFromSubId(subId).getCarrierBandwidth();
6122 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6123 return carrierBandwidth;
6124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
6127 }
6128
6129 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006130 * Set the allowed network types of the device and
6131 * provide the reason triggering the allowed network change.
6132 *
6133 * @param subId the id of the subscription.
6134 * @param reason the reason the allowed network type change is taking place
6135 * @param allowedNetworkTypes the allowed network types.
6136 * @return true on success; false on any failure.
6137 */
6138 @Override
6139 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006140 @TelephonyManager.AllowedNetworkTypesReason int reason,
6141 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6143 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006144 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6145 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6146 return false;
6147 }
6148
6149 if (DBG) {
6150 log("setAllowedNetworkTypesForReason: " + reason
6151 + " value: " + allowedNetworkTypes);
6152 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006153 final long identity = Binder.clearCallingIdentity();
6154 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006155 Boolean success = (Boolean) sendRequest(
6156 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6157 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6158
6159 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6160 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
6164 }
6165
6166 /**
Miaoa84611c2019-03-15 09:21:10 +08006167 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006168 *
Miaoa84611c2019-03-15 09:21:10 +08006169 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006170 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006171 * @hide
6172 */
6173 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006174 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006177 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 try {
Miaoa84611c2019-03-15 09:21:10 +08006179 if (phone != null) {
6180 return phone.hasMatchedTetherApnSetting();
6181 } else {
6182 return false;
6183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 } finally {
6185 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006186 }
Junda Liu475951f2014-11-07 16:45:03 -08006187 }
6188
6189 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006190 * Enable or disable always reporting signal strength changes from radio.
6191 *
6192 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6193 */
6194 @Override
6195 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6196 enforceModifyPermission();
6197 enforceSystemCaller();
6198
6199 final long identity = Binder.clearCallingIdentity();
6200 final Phone phone = getPhone(subId);
6201 try {
6202 if (phone != null) {
6203 if (DBG) {
6204 log("setAlwaysReportSignalStrength: subId=" + subId
6205 + " isEnable=" + isEnable);
6206 }
6207 phone.setAlwaysReportSignalStrength(isEnable);
6208 } else {
6209 loge("setAlwaysReportSignalStrength: no phone found for subId="
6210 + subId);
6211 }
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
6215 }
6216
6217 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006218 * Get the user enabled state of Mobile Data.
6219 *
6220 * TODO: remove and use isUserDataEnabled.
6221 * This can't be removed now because some vendor codes
6222 * calls through ITelephony directly while they should
6223 * use TelephonyManager.
6224 *
6225 * @return true on enabled
6226 */
6227 @Override
6228 public boolean getDataEnabled(int subId) {
6229 return isUserDataEnabled(subId);
6230 }
6231
6232 /**
6233 * Get whether mobile data is enabled per user setting.
6234 *
6235 * There are other factors deciding whether mobile data is actually enabled, but they are
6236 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006237 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006238 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006239 *
6240 * @return {@code true} if data is enabled else {@code false}
6241 */
6242 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006243 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006244 try {
6245 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6246 null);
6247 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6249 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251
6252 final long identity = Binder.clearCallingIdentity();
6253 try {
6254 int phoneId = mSubscriptionController.getPhoneId(subId);
6255 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6256 Phone phone = PhoneFactory.getPhone(phoneId);
6257 if (phone != null) {
6258 boolean retVal = phone.isUserDataEnabled();
6259 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6260 return retVal;
6261 } else {
6262 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6263 return false;
6264 }
6265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006267 }
6268 }
6269
6270 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006271 * Checks if the device is capable of mobile data by considering whether whether the
6272 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6273 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006274 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006275 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006276 */
6277 @Override
6278 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006279 try {
6280 try {
6281 mApp.enforceCallingOrSelfPermission(
6282 android.Manifest.permission.ACCESS_NETWORK_STATE,
6283 null);
6284 } catch (Exception e) {
6285 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6286 "isDataEnabled");
6287 }
6288 } catch (Exception e) {
6289 enforceReadPrivilegedPermission("isDataEnabled");
6290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291
6292 final long identity = Binder.clearCallingIdentity();
6293 try {
6294 int phoneId = mSubscriptionController.getPhoneId(subId);
6295 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6296 Phone phone = PhoneFactory.getPhone(phoneId);
6297 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006298 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6300 return retVal;
6301 } else {
6302 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6303 return false;
6304 }
6305 } finally {
6306 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006307 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006308 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006309
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006310 /**
6311 * Check if data is enabled for a specific reason
6312 * @param subId Subscription index
6313 * @param reason the reason the data enable change is taking place
6314 * @return {@code true} if the overall data is enabled; {@code false} if not.
6315 */
6316 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006317 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006318 @TelephonyManager.DataEnabledReason int reason) {
6319 try {
6320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6321 null);
6322 } catch (Exception e) {
6323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006324 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006325 }
6326
6327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 int phoneId = mSubscriptionController.getPhoneId(subId);
6331 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006332 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006333 + " reason=" + reason);
6334 }
6335 Phone phone = PhoneFactory.getPhone(phoneId);
6336 if (phone != null) {
6337 boolean retVal;
6338 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6339 retVal = phone.isUserDataEnabled();
6340 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006341 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006342 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006343 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006344 return retVal;
6345 } else {
6346 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006347 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006348 + subId + " retVal=false");
6349 }
6350 return false;
6351 }
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
6355 }
6356
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006357 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006358 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006359 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6360 // Skip the check if it's one of these special uids
6361 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6362 }
6363
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006364 //load access rules from carrier configs, and check those as well: b/139133814
6365 SubscriptionController subController = SubscriptionController.getInstance();
6366 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6367 || subController == null) return privilegeFromSim;
6368
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006369 PackageManager pkgMgr = phone.getContext().getPackageManager();
6370 String[] packages = pkgMgr.getPackagesForUid(uid);
6371
6372 final long identity = Binder.clearCallingIdentity();
6373 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006374 int subId = phone.getSubId();
6375 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6376 // A test override is in place for the privileges for this subId, so don't try to
6377 // read the subscription privileges.
6378 return privilegeFromSim;
6379 }
6380 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006381 SubscriptionManager subManager = (SubscriptionManager)
6382 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6383 for (String pkg : packages) {
6384 if (subManager.canManageSubscription(subInfo, pkg)) {
6385 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6386 }
6387 }
6388 return privilegeFromSim;
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
6392 }
6393
6394 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6395 String pkgName) {
6396 //load access rules from carrier configs, and check those as well: b/139133814
6397 SubscriptionController subController = SubscriptionController.getInstance();
6398 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6399 || subController == null) return privilegeFromSim;
6400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006403 int subId = phone.getSubId();
6404 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6405 // A test override is in place for the privileges for this subId, so don't try to
6406 // read the subscription privileges.
6407 return privilegeFromSim;
6408 }
6409 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006410 SubscriptionManager subManager = (SubscriptionManager)
6411 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6412 return subManager.canManageSubscription(subInfo, pkgName)
6413 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
6417 }
6418
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006419 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006420 public int getCarrierPrivilegeStatus(int subId) {
6421 final Phone phone = getPhone(subId);
6422 if (phone == null) {
6423 loge("getCarrierPrivilegeStatus: Invalid subId");
6424 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6425 }
6426 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006427 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006428 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006429 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6430 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006431
6432 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6433 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006434 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006435 }
Junda Liu29340342014-07-10 15:23:27 -07006436
6437 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006438 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006439 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006440 final Phone phone = getPhone(subId);
6441 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006442 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006443 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6444 }
6445 UiccProfile profile =
6446 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6447 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006448 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6450 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006451 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006452 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006453 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006454 }
6455
6456 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006457 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6458 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006460 }
6461
6462 int phoneId = SubscriptionManager.getPhoneId(subId);
6463 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006464 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006465 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006466 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6467 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006468 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6469 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6470 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006471 }
6472
6473 @Override
6474 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006475 if (TextUtils.isEmpty(pkgName))
6476 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006477 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6478 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6479 UiccCard card = UiccController.getInstance().getUiccCard(i);
6480 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006481 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006482 continue;
6483 }
6484
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006485 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6486 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6487 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006488 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6489 break;
6490 }
6491 }
6492
6493 return result;
Junda Liu29340342014-07-10 15:23:27 -07006494 }
Derek Tan89e89d42014-07-08 17:00:10 -07006495
6496 @Override
Junda Liue64de782015-04-16 17:19:16 -07006497 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6498 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6499 loge("phoneId " + phoneId + " is not valid.");
6500 return null;
6501 }
6502 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006503 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006504 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006505 return null ;
6506 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006507 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006508 }
6509
Amith Yamasani6e118872016-02-19 12:53:51 -08006510 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006511 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006512 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006513 List<String> privilegedPackages = new ArrayList<>();
6514 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006515 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6516 // has UICC in that slot.
6517 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006518 if (card.hasCarrierPrivilegeRules()) {
6519 if (packages == null) {
6520 // Only check packages in user 0 for now
6521 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006522 PackageManager.MATCH_DISABLED_COMPONENTS
6523 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006524 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006525 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006526 }
6527 for (int p = packages.size() - 1; p >= 0; p--) {
6528 PackageInfo pkgInfo = packages.get(p);
6529 if (pkgInfo != null && pkgInfo.packageName != null
6530 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006531 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006532 privilegedPackages.add(pkgInfo.packageName);
6533 }
6534 }
6535 }
6536 }
6537 return privilegedPackages;
6538 }
6539
chen xuf7e9fe82019-05-09 19:31:02 -07006540 @Override
6541 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006542 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6543
6544 final long identity = Binder.clearCallingIdentity();
6545
chen xuf7e9fe82019-05-09 19:31:02 -07006546 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006547 try {
6548 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6549 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6550 }
6551 } finally {
6552 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006553 }
6554 return privilegedPackages;
6555 }
6556
Wink Savilleb564aae2014-10-23 10:18:09 -07006557 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006558 final Phone phone = getPhone(subId);
6559 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006560 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006561 return null;
6562 }
6563 String iccId = card.getIccId();
6564 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006565 return null;
6566 }
6567 return iccId;
6568 }
6569
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006570 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006571 public void setCallComposerStatus(int subId, int status) {
6572 enforceModifyPermission();
6573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 Phone phone = getPhone(subId);
6577 if (phone != null) {
6578 Phone defaultPhone = phone.getImsPhone();
6579 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6580 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6581 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006582 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6583 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006584 }
6585 }
Shuo Qian284ae752020-12-22 19:10:14 -08006586 } catch (ImsException e) {
6587 throw new ServiceSpecificException(e.getCode());
6588 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006589 Binder.restoreCallingIdentity(identity);
6590 }
6591 }
6592
6593 @Override
6594 public int getCallComposerStatus(int subId) {
6595 enforceReadPrivilegedPermission("getCallComposerStatus");
6596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 Phone phone = getPhone(subId);
6600 if (phone != null) {
6601 Phone defaultPhone = phone.getImsPhone();
6602 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6603 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6604 return imsPhone.getCallComposerStatus();
6605 }
6606 }
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
6610 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6611 }
6612
6613 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006614 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6615 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006616 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006617 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 final String iccId = getIccId(subId);
6622 final Phone phone = getPhone(subId);
6623 if (phone == null) {
6624 return false;
6625 }
6626 final String subscriberId = phone.getSubscriberId();
6627
6628 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006629 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 + subscriberId + " to " + number);
6631 }
6632
6633 if (TextUtils.isEmpty(iccId)) {
6634 return false;
6635 }
6636
6637 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6638
6639 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6640 if (alphaTag == null) {
6641 editor.remove(alphaTagPrefKey);
6642 } else {
6643 editor.putString(alphaTagPrefKey, alphaTag);
6644 }
6645
6646 // Record both the line number and IMSI for this ICCID, since we need to
6647 // track all merged IMSIs based on line number
6648 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6649 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6650 if (number == null) {
6651 editor.remove(numberPrefKey);
6652 editor.remove(subscriberPrefKey);
6653 } else {
6654 editor.putString(numberPrefKey, number);
6655 editor.putString(subscriberPrefKey, subscriberId);
6656 }
6657
6658 editor.commit();
6659 return true;
6660 } finally {
6661 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006662 }
Derek Tan7226c842014-07-02 17:42:23 -07006663 }
6664
6665 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006666 public String getLine1NumberForDisplay(int subId, String callingPackage,
6667 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006668 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006670 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006671 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006672 return null;
6673 }
Derek Tan97ebb422014-09-05 16:55:38 -07006674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675 final long identity = Binder.clearCallingIdentity();
6676 try {
6677 String iccId = getIccId(subId);
6678 if (iccId != null) {
6679 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6680 if (DBG_MERGE) {
6681 log("getLine1NumberForDisplay returning "
6682 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6683 }
6684 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6687 return null;
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006690 }
Derek Tan7226c842014-07-02 17:42:23 -07006691 }
6692
6693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006694 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6695 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006697 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006698 return null;
6699 }
Derek Tan97ebb422014-09-05 16:55:38 -07006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 String iccId = getIccId(subId);
6704 if (iccId != null) {
6705 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6706 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6707 }
6708 return null;
6709 } finally {
6710 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006711 }
Derek Tan7226c842014-07-02 17:42:23 -07006712 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006713
6714 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006715 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6716 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006717 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6718 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006720 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006721 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006722 return null;
6723 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006724
Jordan Liub49b04b2019-05-06 14:45:15 -07006725 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6726 // the process, where TelephonyManager was instantiated.
6727 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006728 final long identity = Binder.clearCallingIdentity();
6729 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006730 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 final TelephonyManager tele = TelephonyManager.from(context);
6732 final SubscriptionManager sub = SubscriptionManager.from(context);
6733
6734 // Figure out what subscribers are currently active
6735 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
Jordan Liub49b04b2019-05-06 14:45:15 -07006737 // Only consider subs which match the current subId
6738 // This logic can be simplified. See b/131189269 for progress.
6739 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006740 activeSubscriberIds.add(tele.getSubscriberId(subId));
6741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742
6743 // First pass, find a number override for an active subscriber
6744 String mergeNumber = null;
6745 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6746 for (String key : prefs.keySet()) {
6747 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6748 final String subscriberId = (String) prefs.get(key);
6749 if (activeSubscriberIds.contains(subscriberId)) {
6750 final String iccId = key.substring(
6751 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6752 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6753 mergeNumber = (String) prefs.get(numberKey);
6754 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006755 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 + " for active subscriber " + subscriberId);
6757 }
6758 if (!TextUtils.isEmpty(mergeNumber)) {
6759 break;
6760 }
6761 }
6762 }
6763 }
6764
6765 // Shortcut when no active merged subscribers
6766 if (TextUtils.isEmpty(mergeNumber)) {
6767 return null;
6768 }
6769
6770 // Second pass, find all subscribers under that line override
6771 final ArraySet<String> result = new ArraySet<>();
6772 for (String key : prefs.keySet()) {
6773 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6774 final String number = (String) prefs.get(key);
6775 if (mergeNumber.equals(number)) {
6776 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6777 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6778 final String subscriberId = (String) prefs.get(subscriberKey);
6779 if (!TextUtils.isEmpty(subscriberId)) {
6780 result.add(subscriberId);
6781 }
6782 }
6783 }
6784 }
6785
6786 final String[] resultArray = result.toArray(new String[result.size()]);
6787 Arrays.sort(resultArray);
6788 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006789 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6791 }
6792 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006793 } finally {
6794 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006795 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006796 }
6797
6798 @Override
zoey chen38003472019-12-13 17:16:31 +08006799 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6800 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 final TelephonyManager telephonyManager = mApp.getSystemService(
6805 TelephonyManager.class);
6806 String subscriberId = telephonyManager.getSubscriberId(subId);
6807 if (subscriberId == null) {
6808 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006809 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006810 + subId);
6811 }
6812 return null;
6813 }
6814
6815 final SubscriptionInfo info = SubscriptionController.getInstance()
6816 .getSubscriptionInfo(subId);
6817 final ParcelUuid groupUuid = info.getGroupUuid();
6818 // If it doesn't belong to any group, return just subscriberId of itself.
6819 if (groupUuid == null) {
6820 return new String[]{subscriberId};
6821 }
6822
6823 // Get all subscriberIds from the group.
6824 final List<String> mergedSubscriberIds = new ArrayList<>();
6825 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006826 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006827 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006828 for (SubscriptionInfo subInfo : groupInfos) {
6829 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6830 if (subscriberId != null) {
6831 mergedSubscriberIds.add(subscriberId);
6832 }
6833 }
6834
6835 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6836 } finally {
6837 Binder.restoreCallingIdentity(identity);
6838
6839 }
6840 }
6841
6842 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006843 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006844 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846
6847 final long identity = Binder.clearCallingIdentity();
6848 try {
6849 final Phone phone = getPhone(subId);
6850 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6851 } finally {
6852 Binder.restoreCallingIdentity(identity);
6853 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006854 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006855
6856 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006857 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006858 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6859 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006860 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6861 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 final Phone phone = getPhone(subId);
6866 if (phone == null) {
6867 return false;
6868 }
6869 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6870 cdmaNonRoamingList);
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006873 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006874 }
6875
6876 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006877 @Deprecated
6878 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6879 enforceModifyPermission();
6880
6881 int returnValue = 0;
6882 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006883 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006884 if(result.exception == null) {
6885 if (result.result != null) {
6886 byte[] responseData = (byte[])(result.result);
6887 if(responseData.length > oemResp.length) {
6888 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6889 responseData.length + "bytes. Buffer Size is " +
6890 oemResp.length + "bytes.");
6891 }
6892 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6893 returnValue = responseData.length;
6894 }
6895 } else {
6896 CommandException ex = (CommandException) result.exception;
6897 returnValue = ex.getCommandError().ordinal();
6898 if(returnValue > 0) returnValue *= -1;
6899 }
6900 } catch (RuntimeException e) {
6901 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6902 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6903 if(returnValue > 0) returnValue *= -1;
6904 }
6905
6906 return returnValue;
6907 }
6908
6909 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006910 public void setRadioCapability(RadioAccessFamily[] rafs) {
6911 try {
6912 ProxyController.getInstance().setRadioCapability(rafs);
6913 } catch (RuntimeException e) {
6914 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6915 }
6916 }
6917
6918 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006919 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006920 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006921 try {
6922 TelephonyPermissions
6923 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6924 mApp, phone.getSubId(), "getRadioAccessFamily");
6925 } catch (SecurityException e) {
6926 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6927 throw e;
6928 }
chen xub97461a2018-10-26 14:17:57 -07006929 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006930 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006931 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006933 final long identity = Binder.clearCallingIdentity();
6934 try {
chen xub97461a2018-10-26 14:17:57 -07006935 TelephonyPermissions
6936 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6937 mApp, phone.getSubId(), "getRadioAccessFamily");
6938 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
chen xub97461a2018-10-26 14:17:57 -07006942 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006943 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006944
6945 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006946 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08006947 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08006948 try {
6949 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6950 Binder.getCallingUid())) {
6951 throw new SecurityException("Package uid and package name do not match: "
6952 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6953 }
6954 } catch (PackageManager.NameNotFoundException e) {
6955 throw new SecurityException("Package name invalid:" + callingPackage);
6956 }
6957 RoleManager rm = mApp.getSystemService(RoleManager.class);
6958 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6959 if (!dialerRoleHolders.contains(callingPackage)) {
6960 throw new SecurityException("App must be the dialer role holder to"
6961 + " upload a call composer pic");
6962 }
6963
6964 Executors.newSingleThreadExecutor().execute(() -> {
6965 ByteArrayOutputStream output = new ByteArrayOutputStream(
6966 (int) TelephonyManager.getMaximumCallComposerPictureSize());
6967 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
6968 boolean readUntilEnd = false;
6969 int totalBytesRead = 0;
6970 byte[] buffer = new byte[16 * 1024];
6971 while (true) {
6972 int numRead;
6973 try {
6974 numRead = input.read(buffer);
6975 } catch (IOException e) {
6976 try {
6977 fd.checkError();
6978 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
6979 null);
6980 } catch (IOException e1) {
6981 // This means that the other side closed explicitly with an error. If this
6982 // happens, log and ignore.
6983 loge("Remote end of call composer picture pipe closed: " + e1);
6984 }
6985 break;
6986 }
6987 if (numRead == -1) {
6988 readUntilEnd = true;
6989 break;
6990 }
6991 totalBytesRead += numRead;
6992 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
6993 loge("Too many bytes read for call composer picture: " + totalBytesRead);
6994 try {
6995 input.close();
6996 } catch (IOException e) {
6997 // ignore
6998 }
6999 break;
7000 }
7001 output.write(buffer, 0, numRead);
7002 }
7003 // Generally, the remote end will close the file descriptors. The only case where we
7004 // close is above, where the picture size is too big.
7005
7006 try {
7007 fd.checkError();
7008 } catch (IOException e) {
7009 loge("Remote end for call composer closed with an error: " + e);
7010 return;
7011 }
7012
Hall Liuaa4211e2021-01-20 15:43:39 -08007013 if (!readUntilEnd) {
7014 loge("Did not finish reading entire image; aborting");
7015 return;
7016 }
Hall Liu82694d52020-12-11 18:22:04 -08007017
Hall Liuaa4211e2021-01-20 15:43:39 -08007018 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7019 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7020 new CallComposerPictureTransfer.Factory() {},
7021 imageData,
7022 (result) -> {
7023 if (result.first != null) {
7024 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7025 Bundle outputResult = new Bundle();
7026 outputResult.putParcelable(
7027 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7028 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7029 outputResult);
7030 } else {
7031 callback.send(result.second, null);
7032 }
7033 }
7034 );
Hall Liu82694d52020-12-11 18:22:04 -08007035 });
7036 }
7037
7038 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007039 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007040 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042
7043 final long identity = Binder.clearCallingIdentity();
7044 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007045 ImsManager.getInstance(defaultPhone.getContext(),
7046 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007050 }
7051
7052 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007053 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007054 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7056 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007057 return false;
7058 }
Svet Ganovb320e182015-04-16 12:30:10 -07007059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007060 final long identity = Binder.clearCallingIdentity();
7061 try {
7062 // Check the user preference and the system-level IMS setting. Even if the user has
7063 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7064 // In the long run, we may instead need to check if there exists a connection service
7065 // which can support video calling.
7066 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007067 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 return imsManager.isVtEnabledByPlatform()
7069 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7070 && imsManager.isVtEnabledByUser();
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007074 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007075
Andrew Leea1239f22015-03-02 17:44:07 -08007076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007077 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7078 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007080 mApp, subId, callingPackage, callingFeatureId,
7081 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 return false;
7083 }
7084
7085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 CarrierConfigManager configManager =
7088 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007089 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
Andrew Leea1239f22015-03-02 17:44:07 -08007094 }
7095
7096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007097 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007099 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 return false;
7101 }
7102
7103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 CarrierConfigManager configManager =
7106 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007107 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
7111 }
Andrew Leea1239f22015-03-02 17:44:07 -08007112 }
7113
Andrew Lee9431b832015-03-09 18:46:45 -07007114 @Override
7115 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007116 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007117 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007118 }
7119
7120 @Override
7121 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 final long identity = Binder.clearCallingIdentity();
7123 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 } finally {
7126 Binder.restoreCallingIdentity(identity);
7127 }
Andrew Lee9431b832015-03-09 18:46:45 -07007128 }
7129
Hall Liuf6668912018-10-31 17:05:23 -07007130 /**
7131 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7132 * support for the feature and device firmware support.
7133 *
7134 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7135 */
7136 @Override
7137 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007139 final Phone phone = getPhone(subscriptionId);
7140 if (phone == null) {
7141 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7142 return false;
7143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007145 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7147 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007148 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 return isCarrierSupported && isDeviceSupported;
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
7152 }
Hall Liu98187582018-01-22 19:15:32 -08007153 }
7154
Hall Liuf6668912018-10-31 17:05:23 -07007155 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007156 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7157 * RTT setting, will return true if the device and carrier both support RTT.
7158 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007159 */
7160 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 final long identity = Binder.clearCallingIdentity();
7162 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007163 boolean isRttSupported = isRttSupported(subscriptionId);
7164 boolean isUserRttSettingOn = Settings.Secure.getInt(
7165 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7166 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7167 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7168 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 } finally {
7170 Binder.restoreCallingIdentity(identity);
7171 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007172 }
7173
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 @Deprecated
7175 @Override
7176 public String getDeviceId(String callingPackage) {
7177 return getDeviceIdWithFeature(callingPackage, null);
7178 }
7179
Sanket Padawe7310cc72015-01-14 09:53:20 -08007180 /**
7181 * Returns the unique device ID of phone, for example, the IMEI for
7182 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7183 *
7184 * <p>Requires Permission:
7185 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7186 */
7187 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007188 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007189 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007190 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007191 return null;
7192 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007193 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007194 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007195 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007196 return null;
7197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 return phone.getDeviceId();
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007205 }
7206
Ping Sunc67b7c22016-03-02 19:16:45 +08007207 /**
7208 * {@hide}
7209 * Returns the IMS Registration Status on a particular subid
7210 *
7211 * @param subId
7212 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007213 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007214 Phone phone = getPhone(subId);
7215 if (phone != null) {
7216 return phone.isImsRegistered();
7217 } else {
7218 return false;
7219 }
7220 }
7221
Santos Cordon7a1885b2015-02-03 11:15:19 -08007222 @Override
7223 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007230 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007231
Tyler Gunnf70ed162019-04-03 15:28:53 -07007232 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007233 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007234 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007236 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007237 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7238 }
7239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
7245 }
7246
7247 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007248 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007249 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7250 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 Phone phone = getPhone(subscriptionId);
7254 if (phone == null) {
7255 return null;
7256 }
7257 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
7261 }
7262
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007263 /**
7264 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007265 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007266 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 Phone phone = getPhone(subId);
7270 if (phone != null) {
7271 return phone.isWifiCallingEnabled();
7272 } else {
7273 return false;
7274 }
7275 } finally {
7276 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007277 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007278 }
7279
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007280 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007281 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007282 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007283 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007284 final long identity = Binder.clearCallingIdentity();
7285 try {
7286 Phone phone = getPhone(subId);
7287 if (phone != null) {
7288 return phone.isVideoEnabled();
7289 } else {
7290 return false;
7291 }
7292 } finally {
7293 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007294 }
7295 }
7296
7297 /**
7298 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7299 * defined in {@link ImsRegistrationImplBase}.
7300 */
7301 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 final long identity = Binder.clearCallingIdentity();
7303 try {
7304 Phone phone = getPhone(subId);
7305 if (phone != null) {
7306 return phone.getImsRegistrationTech();
7307 } else {
7308 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7309 }
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007312 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007313 }
7314
Stuart Scott8eef64f2015-04-08 15:13:54 -07007315 @Override
7316 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007317 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007318 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7319 return;
7320 }
7321
Svet Ganovcc087f82015-05-12 20:35:54 -07007322 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007323
Svet Ganovcc087f82015-05-12 20:35:54 -07007324 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007325 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7326 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007327 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007328 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007329 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007330 setAllowedNetworkTypesForReason(subId,
7331 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7332 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7333 setAllowedNetworkTypesForReason(subId,
7334 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7335 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7336 setAllowedNetworkTypesForReason(subId,
7337 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7338 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007339 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7340 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007341 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007342 // There has been issues when Sms raw table somehow stores orphan
7343 // fragments. They lead to garbled message when new fragments come
7344 // in and combined with those stale ones. In case this happens again,
7345 // user can reset all network settings which will clean up this table.
7346 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007347 // Clean up IMS settings as well here.
7348 int slotId = getSlotIndex(subId);
7349 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7350 ImsManager.getInstance(mApp, slotId).factoryReset();
7351 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007352
7353 // Erase modem config if erase modem on network setting is enabled.
7354 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7355 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7356 if (configValue != null && Boolean.parseBoolean(configValue)) {
7357 sendEraseModemConfig(getDefaultPhone());
7358 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007359 } finally {
7360 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007361 }
7362 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007363
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007364 private void cleanUpSmsRawTable(Context context) {
7365 ContentResolver resolver = context.getContentResolver();
7366 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7367 resolver.delete(uri, null, null);
7368 }
7369
Narayan Kamath1c496c22015-04-16 14:40:19 +01007370 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007371 public String getSimLocaleForSubscriber(int subId) {
7372 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7373 final Phone phone = getPhone(subId);
7374 if (phone == null) {
7375 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007376 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 final long identity = Binder.clearCallingIdentity();
7379 try {
chen xu5d3637b2019-01-21 23:31:38 -08007380 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007381 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007382 if (info == null) {
7383 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7384 return null;
7385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 // Try and fetch the locale from the carrier properties or from the SIM language
7387 // preferences (EF-PL and EF-LI)...
7388 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007390 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7391 if (localeFromDefaultSim != null) {
7392 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7393 if (DBG) log("Using locale from subId: " + subId + " locale: "
7394 + localeFromDefaultSim);
7395 return localeFromDefaultSim.toLanguageTag();
7396 } else {
7397 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 }
7399 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 // The SIM language preferences only store a language (e.g. fr = French), not an
7402 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7403 // the SIM and carrier preferences does not include a country we add the country
7404 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007405 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007407 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 return mccLocale.toLanguageTag();
7409 }
7410
7411 if (DBG) log("No locale found - returning null");
7412 return null;
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007416 }
7417
7418 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007419 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007420 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007421 }
7422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 /**
7424 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7425 */
7426 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007427 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007428 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007429 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007430
Chenjie Yu1ba97252018-01-11 18:16:20 -08007431 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007432 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007434 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007435 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7436 * representing the state of the modem.
7437 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007438 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7439 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007440 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007441 */
7442 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007443 public void requestModemActivityInfo(ResultReceiver result) {
7444 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446
7447 final long identity = Binder.clearCallingIdentity();
7448 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007449 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 } finally {
7451 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007452 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007453 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007454
Siddharth Rayb8114062018-06-17 15:02:38 -07007455 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7456 // less than total activity duration.
7457 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7458 if (info == null) {
7459 return false;
7460 }
7461 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007462 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7463 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7464
Siddharth Rayb8114062018-06-17 15:02:38 -07007465 return (info.isValid()
7466 && (info.getSleepTimeMillis() <= activityDurationMs)
7467 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007468 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007469 && (totalTxTimeMs <= activityDurationMs));
7470 }
7471
Jack Yu85bd38a2015-11-09 11:34:32 -08007472 /**
7473 * {@hide}
7474 * Returns the service state information on specified subscription.
7475 */
7476 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007477 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7478 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007481 return null;
7482 }
7483
Hall Liuf19c44f2018-11-27 14:38:17 -08007484 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7485 LocationAccessPolicy.checkLocationPermission(mApp,
7486 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7487 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007488 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007489 .setCallingPid(Binder.getCallingPid())
7490 .setCallingUid(Binder.getCallingUid())
7491 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007492 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007493 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007494 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7495 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007496 .build());
7497
7498 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7499 LocationAccessPolicy.checkLocationPermission(mApp,
7500 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7501 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007502 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007503 .setCallingPid(Binder.getCallingPid())
7504 .setCallingUid(Binder.getCallingUid())
7505 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007506 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007507 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007508 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7509 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007510 .build());
7511 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7512 boolean hasFinePermission =
7513 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7514 boolean hasCoarsePermission =
7515 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7516
Jack Yu479f40e2020-10-27 21:29:25 -07007517 final Phone phone = getPhone(subId);
7518 if (phone == null) {
7519 return null;
7520 }
7521
Jordan Liu0f2bc442020-11-18 16:47:37 -08007522 final long identity = Binder.clearCallingIdentity();
7523
Jack Yu479f40e2020-10-27 21:29:25 -07007524 boolean isCallingPackageDataService = phone.getDataServicePackages()
7525 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007527 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7528 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7529 Rlog.d(LOG_TAG,
7530 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7531 return null;
7532 }
7533
Hall Liuf19c44f2018-11-27 14:38:17 -08007534 ServiceState ss = phone.getServiceState();
7535
7536 // Scrub out the location info in ServiceState depending on what level of access
7537 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007538 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007539 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7540 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007544 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007545
7546 /**
7547 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7548 *
7549 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7550 * voicemail ringtone.
7551 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7552 * PhoneAccount.
7553 */
7554 @Override
7555 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7559 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007560 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007567 }
7568
7569 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007570 * Sets the per-account voicemail ringtone.
7571 *
7572 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7573 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7574 *
7575 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7576 * voicemail ringtone.
7577 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7578 * PhoneAccount.
7579 */
7580 @Override
7581 public void setVoicemailRingtoneUri(String callingPackage,
7582 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007585 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7586 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7588 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7589 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591
7592 final long identity = Binder.clearCallingIdentity();
7593 try {
7594 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7595 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007596 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 }
7598 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007601 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007602 }
7603
7604 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007605 * Returns whether vibration is set for voicemail notification in Phone settings.
7606 *
7607 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7608 * voicemail vibration setting.
7609 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7610 */
7611 @Override
7612 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7616 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007617 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007624 }
7625
Youhan Wange64578a2016-05-02 15:32:42 -07007626 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007627 * Sets the per-account voicemail vibration.
7628 *
7629 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7630 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7631 *
7632 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7633 * voicemail vibration setting.
7634 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7635 * specific PhoneAccount.
7636 */
7637 @Override
7638 public void setVoicemailVibrationEnabled(String callingPackage,
7639 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007642 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7643 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7645 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7646 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007647 }
7648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7652 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007653 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 }
7655 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007658 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007659 }
7660
7661 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007662 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7663 *
7664 * @throws SecurityException if the caller does not have the required permission
7665 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007666 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007667 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007668 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007669 }
7670
7671 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007672 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7673 * permission.
7674 *
7675 * @throws SecurityException if the caller does not have the required permission
7676 */
7677 private void enforceSendSmsPermission() {
7678 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7679 }
7680
7681 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007682 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007683 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007684 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007685 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007686 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007690 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 if (componentName == null) {
7692 throw new SecurityException(
7693 "Caller not current active visual voicemail package[null]");
7694 }
7695 String vvmPackage = componentName.getPackageName();
7696 if (!callingPackage.equals(vvmPackage)) {
7697 throw new SecurityException("Caller not current active visual voicemail package["
7698 + vvmPackage + "]");
7699 }
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007702 }
7703 }
7704
7705 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007706 * Return the application ID for the app type.
7707 *
7708 * @param subId the subscription ID that this request applies to.
7709 * @param appType the uicc app type.
7710 * @return Application ID for specificied app type, or null if no uicc.
7711 */
7712 @Override
7713 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007714 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007715 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716
7717 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007718 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 if (phone == null) {
7720 return null;
7721 }
7722 String aid = null;
7723 try {
7724 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7725 .getApplicationByType(appType).getAid();
7726 } catch (Exception e) {
7727 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7728 }
7729 return aid;
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007732 }
Youhan Wange64578a2016-05-02 15:32:42 -07007733 }
7734
Youhan Wang4001d252016-05-11 10:29:41 -07007735 /**
7736 * Return the Electronic Serial Number.
7737 *
7738 * @param subId the subscription ID that this request applies to.
7739 * @return ESN or null if error.
7740 */
7741 @Override
7742 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007743 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007744 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745
7746 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007747 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748 if (phone == null) {
7749 return null;
7750 }
7751 String esn = null;
7752 try {
7753 esn = phone.getEsn();
7754 } catch (Exception e) {
7755 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7756 }
7757 return esn;
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007760 }
Youhan Wang4001d252016-05-11 10:29:41 -07007761 }
7762
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007763 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007764 * Return the Preferred Roaming List Version.
7765 *
7766 * @param subId the subscription ID that this request applies to.
7767 * @return PRLVersion or null if error.
7768 */
7769 @Override
7770 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007771 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007772 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773
7774 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007775 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 if (phone == null) {
7777 return null;
7778 }
7779 String cdmaPrlVersion = null;
7780 try {
7781 cdmaPrlVersion = phone.getCdmaPrlVersion();
7782 } catch (Exception e) {
7783 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7784 }
7785 return cdmaPrlVersion;
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007788 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007789 }
7790
7791 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007792 * Get snapshot of Telephony histograms
7793 * @return List of Telephony histograms
7794 * @hide
7795 */
7796 @Override
7797 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7799 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800
7801 final long identity = Binder.clearCallingIdentity();
7802 try {
7803 return RIL.getTelephonyRILTimingHistograms();
7804 } finally {
7805 Binder.restoreCallingIdentity(identity);
7806 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007807 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007808
7809 /**
7810 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007811 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7812 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007813 * Require system privileges. In the future we may add this to carrier APIs.
7814 *
Michele Berionne482f8202018-11-27 18:57:59 -08007815 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007816 */
7817 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007818 @TelephonyManager.SetCarrierRestrictionResult
7819 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007820 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007822
Michele Berionne482f8202018-11-27 18:57:59 -08007823 if (carrierRestrictionRules == null) {
7824 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007825 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 final long identity = Binder.clearCallingIdentity();
7828 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007829 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007830 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007834 }
7835
7836 /**
7837 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007838 * Get the allowed carrier list and the excluded carrier list, including the priority between
7839 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007840 * Require system privileges. In the future we may add this to carrier APIs.
7841 *
Michele Berionne482f8202018-11-27 18:57:59 -08007842 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007843 */
7844 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007845 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007846 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007851 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7852 if (response instanceof CarrierRestrictionRules) {
7853 return (CarrierRestrictionRules) response;
7854 }
7855 // Response is an Exception of some kind,
7856 // which is signalled to the user as a NULL retval
7857 return null;
7858 } catch (Exception e) {
7859 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7860 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007864 }
7865
fionaxu59545b42016-05-25 15:53:37 -07007866 /**
fionaxu59545b42016-05-25 15:53:37 -07007867 * Action set from carrier signalling broadcast receivers to enable/disable radio
7868 * @param subId the subscription ID that this action applies to.
7869 * @param enabled control enable or disable radio.
7870 * {@hide}
7871 */
7872 @Override
7873 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7874 enforceModifyPermission();
7875 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876
7877 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007878 if (phone == null) {
7879 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7880 return;
7881 }
7882 try {
7883 phone.carrierActionSetRadioEnabled(enabled);
7884 } catch (Exception e) {
7885 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 } finally {
7887 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007888 }
7889 }
7890
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007891 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007892 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7893 * network status based on which carrier apps could apply actions accordingly,
7894 * enable/disable default url handler for example.
7895 *
7896 * @param subId the subscription ID that this action applies to.
7897 * @param report control start/stop reporting the default network status.
7898 * {@hide}
7899 */
7900 @Override
7901 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7902 enforceModifyPermission();
7903 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904
7905 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007906 if (phone == null) {
7907 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7908 return;
7909 }
7910 try {
7911 phone.carrierActionReportDefaultNetworkStatus(report);
7912 } catch (Exception e) {
7913 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 } finally {
7915 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007916 }
7917 }
7918
7919 /**
fionaxud9622282017-07-17 17:51:30 -07007920 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7921 * @param subId the subscription ID that this action applies to.
7922 * {@hide}
7923 */
7924 @Override
7925 public void carrierActionResetAll(int subId) {
7926 enforceModifyPermission();
7927 final Phone phone = getPhone(subId);
7928 if (phone == null) {
7929 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7930 return;
7931 }
7932 try {
7933 phone.carrierActionResetAll();
7934 } catch (Exception e) {
7935 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7936 }
7937 }
7938
7939 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007940 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7941 * bug report is being generated.
7942 */
7943 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007944 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007945 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7946 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007947 writer.println("Permission Denial: can't dump Phone from pid="
7948 + Binder.getCallingPid()
7949 + ", uid=" + Binder.getCallingUid()
7950 + "without permission "
7951 + android.Manifest.permission.DUMP);
7952 return;
7953 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007954 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007955 }
Jack Yueb89b242016-06-22 13:27:47 -07007956
Brad Ebingerdac2f002018-04-03 15:17:52 -07007957 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007958 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7959 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7960 @NonNull String[] args) {
7961 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7962 this, in.getFileDescriptor(), out.getFileDescriptor(),
7963 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007964 }
7965
Jack Yueb89b242016-06-22 13:27:47 -07007966 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007967 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007968 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007969 * @param reason the reason the data enable change is taking place
7970 * @param enabled True if enabling the data, otherwise disabling.
7971 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007972 */
7973 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007974 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007975 boolean enabled) {
7976 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7977 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7978 try {
7979 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007980 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007981 } catch (SecurityException se) {
7982 enforceModifyPermission();
7983 }
7984 } else {
7985 enforceModifyPermission();
7986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987
7988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 Phone phone = getPhone(subId);
7991 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007992 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7993 phone.carrierActionSetMeteredApnsEnabled(enabled);
7994 } else {
7995 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 }
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008000 }
8001 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008002
8003 /**
8004 * Get Client request stats
8005 * @return List of Client Request Stats
8006 * @hide
8007 */
8008 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008009 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8010 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008012 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008013 return null;
8014 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008015 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 if (phone != null) {
8020 return phone.getClientRequestStats();
8021 }
8022
8023 return null;
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
8026 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008027 }
8028
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008029 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008030 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008031 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008032 }
Jack Yueb4124c2017-02-16 15:32:43 -08008033
8034 /**
Grace Chen70990072017-03-24 17:21:30 -07008035 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008036 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008037 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008038 * @param state State of SIM (power down, power up, pass through)
8039 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8040 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8041 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008042 *
8043 **/
8044 @Override
Grace Chen70990072017-03-24 17:21:30 -07008045 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008046 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008047 Phone phone = PhoneFactory.getPhone(slotIndex);
8048
vagdeviaf9a5b92018-08-15 16:01:53 -07008049 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008054 phone.setSimPowerState(state, null, workSource);
8055 }
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
8058 }
8059 }
8060
8061 /**
8062 * Set SIM card power state.
8063 *
8064 * @param slotIndex SIM slot id.
8065 * @param state State of SIM (power down, power up, pass through)
8066 * @param callback callback to trigger after success or failure
8067 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8068 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8069 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8070 *
8071 **/
8072 @Override
8073 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8074 IIntegerConsumer callback) {
8075 enforceModifyPermission();
8076 Phone phone = PhoneFactory.getPhone(slotIndex);
8077
8078 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8079
8080 final long identity = Binder.clearCallingIdentity();
8081 try {
8082 if (phone != null) {
8083 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8084 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 }
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008088 }
8089 }
Shuo Qiandd210312017-04-12 22:11:33 +00008090
Tyler Gunn65d45c22017-06-05 11:22:26 -07008091 private boolean isUssdApiAllowed(int subId) {
8092 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008093 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008094 if (configManager == null) {
8095 return false;
8096 }
8097 PersistableBundle pb = configManager.getConfigForSubId(subId);
8098 if (pb == null) {
8099 return false;
8100 }
8101 return pb.getBoolean(
8102 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8103 }
8104
Shuo Qiandd210312017-04-12 22:11:33 +00008105 /**
8106 * Check if phone is in emergency callback mode
8107 * @return true if phone is in emergency callback mode
8108 * @param subId sub id
8109 */
goneil9c5f4872017-12-05 14:07:56 -08008110 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008111 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008112 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114
8115 final long identity = Binder.clearCallingIdentity();
8116 try {
8117 if (phone != null) {
8118 return phone.isInEcm();
8119 } else {
8120 return false;
8121 }
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008124 }
8125 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008126
8127 /**
8128 * Get the current signal strength information for the given subscription.
8129 * Because this information is not updated when the device is in a low power state
8130 * it should not be relied-upon to be current.
8131 * @param subId Subscription index
8132 * @return the most recent cached signal strength info from the modem
8133 */
8134 @Override
8135 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 Phone p = getPhone(subId);
8139 if (p == null) {
8140 return null;
8141 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 return p.getSignalStrength();
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008148
Pengquan Meng77b7f132018-08-22 14:49:57 -07008149 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008150 * Get the current modem radio state for the given slot.
8151 * @param slotIndex slot index.
8152 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008153 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008154 * @return the current radio power state from the modem
8155 */
8156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008157 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008158 Phone phone = PhoneFactory.getPhone(slotIndex);
8159 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8161 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008162 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8163 }
8164
8165 final long identity = Binder.clearCallingIdentity();
8166 try {
8167 return phone.getRadioPowerState();
8168 } finally {
8169 Binder.restoreCallingIdentity(identity);
8170 }
8171 }
8172 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8173 }
8174
8175 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008176 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8177 *
8178 * <p>Requires one of the following permissions:
8179 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8180 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8181 * privileges.
8182 *
8183 * @param subId subscription id
8184 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8185 * {@code false}.
8186 */
8187 @Override
8188 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008189 try {
8190 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8191 null);
8192 } catch (Exception e) {
8193 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8194 mApp, subId, "isDataRoamingEnabled");
8195 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008196
Pengquan Menga1bb6272018-09-06 09:59:22 -07008197 boolean isEnabled = false;
8198 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008199 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 Phone phone = getPhone(subId);
8201 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008202 } finally {
8203 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008204 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008205 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008206 }
8207
8208
8209 /**
8210 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8211 *
8212 * <p> Requires permission:
8213 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8214 * privileges.
8215 *
8216 * @param subId subscription id
8217 * @param isEnabled {@code true} means enable, {@code false} means disable.
8218 */
8219 @Override
8220 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8222 mApp, subId, "setDataRoamingEnabled");
8223
Pengquan Menga1bb6272018-09-06 09:59:22 -07008224 final long identity = Binder.clearCallingIdentity();
8225 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008226 Phone phone = getPhone(subId);
8227 if (phone != null) {
8228 phone.setDataRoamingEnabled(isEnabled);
8229 }
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008232 }
8233 }
8234
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008235 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008236 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008237 TelephonyPermissions
8238 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008239 mApp, subId, "isManualNetworkSelectionAllowed");
8240
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008241 boolean isAllowed = true;
8242 final long identity = Binder.clearCallingIdentity();
8243 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008244 Phone phone = getPhone(subId);
8245 if (phone != null) {
8246 isAllowed = phone.isCspPlmnEnabled();
8247 }
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
8251 return isAllowed;
8252 }
8253
8254 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008255 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008256 // Verify that tha callingPackage belongs to the calling UID
8257 mApp.getSystemService(AppOpsManager.class)
8258 .checkPackage(Binder.getCallingUid(), callingPackage);
8259
Jordan Liu1e142fc2019-04-22 15:10:43 -07008260 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008261 try {
8262 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008263 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008264 } catch (SecurityException e) {
8265 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8266 // has carrier privileges on an active UICC
8267 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8268 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008269 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008270 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008271 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008272
8273 final long identity = Binder.clearCallingIdentity();
8274 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008275 UiccController uiccController = UiccController.getInstance();
8276 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008277 if (hasReadPermission) {
8278 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008279 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008280
8281 // Remove private info if the caller doesn't have access
8282 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8283 for (UiccCardInfo cardInfo : cardInfos) {
8284 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8285 // is available
8286 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8287 if (card == null || card.getUiccProfile() == null) {
8288 // assume no access if the card or profile is unavailable
8289 filteredInfos.add(cardInfo.getUnprivileged());
8290 continue;
8291 }
8292 UiccProfile profile = card.getUiccProfile();
8293 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8294 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8295 filteredInfos.add(cardInfo);
8296 } else {
8297 filteredInfos.add(cardInfo.getUnprivileged());
8298 }
8299 }
8300 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 }
8305
8306 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008307 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008308 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 final long identity = Binder.clearCallingIdentity();
8311 try {
8312 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8313 if (slots == null) {
8314 Rlog.i(LOG_TAG, "slots is null.");
8315 return null;
8316 }
8317
8318 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8319 for (int i = 0; i < slots.length; i++) {
8320 UiccSlot slot = slots[i];
8321 if (slot == null) {
8322 continue;
8323 }
8324
Jordan Liu7be7e652019-05-06 18:55:02 +00008325 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 UiccCard card = slot.getUiccCard();
8327 if (card != null) {
8328 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008329 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008330 cardId = slot.getEid();
8331 if (TextUtils.isEmpty(cardId)) {
8332 cardId = slot.getIccId();
8333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 }
8335
Jordan Liu857451f2019-05-09 16:35:35 -07008336 if (cardId != null) {
8337 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8338 // if cardId is an EID, it's all digits so this is fine
8339 cardId = IccUtils.stripTrailingFs(cardId);
8340 }
8341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008342 int cardState = 0;
8343 switch (slot.getCardState()) {
8344 case CARDSTATE_ABSENT:
8345 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8346 break;
8347 case CARDSTATE_PRESENT:
8348 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8349 break;
8350 case CARDSTATE_ERROR:
8351 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8352 break;
8353 case CARDSTATE_RESTRICTED:
8354 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8355 break;
8356 default:
8357 break;
8358
8359 }
8360
8361 infos[i] = new UiccSlotInfo(
8362 slot.isActive(),
8363 slot.isEuicc(),
8364 cardId,
8365 cardState,
8366 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008367 slot.isExtendedApduSupported(),
8368 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 }
8370 return infos;
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008373 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008374 }
8375
8376 @Override
8377 public boolean switchSlots(int[] physicalSlots) {
8378 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
8382 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008386 }
Jack Yu4c988042018-02-27 15:30:01 -08008387
8388 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008389 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008390 final long identity = Binder.clearCallingIdentity();
8391 try {
8392 return UiccController.getInstance().getCardIdForDefaultEuicc();
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
8396 }
8397
Pengquan Meng85728fb2018-03-12 16:31:21 -07008398 /**
goneil47ffb6e2018-04-06 15:40:58 -07008399 * A test API to reload the UICC profile.
8400 *
8401 * <p>Requires that the calling app has permission
8402 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8403 * @hide
8404 */
8405 @Override
8406 public void refreshUiccProfile(int subId) {
8407 enforceModifyPermission();
8408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 Phone phone = getPhone(subId);
8412 if (phone == null) {
8413 return;
8414 }
8415 UiccCard uiccCard = phone.getUiccCard();
8416 if (uiccCard == null) {
8417 return;
8418 }
8419 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8420 if (uiccProfile == null) {
8421 return;
8422 }
8423 uiccProfile.refresh();
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
8428
8429 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008430 * Returns false if the mobile data is disabled by default, otherwise return true.
8431 */
8432 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008433 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008434 }
8435
8436 /**
8437 * Returns true if the data roaming is enabled by default, i.e the system property
8438 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8439 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8440 */
8441 private boolean getDefaultDataRoamingEnabled(int subId) {
8442 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008443 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008444 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008445 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8446 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8447 return isDataRoamingEnabled;
8448 }
8449
8450 /**
8451 * Returns the default network type for the given {@code subId}, if the default network type is
8452 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8453 */
8454 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008455 List<Integer> list = TelephonyProperties.default_network();
8456 int phoneId = mSubscriptionController.getPhoneId(subId);
8457 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8458 return list.get(phoneId);
8459 }
8460 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008461 }
fionaxua13278b2018-03-21 00:08:13 -07008462
8463 @Override
8464 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008465 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 final Phone phone = getPhone(subId);
8471 if (phone == null) {
8472 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8473 return;
8474 }
chen xueaba88a2019-03-15 13:15:10 -07008475 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8476 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008477 if (carrierPrivilegeRules == null) {
8478 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8479 } else {
8480 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 } finally {
8483 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008484 }
fionaxua13278b2018-03-21 00:08:13 -07008485 }
8486
8487 @Override
8488 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008489 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 final Phone phone = getPhone(subId);
8494 if (phone == null) {
8495 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8496 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8497 }
8498 return phone.getCarrierIdListVersion();
8499 } finally {
8500 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008501 }
fionaxua13278b2018-03-21 00:08:13 -07008502 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008503
8504 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008505 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8506 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008508 mApp, subId, callingPackage, callingFeatureId,
8509 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008510 return -1;
8511 }
8512
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008520
8521 @Override
8522 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008523 TelephonyPermissions
8524 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008525 mApp, subId, "getCdmaRoamingMode");
8526
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
8535 @Override
8536 public boolean setCdmaRoamingMode(int subId, int mode) {
8537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8538 mApp, subId, "setCdmaRoamingMode");
8539
8540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
8545 }
8546 }
8547
8548 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008549 public int getCdmaSubscriptionMode(int subId) {
8550 TelephonyPermissions
8551 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8552 mApp, subId, "getCdmaSubscriptionMode");
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
8562 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008563 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8565 mApp, subId, "setCdmaSubscriptionMode");
8566
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
8569 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8570 } finally {
8571 Binder.restoreCallingIdentity(identity);
8572 }
8573 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008574
sqianc5eccab2018-10-19 18:46:41 -07008575 @Override
sqian8c685422019-02-22 15:55:18 -08008576 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008577 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008579 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8580 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008581 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8582 }
8583 final long identity = Binder.clearCallingIdentity();
8584 try {
sqian854d44b2018-12-12 16:48:18 -08008585 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8586 for (Phone phone: PhoneFactory.getPhones()) {
8587 if (phone.getEmergencyNumberTracker() != null
8588 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8589 emergencyNumberListInternal.put(
8590 phone.getSubId(),
8591 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8592 }
sqian11b7a0e2018-12-05 18:48:28 -08008593 }
sqian854d44b2018-12-12 16:48:18 -08008594 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
sqianc5eccab2018-10-19 18:46:41 -07008598 }
8599
8600 @Override
sqian8c685422019-02-22 15:55:18 -08008601 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008602 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008603 if (!exactMatch) {
8604 TelephonyPermissions
8605 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008606 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008607 }
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
sqian854d44b2018-12-12 16:48:18 -08008610 for (Phone phone: PhoneFactory.getPhones()) {
8611 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008612 && phone.getEmergencyNumberTracker()
8613 .isEmergencyNumber(number, exactMatch)) {
8614 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008615 }
sqian11b7a0e2018-12-05 18:48:28 -08008616 }
8617 return false;
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
sqianf4ca7ed2019-01-15 18:32:07 -08008623 /**
8624 * Update emergency number list for test mode.
8625 */
8626 @Override
8627 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8629 "updateEmergencyNumberListTestMode");
8630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 for (Phone phone: PhoneFactory.getPhones()) {
8634 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8635 if (tracker != null) {
8636 tracker.executeEmergencyNumberTestModeCommand(action, num);
8637 }
8638 }
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
8643
8644 /**
8645 * Get the full emergency number list for test mode.
8646 */
8647 @Override
8648 public List<String> getEmergencyNumberListTestMode() {
8649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8650 "getEmergencyNumberListTestMode");
8651
8652 final long identity = Binder.clearCallingIdentity();
8653 try {
8654 Set<String> emergencyNumbers = new HashSet<>();
8655 for (Phone phone: PhoneFactory.getPhones()) {
8656 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8657 if (tracker != null) {
8658 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8659 emergencyNumbers.add(num.getNumber());
8660 }
8661 }
8662 }
8663 return new ArrayList<>(emergencyNumbers);
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 }
8668
chen xud6b45bd2018-10-30 22:27:10 -07008669 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008670 public int getEmergencyNumberDbVersion(int subId) {
8671 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8672
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
8675 final Phone phone = getPhone(subId);
8676 if (phone == null) {
8677 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8678 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8679 }
8680 return phone.getEmergencyNumberDbVersion();
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
8683 }
8684 }
8685
8686 @Override
8687 public void notifyOtaEmergencyNumberDbInstalled() {
8688 enforceModifyPermission();
8689
8690 final long identity = Binder.clearCallingIdentity();
8691 try {
8692 for (Phone phone: PhoneFactory.getPhones()) {
8693 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8694 if (tracker != null) {
8695 tracker.updateOtaEmergencyNumberDatabase();
8696 }
8697 }
8698 } finally {
8699 Binder.restoreCallingIdentity(identity);
8700 }
8701 }
8702
8703 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008704 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008705 enforceActiveEmergencySessionPermission();
8706
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
8709 for (Phone phone: PhoneFactory.getPhones()) {
8710 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8711 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008712 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8713 }
8714 }
8715 } finally {
8716 Binder.restoreCallingIdentity(identity);
8717 }
8718 }
8719
8720 @Override
8721 public void resetOtaEmergencyNumberDbFilePath() {
8722 enforceActiveEmergencySessionPermission();
8723
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 for (Phone phone: PhoneFactory.getPhones()) {
8727 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8728 if (tracker != null) {
8729 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008730 }
8731 }
8732 } finally {
8733 Binder.restoreCallingIdentity(identity);
8734 }
8735 }
8736
8737 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008738 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8739 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8740 Phone phone = getPhone(subId);
8741 if (phone == null) {
8742 return null;
8743 }
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 UiccProfile profile = UiccController.getInstance()
8747 .getUiccProfileForPhone(phone.getPhoneId());
8748 if (profile != null) {
8749 return profile.getCertsFromCarrierPrivilegeAccessRules();
8750 }
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
8754 return null;
8755 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008756
8757 /**
8758 * Enable or disable a modem stack.
8759 */
8760 @Override
8761 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8762 enforceModifyPermission();
8763
8764 final long identity = Binder.clearCallingIdentity();
8765 try {
8766 Phone phone = PhoneFactory.getPhone(slotIndex);
8767 if (phone == null) {
8768 return false;
8769 } else {
8770 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8771 }
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
Michelecea4cf22018-12-21 15:00:11 -08008776
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008777 /**
8778 * Whether a modem stack is enabled or not.
8779 */
8780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008781 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8782 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008783 Phone phone = PhoneFactory.getPhone(slotIndex);
8784 if (phone == null) return false;
8785
8786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008787 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8788 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008789 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8790 }
8791
8792 final long identity = Binder.clearCallingIdentity();
8793 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008794 try {
8795 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8796 } catch (NoSuchElementException ex) {
8797 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8798 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
Michelecea4cf22018-12-21 15:00:11 -08008804 @Override
Michele0ea7d782019-03-19 14:58:42 -07008805 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008806 enforceModifyPermission();
8807
8808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008811 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008812 .commit();
8813 } finally {
8814 Binder.restoreCallingIdentity(identity);
8815 }
8816 }
8817
8818 @Override
Michele0ea7d782019-03-19 14:58:42 -07008819 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008820 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008822 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8823 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008824 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008825 }
Michelecea4cf22018-12-21 15:00:11 -08008826
8827 final long identity = Binder.clearCallingIdentity();
8828 try {
Michele0ea7d782019-03-19 14:58:42 -07008829 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008830 } finally {
8831 Binder.restoreCallingIdentity(identity);
8832 }
8833 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008834
Michele0ea7d782019-03-19 14:58:42 -07008835 @TelephonyManager.IsMultiSimSupportedResult
8836 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008837 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8838 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8839 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008840 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8841 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008842 }
8843 // Check if the hardware supports multisim functionality. If usage of multisim is not
8844 // supported by the modem, indicate that it is restricted.
8845 PhoneCapability staticCapability =
8846 mPhoneConfigurationManager.getStaticPhoneCapability();
8847 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008848 loge("isMultiSimSupportedInternal: no static configuration available");
8849 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008850 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008851 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008852 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8853 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008854 }
8855 // Check if support of multiple SIMs is restricted by carrier
8856 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008857 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008858 }
8859
Michele0ea7d782019-03-19 14:58:42 -07008860 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008861 }
8862
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008863 /**
8864 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008865 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8866 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8867 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008868 * @param numOfSims number of active sims we want to switch to
8869 */
8870 @Override
8871 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008872 if (numOfSims == 1) {
8873 enforceModifyPermission();
8874 } else {
8875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8876 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8877 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008878 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008879
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008880 try {
Michele30b57b22019-03-01 12:01:14 -08008881 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008882 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008883 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8884 return;
8885 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008886 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
8890 }
8891
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008892 @Override
8893 public boolean isApplicationOnUicc(int subId, int appType) {
8894 enforceReadPrivilegedPermission("isApplicationOnUicc");
8895 Phone phone = getPhone(subId);
8896 if (phone == null) {
8897 return false;
8898 }
8899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 UiccCard uiccCard = phone.getUiccCard();
8902 if (uiccCard == null) {
8903 return false;
8904 }
8905 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8906 if (uiccProfile == null) {
8907 return false;
8908 }
8909 if (TelephonyManager.APPTYPE_SIM <= appType
8910 && appType <= TelephonyManager.APPTYPE_ISIM) {
8911 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8912 }
8913 return false;
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
8918
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008919 /**
chen xub4baa772019-04-03 10:23:41 -07008920 * Get whether making changes to modem configurations will trigger reboot.
8921 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008922 */
8923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008924 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8925 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008927 mApp, subId, callingPackage, callingFeatureId,
8928 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008929 return false;
8930 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8934 } finally {
8935 Binder.restoreCallingIdentity(identity);
8936 }
8937 }
8938
Nathan Harold29f5f052019-02-15 13:41:57 -08008939 private void updateModemStateMetrics() {
8940 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8941 // TODO: check the state for each modem if the api is ready.
8942 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8943 }
8944
Pengquan Meng3889a572019-01-23 11:16:29 -08008945 @Override
8946 public int[] getSlotsMapping() {
8947 enforceReadPrivilegedPermission("getSlotsMapping");
8948
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8952 // All logical slots should have a mapping to a physical slot.
8953 int[] logicalSlotsMapping = new int[phoneCount];
8954 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8955 for (int i = 0; i < slotInfos.length; i++) {
8956 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8957 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8958 }
8959 }
8960 return logicalSlotsMapping;
8961 } finally {
8962 Binder.restoreCallingIdentity(identity);
8963 }
8964 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008965
8966 /**
8967 * Get the IRadio HAL Version
8968 */
8969 @Override
8970 public int getRadioHalVersion() {
8971 Phone phone = getDefaultPhone();
8972 if (phone == null) return -1;
8973 HalVersion hv = phone.getHalVersion();
8974 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8975 return hv.major * 100 + hv.minor;
8976 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008977
8978 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008979 * Get the current calling package name.
8980 * @return the current calling package name
8981 */
8982 @Override
8983 public String getCurrentPackageName() {
8984 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8985 }
8986
8987 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008988 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8989 * corresponding network requests on a subId.
8990 *
8991 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008992 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008993 * 2) APN is un-metered for this subscription, or
8994 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008995 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008996 *
8997 * @return whether data is allowed for a apn type.
8998 *
8999 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009000 */
9001 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009002 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009003 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9004 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009005
9006 // Now that all security checks passes, perform the operation as ourselves.
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 Phone phone = getPhone(subId);
9010 if (phone == null) return false;
9011
Jack Yu41407ee2019-05-13 16:54:09 -07009012 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009013 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
9019 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009020 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009021 enforceReadPrivilegedPermission("isApnMetered");
9022
9023 // Now that all security checks passes, perform the operation as ourselves.
9024 final long identity = Binder.clearCallingIdentity();
9025 try {
9026 Phone phone = getPhone(subId);
9027 if (phone == null) return true; // By default return true.
9028
Jack Yu41407ee2019-05-13 16:54:09 -07009029 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009030 } finally {
9031 Binder.restoreCallingIdentity(identity);
9032 }
9033 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009034
9035 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009036 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9037 int subscriptionId, IBooleanConsumer resultCallback) {
9038 enforceModifyPermission();
9039 long token = Binder.clearCallingIdentity();
9040 try {
9041 Phone phone = getPhone(subscriptionId);
9042 if (phone == null) {
9043 try {
9044 if (resultCallback != null) {
9045 resultCallback.accept(false);
9046 }
9047 } catch (RemoteException e) {
9048 // ignore
9049 }
9050 return;
9051 }
9052 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9053 Pair.create(specifiers, (x) -> {
9054 try {
9055 if (resultCallback != null) {
9056 resultCallback.accept(x);
9057 }
9058 } catch (RemoteException e) {
9059 // ignore
9060 }
9061 });
9062 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9063 } finally {
9064 Binder.restoreCallingIdentity(token);
9065 }
9066 }
9067
9068 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009069 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9070 TelephonyPermissions
9071 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9072 mApp, subId, "getSystemSelectionChannels");
9073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9074 final long identity = Binder.clearCallingIdentity();
9075 try {
9076 List<RadioAccessSpecifier> specifiers =
9077 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9078 null, subId, workSource);
9079 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9080 return specifiers;
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
9086 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009087 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009088 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009089 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9090 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9091 if (iccRecords == null) {
9092 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9093 return false;
9094 }
9095 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9096 }
9097
9098 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009099 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9100 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009101 if (callingPackage == null) {
9102 callingPackage = getCurrentPackageName();
9103 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009104 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9105 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009106 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9107 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009108 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9109 }
9110 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9111 Intent intent = new Intent();
9112 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9113 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9114 // Bring up choose default SMS subscription dialog right now
9115 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9116 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9117 mApp.startActivity(intent);
9118 }
chen xud5ca2d52019-05-28 15:20:57 -07009119
9120 @Override
9121 public String getMmsUAProfUrl(int subId) {
9122 //TODO investigate if this API should require proper permission check in R b/133791609
9123 final long identity = Binder.clearCallingIdentity();
9124 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009125 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9126 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9127 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9128 return carrierUAProfUrl;
9129 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009130 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9131 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @Override
9138 public String getMmsUserAgent(int subId) {
9139 //TODO investigate if this API should require proper permission check in R b/133791609
9140 final long identity = Binder.clearCallingIdentity();
9141 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009142 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9143 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9144 if (!TextUtils.isEmpty(carrierUserAgent)) {
9145 return carrierUserAgent;
9146 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009147 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9148 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
Jack Yub07d4972019-05-28 16:12:25 -07009153
9154 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009155 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9156 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009157
Jack Yub07d4972019-05-28 16:12:25 -07009158 final long identity = Binder.clearCallingIdentity();
9159 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009160 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009161 if (phone == null) return false;
9162
Hall Liua62f5da2020-09-25 10:42:19 -07009163 switch (policy) {
9164 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9165 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9166 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9167 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9168 default:
9169 throw new IllegalArgumentException(policy + " is not a valid policy");
9170 }
Jack Yub07d4972019-05-28 16:12:25 -07009171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
9176 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009177 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9178 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009179 enforceModifyPermission();
9180
changbettyd5c246e2019-12-24 15:40:37 +08009181 final long identity = Binder.clearCallingIdentity();
9182 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009183 Phone phone = getPhone(subscriptionId);
9184 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009185
Hall Liua62f5da2020-09-25 10:42:19 -07009186 switch (policy) {
9187 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9188 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9189 break;
9190 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9191 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9192 break;
9193 default:
9194 throw new IllegalArgumentException(policy + " is not a valid policy");
9195 }
changbettyd5c246e2019-12-24 15:40:37 +08009196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009201 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009202 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009203 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9204 * otherwise.
9205 */
9206 @Override
9207 public void setCepEnabled(boolean isCepEnabled) {
9208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9209
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
9212 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9213 for (Phone phone : PhoneFactory.getPhones()) {
9214 Phone defaultPhone = phone.getImsPhone();
9215 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9216 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9217 ImsPhoneCallTracker imsPhoneCallTracker =
9218 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9219 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9220 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9221 + imsPhone.getMsisdn());
9222 }
9223 }
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
9227 }
allenwtsu46dcc572020-01-08 18:24:03 +08009228
9229 /**
9230 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9231 *
9232 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9233 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9234 * before being read.
9235 */
9236 @Override
9237 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9238 isCompressed) {
9239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9240 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009241 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9242 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9243 }
9244 if (!isImsAvailableOnDevice()) {
9245 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9246 "IMS not available on device.");
9247 }
9248
9249 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009250 try {
Hui Wang761a6682020-10-31 05:12:53 +00009251 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009254 }
9255 }
zoey chene02881a2019-12-30 16:11:23 +08009256
9257 @Override
9258 public boolean isIccLockEnabled(int subId) {
9259 enforceReadPrivilegedPermission("isIccLockEnabled");
9260
9261 // Now that all security checks passes, perform the operation as ourselves.
9262 final long identity = Binder.clearCallingIdentity();
9263 try {
9264 Phone phone = getPhone(subId);
9265 if (phone != null && phone.getIccCard() != null) {
9266 return phone.getIccCard().getIccLockEnabled();
9267 } else {
9268 return false;
9269 }
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
9275 /**
9276 * Set the ICC pin lock enabled or disabled.
9277 *
9278 * @return an integer representing the status of IccLock enabled or disabled in the following
9279 * three cases:
9280 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9281 * successfully.
9282 * - Positive number and zero for remaining password attempts.
9283 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9284 *
9285 */
9286 @Override
9287 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9288 enforceModifyPermission();
9289
9290 Phone phone = getPhone(subId);
9291 if (phone == null) {
9292 return 0;
9293 }
9294 // Now that all security checks passes, perform the operation as ourselves.
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
9297 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9298 new Pair<Boolean, String>(enabled, password), phone, null);
9299 return attemptsRemaining;
9300
9301 } catch (Exception e) {
9302 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9303 } finally {
9304 Binder.restoreCallingIdentity(identity);
9305 }
9306 return 0;
9307 }
9308
9309 /**
9310 * Change the ICC password used in ICC pin lock.
9311 *
9312 * @return an integer representing the status of IccLock changed in the following three cases:
9313 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9314 * - Positive number and zero for remaining password attempts.
9315 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9316 *
9317 */
9318 @Override
9319 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9320 enforceModifyPermission();
9321
9322 Phone phone = getPhone(subId);
9323 if (phone == null) {
9324 return 0;
9325 }
9326 // Now that all security checks passes, perform the operation as ourselves.
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9330 new Pair<String, String>(oldPassword, newPassword), phone, null);
9331 return attemptsRemaining;
9332
9333 } catch (Exception e) {
9334 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 return 0;
9339 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009340
9341 /**
9342 * Request for receiving user activity notification
9343 */
9344 @Override
9345 public void requestUserActivityNotification() {
9346 if (!mNotifyUserActivity.get()
9347 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9348 mNotifyUserActivity.set(true);
9349 }
9350 }
9351
9352 /**
9353 * Called when userActivity is signalled in the power manager.
9354 * This is safe to call from any thread, with any window manager locks held or not.
9355 */
9356 @Override
9357 public void userActivity() {
9358 // ***************************************
9359 // * Inherited from PhoneWindowManager *
9360 // ***************************************
9361 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9362 // WITH ITS LOCKS HELD.
9363 //
9364 // This code must be VERY careful about the locks
9365 // it acquires.
9366 // In fact, the current code acquires way too many,
9367 // and probably has lurking deadlocks.
9368
9369 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9370 throw new SecurityException("Only the OS may call notifyUserActivity()");
9371 }
9372
9373 if (mNotifyUserActivity.getAndSet(false)) {
9374 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9375 USER_ACTIVITY_NOTIFICATION_DELAY);
9376 }
9377 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009378
9379 @Override
9380 public boolean canConnectTo5GInDsdsMode() {
9381 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9382 }
Jack Yud10cdd42020-09-28 20:28:01 -07009383
9384 @Override
9385 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9386 String callingFeatureId) {
9387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9388 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9389 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9390 }
9391
9392 Phone phone = getPhone(subId);
9393 if (phone == null) {
9394 throw new RuntimeException("phone is not available");
9395 }
9396 // Now that all security checks passes, perform the operation as ourselves.
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 return phone.getEquivalentHomePlmns();
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 }
Daniel Bright59e67312020-11-13 11:49:37 -08009404
9405 @Override
9406 public boolean isRadioInterfaceCapabilitySupported(
9407 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9408 RadioInterfaceCapabilities radioInterfaceCapabilities =
9409 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9410 if (radioInterfaceCapabilities == null) {
9411 throw new RuntimeException("radio interface capabilities are not available");
9412 } else {
9413 return radioInterfaceCapabilities.isSupported(capability);
9414 }
9415 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009416
Hui Wang641e81c2020-10-12 12:14:23 -07009417 @Override
9418 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9419 UaSecurityProtocolIdentifier securityProtocol,
9420 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9421 throws RemoteException {
9422 enforceModifyPermission();
9423 if (DBG) {
9424 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9425 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9426 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9427 }
9428
9429 if (!SubscriptionManager.isValidSubscriptionId(subId)
9430 || appType < TelephonyManager.APPTYPE_UNKNOWN
9431 || appType > TelephonyManager.APPTYPE_ISIM
9432 || nafUrl == null || securityProtocol == null || callback == null) {
9433 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9434 if (callback != null) {
9435 try {
9436 callback.onAuthenticationFailure(
9437 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9438 } catch (RemoteException exception) {
9439 log("Fail to notify onAuthenticationFailure due to " + exception);
9440 }
9441 return;
9442 }
9443 }
9444
9445 final long token = Binder.clearCallingIdentity();
9446 try {
9447 getGbaManager(subId).bootstrapAuthenticationRequest(
9448 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9449 forceBootStrapping, callback));
9450 } finally {
9451 Binder.restoreCallingIdentity(token);
9452 }
9453 }
9454
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009455 /**
9456 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9457 * requested radio power state will actually be set. See {@link
9458 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9459 *
9460 * @param subId the subscription ID of the phone requesting to set the radio power state.
9461 * @param enable {@code true} if trying to turn radio on.
9462 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9463 * false}.
9464 */
9465 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9466 Phone phone = getPhone(subId);
9467 if (phone != null) {
9468 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9469 return true;
9470 }
9471 return false;
9472 }
9473
9474 private int handleDataThrottlingRequest(int subId,
9475 DataThrottlingRequest dataThrottlingRequest) {
9476 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9477 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9478 if (!setRadioPowerForThermal(subId, true)) {
9479 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9480 }
9481
9482 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9483
9484 int thermalMitigationResult =
9485 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9486 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9487 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9488 }
9489 return thermalMitigationResult;
9490 }
9491
9492 /**
9493 * Thermal mitigation request to control functionalities at modem.
9494 *
9495 * @param subId the id of the subscription.
9496 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9497 *
9498 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9499 */
9500 @Override
9501 @ThermalMitigationResult
9502 public int sendThermalMitigationRequest(
9503 int subId,
9504 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9505 enforceModifyPermission();
9506
9507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9508 final long identity = Binder.clearCallingIdentity();
9509
9510 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9511 try {
9512 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9513 switch (thermalMitigationAction) {
9514 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9515 thermalMitigationResult =
9516 handleDataThrottlingRequest(subId,
9517 thermalMitigationRequest.getDataThrottlingRequest());
9518 break;
9519 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9520 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9521 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9522 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9523 }
9524
9525 // Ensure that radio is on. If not able to power on due to phone being
9526 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9527 if (!setRadioPowerForThermal(subId, true)) {
9528 thermalMitigationResult =
9529 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9530 break;
9531 }
9532
9533 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9534 false);
9535 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9536 break;
9537 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9538 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9539 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9540 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9541 }
9542
9543 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9544 if (registry != null) {
9545 TelephonyConnectionService service =
9546 registry.getTelephonyConnectionService();
9547 Phone phone = getPhone(subId);
9548 if (phone == null) {
9549 thermalMitigationResult =
9550 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9551 break;
9552 }
9553
9554 if (PhoneConstantConversions.convertCallState(phone.getState())
9555 != TelephonyManager.CALL_STATE_IDLE
9556 || phone.isInEmergencySmsMode() || phone.isInEcm()
9557 || (service != null && service.isEmergencyCallPending())) {
9558 String errorMessage = "Phone state is not valid. call state = "
9559 + PhoneConstantConversions.convertCallState(phone.getState())
9560 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9561 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9562 errorMessage += service == null
9563 ? " TelephonyConnectionService is null"
9564 : " isEmergencyCallPending = "
9565 + service.isEmergencyCallPending();
9566 Log.e(LOG_TAG, errorMessage);
9567 thermalMitigationResult =
9568 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9569 break;
9570 }
9571 } else {
9572 thermalMitigationResult =
9573 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9574 break;
9575 }
9576
9577 // Turn radio off. If not able to power off due to phone being unavailable,
9578 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9579 if (!setRadioPowerForThermal(subId, false)) {
9580 thermalMitigationResult =
9581 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9582 break;
9583 }
9584 thermalMitigationResult =
9585 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9586 break;
9587 default:
9588 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9589 + "not exist. Requested action: " + thermalMitigationAction);
9590 }
9591 } catch (IllegalArgumentException e) {
9592 throw e;
9593 } catch (Exception e) {
9594 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9595 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
9598 }
9599
9600 if (DBG) {
9601 log("thermalMitigationRequest returning with thermalMitigationResult: "
9602 + thermalMitigationResult);
9603 }
9604
9605 return thermalMitigationResult;
9606 }
Hui Wang641e81c2020-10-12 12:14:23 -07009607
9608 /**
9609 * Set the GbaService Package Name that Telephony will bind to.
9610 *
9611 * @param subId The sim that the GbaService is associated with.
9612 * @param packageName The name of the package to be replaced with.
9613 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9614 */
9615 @Override
9616 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9617 enforceModifyPermission();
9618
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 return getGbaManager(subId).overrideServicePackage(packageName);
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 /**
9628 * Return the package name of the currently bound GbaService.
9629 *
9630 * @param subId The sim that the GbaService is associated with.
9631 * @return the package name of the GbaService configuration, null if GBA is not supported.
9632 */
9633 @Override
9634 public String getBoundGbaService(int subId) {
9635 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9636
9637 final long identity = Binder.clearCallingIdentity();
9638 try {
9639 return getGbaManager(subId).getServicePackage();
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
9644
9645 /**
9646 * Set the release time for telephony to unbind GbaService.
9647 *
9648 * @param subId The sim that the GbaService is associated with.
9649 * @param interval The release time to unbind GbaService by millisecond.
9650 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9651 */
9652 @Override
9653 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9654 enforceModifyPermission();
9655
9656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 return getGbaManager(subId).overrideReleaseTime(interval);
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
9661 }
9662 }
9663
9664 /**
9665 * Return the release time for telephony to unbind GbaService.
9666 *
9667 * @param subId The sim that the GbaService is associated with.
9668 * @return The release time to unbind GbaService by millisecond.
9669 */
9670 @Override
9671 public int getGbaReleaseTime(int subId) {
9672 enforceReadPrivilegedPermission("getGbaReleaseTime");
9673
9674 final long identity = Binder.clearCallingIdentity();
9675 try {
9676 return getGbaManager(subId).getReleaseTime();
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
9679 }
9680 }
9681
9682 private GbaManager getGbaManager(int subId) {
9683 GbaManager instance = GbaManager.getInstance(subId);
9684 if (instance == null) {
9685 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9686 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9687 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9688 }
9689 return instance;
9690 }
Hui Wang761a6682020-10-31 05:12:53 +00009691
9692 /**
9693 * indicate whether the device and the carrier can support
9694 * RCS VoLTE single registration.
9695 */
9696 @Override
9697 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9698 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9699
9700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9701 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9702 }
9703
9704 final long identity = Binder.clearCallingIdentity();
9705 try {
9706 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9707 if (rpm != null) {
9708 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9709 }
9710 return false;
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
9716 /**
9717 * Register RCS provisioning callback.
9718 */
9719 @Override
9720 public void registerRcsProvisioningChangedCallback(int subId,
9721 IRcsConfigCallback callback) {
9722 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9723
9724 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9725 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9726 }
9727 if (!isImsAvailableOnDevice()) {
9728 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9729 "IMS not available on device.");
9730 }
9731
9732 final long identity = Binder.clearCallingIdentity();
9733 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009734 if (!RcsProvisioningMonitor.getInstance()
9735 .registerRcsProvisioningChangedCallback(subId, callback)) {
9736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9737 "Service not available for the subscription.");
9738 }
Hui Wang761a6682020-10-31 05:12:53 +00009739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
9743
9744 /**
9745 * Unregister RCS provisioning callback.
9746 */
9747 @Override
9748 public void unregisterRcsProvisioningChangedCallback(int subId,
9749 IRcsConfigCallback callback) {
9750 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9751
9752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9753 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9754 }
9755 if (!isImsAvailableOnDevice()) {
9756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9757 "IMS not available on device.");
9758 }
9759
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009762 RcsProvisioningMonitor.getInstance()
9763 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009764 } finally {
9765 Binder.restoreCallingIdentity(identity);
9766 }
9767 }
9768
9769 /**
9770 * trigger RCS reconfiguration.
9771 */
9772 public void triggerRcsReconfiguration(int subId) {
9773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9774 mApp, subId, "triggerRcsReconfiguration");
9775
9776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9778 }
9779 if (!isImsAvailableOnDevice()) {
9780 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9781 "IMS not available on device.");
9782 }
9783
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9787 } finally {
9788 Binder.restoreCallingIdentity(identity);
9789 }
9790 }
9791
9792 /**
9793 * Provide the client configuration parameters of the RCS application.
9794 */
9795 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9797 mApp, subId, "setRcsClientConfiguration");
9798
9799 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9800 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9801 }
9802 if (!isImsAvailableOnDevice()) {
9803 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9804 "IMS not available on device.");
9805 }
9806
9807 final long identity = Binder.clearCallingIdentity();
9808
9809 try {
9810 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9811 if (configBinder == null) {
9812 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9813 } else {
9814 configBinder.setRcsClientConfiguration(rcc);
9815 }
9816 } catch (RemoteException e) {
9817 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
9822
9823 /**
9824 * Overrides the config of RCS VoLTE single registration enabled for the device.
9825 */
9826 @Override
9827 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9829 "setDeviceSingleRegistrationEnabledOverride");
9830 enforceModifyPermission();
9831
9832 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9833 : Boolean.parseBoolean(enabledStr);
9834 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9835 }
9836
9837 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009838 * Sends a device to device communication message. Only usable via shell.
9839 * @param message message to send.
9840 * @param value message value.
9841 */
9842 @Override
9843 public void sendDeviceToDeviceMessage(int message, int value) {
9844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9845 "setCarrierSingleRegistrationEnabledOverride");
9846 enforceModifyPermission();
9847
9848 final long identity = Binder.clearCallingIdentity();
9849 try {
9850 TelephonyConnectionService service =
9851 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9852 if (service == null) {
9853 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9854 return;
9855 }
9856 service.sendTestDeviceToDeviceMessage(message, value);
9857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862
9863 /**
Hui Wang761a6682020-10-31 05:12:53 +00009864 * Gets the config of RCS VoLTE single registration enabled for the device.
9865 */
9866 @Override
9867 public boolean getDeviceSingleRegistrationEnabled() {
9868 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9869 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9870 }
9871
9872 /**
9873 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9874 */
9875 @Override
9876 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9878 "setCarrierSingleRegistrationEnabledOverride");
9879 enforceModifyPermission();
9880
9881 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9882 : Boolean.parseBoolean(enabledStr);
9883 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9884 subId, enabled);
9885 }
9886
9887 /**
9888 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9889 */
9890 @Override
9891 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9892 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9893 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9894 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009895
9896 /**
9897 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9898 * their mobile plan.
9899 */
9900 @Override
9901 public String getMobileProvisioningUrl() {
9902 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9903 final long identity = Binder.clearCallingIdentity();
9904 try {
9905 return getDefaultPhone().getMobileProvisioningUrl();
9906 } finally {
9907 Binder.restoreCallingIdentity(identity);
9908 }
9909 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009910
James.cf Linbcdf8b32021-01-14 16:44:13 +08009911 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009912 * Get the EAB contact from the EAB database.
9913 */
9914 @Override
9915 public String getContactFromEab(String contact) {
9916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9917 enforceModifyPermission();
9918 final long identity = Binder.clearCallingIdentity();
9919 try {
9920 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9921 } finally {
9922 Binder.restoreCallingIdentity(identity);
9923 }
9924 }
9925
9926 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009927 * Remove the EAB contacts from the EAB database.
9928 */
9929 @Override
9930 public int removeContactFromEab(int subId, String contacts) {
9931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9932 enforceModifyPermission();
9933 final long identity = Binder.clearCallingIdentity();
9934 try {
9935 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9936 } finally {
9937 Binder.restoreCallingIdentity(identity);
9938 }
9939 }
9940
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009941 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009942 public boolean getDeviceUceEnabled() {
9943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9944 final long identity = Binder.clearCallingIdentity();
9945 try {
9946 return mApp.getDeviceUceEnabled();
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
9949 }
9950 }
9951
9952 @Override
9953 public void setDeviceUceEnabled(boolean isEnabled) {
9954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9955 final long identity = Binder.clearCallingIdentity();
9956 try {
9957 mApp.setDeviceUceEnabled(isEnabled);
9958 } finally {
9959 Binder.restoreCallingIdentity(identity);
9960 }
9961 }
9962
9963 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009964 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9965 String callingPackage) {
9966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9967 mApp, subId, "setSignalStrengthUpdateRequest");
9968
9969 final int callingUid = Binder.getCallingUid();
9970 // Verify that tha callingPackage belongs to the calling UID
9971 mApp.getSystemService(AppOpsManager.class)
9972 .checkPackage(callingUid, callingPackage);
9973
9974 validateSignalStrengthUpdateRequest(request, callingUid);
9975
9976 final long identity = Binder.clearCallingIdentity();
9977 try {
9978 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9979 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9980
9981 if (result instanceof IllegalStateException) {
9982 throw (IllegalStateException) result;
9983 }
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
9986 }
9987 }
9988
9989 @Override
9990 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9991 String callingPackage) {
9992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9993 mApp, subId, "clearSignalStrengthUpdateRequest");
9994
9995 final int callingUid = Binder.getCallingUid();
9996 // Verify that tha callingPackage belongs to the calling UID
9997 mApp.getSystemService(AppOpsManager.class)
9998 .checkPackage(callingUid, callingPackage);
9999
10000 final long identity = Binder.clearCallingIdentity();
10001 try {
10002 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10003 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10004
10005 if (result instanceof IllegalStateException) {
10006 throw (IllegalStateException) result;
10007 }
10008 } finally {
10009 Binder.restoreCallingIdentity(identity);
10010 }
10011 }
10012
10013 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10014 int callingUid) {
10015 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10016 // phone/system process do not have further restriction on request
10017 return;
10018 }
10019
10020 // Applications has restrictions on how to use the request:
10021 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10022 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10023 // This is not system caller which has been checked above
10024 throw new IllegalArgumentException(
10025 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10026 }
10027
10028 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10029 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10030 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10031 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10032 || info.isEnabled()) {
10033 throw new IllegalArgumentException(
10034 "Only system can set hide fields in SignalThresholdInfo");
10035 }
10036
10037 // Thresholds length for each RAN need in range. This has been validated in
10038 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10039 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10040 final int[] thresholds = info.getThresholds();
10041 Objects.requireNonNull(thresholds);
10042 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10043 || thresholds.length
10044 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10045 throw new IllegalArgumentException(
10046 "thresholds length is out of range: " + thresholds.length);
10047 }
10048 }
10049 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010050
10051 /**
10052 * Gets the current phone capability.
10053 *
10054 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10055 * @return the PhoneCapability which describes the data connection capability of modem.
10056 * It's used to evaluate possible phone config change, for example from single
10057 * SIM device to multi-SIM device.
10058 */
10059 @Override
10060 public PhoneCapability getPhoneCapability() {
10061 enforceReadPrivilegedPermission("getPhoneCapability");
10062 final long identity = Binder.clearCallingIdentity();
10063 try {
10064 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010069}