blob: 56f58d09a926de2c49f8fd68cbb09cbc0a87a106 [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;
Shuo Qian4a594052020-01-23 11:59:30 -0800134import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700136import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700137import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800138import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700143import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800144import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800145import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700146import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800148import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700152import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700155import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800156import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700157import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700158import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700159import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700160import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700161import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700162import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800164import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800165import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700167import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800168import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700169import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800170import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700171import com.android.internal.telephony.imsphone.ImsPhone;
172import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800173import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700174import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800176import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700179import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800182import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000183import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800184import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700185import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700186import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700188import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700189import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800190import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700192import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800193import com.android.services.telephony.TelecomAccountRegistry;
194import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800195import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800196
Hall Liu82694d52020-12-11 18:22:04 -0800197import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700198import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800199import java.io.IOException;
200import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700201import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800204import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800206import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100207import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700209import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800211import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.util.UUID;
213import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800214import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800215import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
217/**
218 * Implementation of the ITelephony interface.
219 */
Santos Cordon117fee72014-05-16 17:56:12 -0700220public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 private static final String LOG_TAG = "PhoneInterfaceManager";
222 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
223 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225
226 // Message codes used with mMainThreadHandler
227 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700228 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
229 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700230 private static final int CMD_OPEN_CHANNEL = 9;
231 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
232 private static final int CMD_CLOSE_CHANNEL = 11;
233 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800234 private static final int CMD_NV_READ_ITEM = 13;
235 private static final int EVENT_NV_READ_ITEM_DONE = 14;
236 private static final int CMD_NV_WRITE_ITEM = 15;
237 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
238 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
239 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700240 private static final int CMD_RESET_MODEM_CONFIG = 19;
241 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800242 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
243 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800244 private static final int CMD_SEND_ENVELOPE = 25;
245 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000246 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
247 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700248 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
249 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
250 private static final int CMD_EXCHANGE_SIM_IO = 31;
251 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800252 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
253 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700254 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
255 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700256 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
257 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700258 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
259 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
260 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
261 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700262 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
263 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
264 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
265 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700266 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800267 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
268 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000269 private static final int CMD_SWITCH_SLOTS = 50;
270 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700271 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
272 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
273 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
274 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
275 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
276 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
277 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
278 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700279 private static final int CMD_GET_ALL_CELL_INFO = 60;
280 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
281 private static final int CMD_GET_CELL_LOCATION = 62;
282 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700283 private static final int CMD_MODEM_REBOOT = 64;
284 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700285 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
286 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800287 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
288 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700289 private static final int CMD_GET_MODEM_STATUS = 70;
290 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700291 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
292 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700293 private static final int CMD_ERASE_MODEM_CONFIG = 74;
294 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800295 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
296 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
297 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
298 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800299 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
300 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800301 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800302 private static final int CMD_GET_CALL_FORWARDING = 83;
303 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
304 private static final int CMD_SET_CALL_FORWARDING = 85;
305 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
306 private static final int CMD_GET_CALL_WAITING = 87;
307 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
308 private static final int CMD_SET_CALL_WAITING = 89;
309 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700310 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
311 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
312 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
313 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700314 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
315 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800316 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
317 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800318 private static final int CMD_SET_DATA_THROTTLING = 99;
319 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800320 private static final int CMD_SET_SIM_POWER = 101;
321 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800322 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
323 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
324 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
325 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800326 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
327 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800329 // Parameters of select command.
330 private static final int SELECT_COMMAND = 0xA4;
331 private static final int SELECT_P1 = 0x04;
332 private static final int SELECT_P2 = 0;
333 private static final int SELECT_P3 = 0x10;
334
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 /** The singleton instance. */
336 private static PhoneInterfaceManager sInstance;
337
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800340 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700341 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private AppOpsManager mAppOps;
343 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800344 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800345 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700346 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
Peter Wangdafb9ac2020-01-15 14:13:38 -0800348 /** User Activity */
349 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
351
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700352 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
353
Derek Tan97ebb422014-09-05 16:55:38 -0700354 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
355 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800356 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800357 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700358
Michelecea4cf22018-12-21 15:00:11 -0800359 // String to store multi SIM allowed
360 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
361
Derek Tan740e1672017-06-27 14:56:27 -0700362 // The AID of ISD-R.
363 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
364
yinxub1bed742017-04-17 11:45:04 -0700365 private NetworkScanRequestTracker mNetworkScanRequestTracker;
366
David Kelly5e06a7f2018-03-12 14:10:59 +0000367 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
368 private static final int MANUFACTURER_CODE_LENGTH = 8;
369
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800370 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
371
Derek Tan89e89d42014-07-08 17:00:10 -0700372 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700373 * Experiment flag to enable erase modem config on reset network, default value is false
374 */
375 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
376 "reset_network_erase_modem_config_enabled";
377
378 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700379 * A request object to use for transmitting data to an ICC.
380 */
381 private static final class IccAPDUArgument {
382 public int channel, cla, command, p1, p2, p3;
383 public String data;
384
385 public IccAPDUArgument(int channel, int cla, int command,
386 int p1, int p2, int p3, String data) {
387 this.channel = channel;
388 this.cla = cla;
389 this.command = command;
390 this.p1 = p1;
391 this.p2 = p2;
392 this.p3 = p3;
393 this.data = data;
394 }
395 }
396
397 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700398 * A request object to use for transmitting data to an ICC.
399 */
400 private static final class ManualNetworkSelectionArgument {
401 public OperatorInfo operatorInfo;
402 public boolean persistSelection;
403
404 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
405 this.operatorInfo = operatorInfo;
406 this.persistSelection = persistSelection;
407 }
408 }
409
410 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
412 * request after sending. The main thread will notify the request when it is complete.
413 */
414 private static final class MainThreadRequest {
415 /** The argument to use for the request */
416 public Object argument;
417 /** The result of the request that is run on the main thread */
418 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800419 // The subscriber id that this request applies to. Defaults to
420 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
421 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422
Nathan Harold92bed182018-10-12 18:16:49 -0700423 // In cases where subId is unavailable, the caller needs to specify the phone.
424 public Phone phone;
425
vagdeviaf9a5b92018-08-15 16:01:53 -0700426 public WorkSource workSource;
427
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 public MainThreadRequest(Object argument) {
429 this.argument = argument;
430 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800431
Nathan Harold92bed182018-10-12 18:16:49 -0700432 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
433 this.argument = argument;
434 if (phone != null) {
435 this.phone = phone;
436 }
437 this.workSource = workSource;
438 }
439
vagdeviaf9a5b92018-08-15 16:01:53 -0700440 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800441 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800442 if (subId != null) {
443 this.subId = subId;
444 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700445 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 }
448
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800449 private static final class IncomingThirdPartyCallArgs {
450 public final ComponentName component;
451 public final String callId;
452 public final String callerDisplayName;
453
454 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
455 String callerDisplayName) {
456 this.component = component;
457 this.callId = callId;
458 this.callerDisplayName = callerDisplayName;
459 }
460 }
461
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 /**
463 * A handler that processes messages on the main thread in the phone process. Since many
464 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
465 * inbound binder threads to the main thread in the phone process. The Binder thread
466 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
467 * on, which will be notified when the operation completes and will contain the result of the
468 * request.
469 *
470 * <p>If a MainThreadRequest object is provided in the msg.obj field,
471 * note that request.result must be set to something non-null for the calling thread to
472 * unblock.
473 */
474 private final class MainThreadHandler extends Handler {
475 @Override
476 public void handleMessage(Message msg) {
477 MainThreadRequest request;
478 Message onCompleted;
479 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800480 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800482 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483
484 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 case CMD_HANDLE_USSD_REQUEST: {
486 request = (MainThreadRequest) msg.obj;
487 final Phone phone = getPhoneFromRequest(request);
488 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
489 String ussdRequest = ussdObject.first;
490 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700491
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 if (!isUssdApiAllowed(request.subId)) {
493 // Carrier does not support use of this API, return failure.
494 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
495 UssdResponse response = new UssdResponse(ussdRequest, null);
496 Bundle returnData = new Bundle();
497 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
498 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700499
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 request.result = true;
501 notifyRequester(request);
502 return;
503 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700504
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 try {
506 request.result = phone != null
507 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
508 } catch (CallStateException cse) {
509 request.result = false;
510 }
511 // Wake up the requesting thread
512 notifyRequester(request);
513 break;
pkanwar32d516d2016-10-14 19:37:38 -0700514 }
515
Yorke Lee716f67e2015-06-17 15:39:16 -0700516 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700518 final Phone phone = getPhoneFromRequest(request);
519 request.result = phone != null ?
520 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
521 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 if (uiccCard == null) {
532 loge("iccTransmitApduLogicalChannel: No UICC");
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
537 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 iccArgument.channel, iccArgument.cla, iccArgument.command,
540 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 break;
544
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
550 } else {
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
552 if (ar.result == null) {
553 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800554 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800556 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 } else {
558 loge("iccTransmitApduLogicalChannel: Unknown exception");
559 }
560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 break;
563
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
565 request = (MainThreadRequest) msg.obj;
566 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 if (uiccCard == null) {
569 loge("iccTransmitApduBasicChannel: No UICC");
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 } else {
573 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
574 request);
575 uiccCard.iccTransmitApduBasicChannel(
576 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
577 iccArgument.p3, iccArgument.data, onCompleted);
578 }
579 break;
580
581 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
584 if (ar.exception == null && ar.result != null) {
585 request.result = ar.result;
586 } else {
587 request.result = new IccIoResult(0x6F, 0, (byte[])null);
588 if (ar.result == null) {
589 loge("iccTransmitApduBasicChannel: Empty response");
590 } else if (ar.exception instanceof CommandException) {
591 loge("iccTransmitApduBasicChannel: CommandException: " +
592 ar.exception);
593 } else {
594 loge("iccTransmitApduBasicChannel: Unknown exception");
595 }
596 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 break;
599
600 case CMD_EXCHANGE_SIM_IO:
601 request = (MainThreadRequest) msg.obj;
602 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800603 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 if (uiccCard == null) {
605 loge("iccExchangeSimIO: No UICC");
606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 } else {
609 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
610 request);
611 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
612 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
613 iccArgument.data, onCompleted);
614 }
615 break;
616
617 case EVENT_EXCHANGE_SIM_IO_DONE:
618 ar = (AsyncResult) msg.obj;
619 request = (MainThreadRequest) ar.userObj;
620 if (ar.exception == null && ar.result != null) {
621 request.result = ar.result;
622 } else {
623 request.result = new IccIoResult(0x6f, 0, (byte[])null);
624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 break;
627
Derek Tan4d5e5c12014-02-04 11:54:58 -0800628 case CMD_SEND_ENVELOPE:
629 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800630 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 if (uiccCard == null) {
632 loge("sendEnvelopeWithStatus: No UICC");
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
637 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
638 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800639 break;
640
641 case EVENT_SEND_ENVELOPE_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700647 request.result = new IccIoResult(0x6F, 0, (byte[])null);
648 if (ar.result == null) {
649 loge("sendEnvelopeWithStatus: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("sendEnvelopeWithStatus: CommandException: " +
652 ar.exception);
653 } else {
654 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
655 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 break;
659
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 case CMD_OPEN_CHANNEL:
661 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800662 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800663 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 if (uiccCard == null) {
665 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800666 request.result = new IccOpenLogicalChannelResponse(-1,
667 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700669 } else {
670 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800671 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
672 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case EVENT_OPEN_CHANNEL_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 int[] result = (int[]) ar.result;
682 int channelId = result[0];
683 byte[] selectResponse = null;
684 if (result.length > 1) {
685 selectResponse = new byte[result.length - 1];
686 for (int i = 1; i < result.length; ++i) {
687 selectResponse[i - 1] = (byte) result[i];
688 }
689 }
690 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700691 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 if (ar.result == null) {
694 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 if (ar.exception != null) {
697 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
698 }
699
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700701 if (ar.exception instanceof CommandException) {
702 CommandException.Error error =
703 ((CommandException) (ar.exception)).getCommandError();
704 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700705 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700706 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
709 }
710 openChannelResp = new IccOpenLogicalChannelResponse(
711 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700713 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 break;
716
717 case CMD_CLOSE_CHANNEL:
718 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800719 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 if (uiccCard == null) {
721 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900722 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 } else {
725 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
726 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
727 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 break;
729
730 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800731 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
732 break;
733
734 case CMD_NV_READ_ITEM:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
738 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800739 break;
740
741 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 ar = (AsyncResult) msg.obj;
743 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800744 if (ar.exception == null && ar.result != null) {
745 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800747 request.result = "";
748 if (ar.result == null) {
749 loge("nvReadItem: Empty response");
750 } else if (ar.exception instanceof CommandException) {
751 loge("nvReadItem: CommandException: " +
752 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800754 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 }
756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 break;
759
Jake Hambye994d462014-02-03 13:10:13 -0800760 case CMD_NV_WRITE_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
763 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700765 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
768 case EVENT_NV_WRITE_ITEM_DONE:
769 handleNullReturnEvent(msg, "nvWriteItem");
770 break;
771
772 case CMD_NV_WRITE_CDMA_PRL:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800775 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800776 break;
777
778 case EVENT_NV_WRITE_CDMA_PRL_DONE:
779 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
780 break;
781
chen xu6dac5ab2018-10-26 17:39:23 -0700782 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800783 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700784 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
chen xu6dac5ab2018-10-26 17:39:23 -0700788 case EVENT_RESET_MODEM_CONFIG_DONE:
789 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800790 break;
791
Sooraj Sasindran37444802020-08-11 10:40:43 -0700792 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
795 request);
796 Phone phone = getPhoneFromRequest(request);
797 if (phone != null) {
798 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
799 } else {
800 loge("isNRDualConnectivityEnabled: No phone object");
801 request.result = false;
802 notifyRequester(request);
803 }
804 break;
805 }
806
807 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 // request.result must be set to something non-null
814 // for the calling thread to unblock
815 if (request.result != null) {
816 request.result = ar.result;
817 } else {
818 request.result = false;
819 }
820 if (ar.result == null) {
821 loge("isNRDualConnectivityEnabled: Empty response");
822 } else if (ar.exception instanceof CommandException) {
823 loge("isNRDualConnectivityEnabled: CommandException: "
824 + ar.exception);
825 } else {
826 loge("isNRDualConnectivityEnabled: Unknown exception");
827 }
828 }
829 notifyRequester(request);
830 break;
831
832 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
835 Phone phone = getPhoneFromRequest(request);
836 if (phone != null) {
837 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
838 request.workSource);
839 } else {
840 loge("enableNrDualConnectivity: No phone object");
841 request.result =
842 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
843 notifyRequester(request);
844 }
845 break;
846 }
847
848 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null) {
852 request.result =
853 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
854 } else {
855 request.result =
856 TelephonyManager
857 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
858 if (ar.exception instanceof CommandException) {
859 CommandException.Error error =
860 ((CommandException) (ar.exception)).getCommandError();
861 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
862 request.result =
863 TelephonyManager
864 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
865 }
866 loge("enableNrDualConnectivity" + ": CommandException: "
867 + ar.exception);
868 } else {
869 loge("enableNrDualConnectivity" + ": Unknown exception");
870 }
871 }
872 notifyRequester(request);
873 break;
874 }
875
SongFerngWang3ef3e072020-12-21 16:41:52 +0800876 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800877 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800878 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
879 request);
880 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800881 break;
882
SongFerngWang3ef3e072020-12-21 16:41:52 +0800883 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result; // Integer
888 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530889 // request.result must be set to something non-null
890 // for the calling thread to unblock
891 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800892 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800893 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800895 loge("getAllowedNetworkTypesBitmask: CommandException: "
896 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800898 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 }
900 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 break;
903
SongFerngWang3ef3e072020-12-21 16:41:52 +0800904 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800906 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
907 request);
908 Pair<Integer, Long> reasonWithNetworkTypes =
909 (Pair<Integer, Long>) request.argument;
910 getPhoneFromRequest(request).setAllowedNetworkTypes(
911 reasonWithNetworkTypes.first,
912 reasonWithNetworkTypes.second,
913 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 break;
915
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
917 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 break;
919
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000920 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
921 request = (MainThreadRequest)msg.obj;
922 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800923 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000924 break;
925
926 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
927 ar = (AsyncResult)msg.obj;
928 request = (MainThreadRequest)ar.userObj;
929 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000931 break;
932
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800933 case CMD_SET_VOICEMAIL_NUMBER:
934 request = (MainThreadRequest) msg.obj;
935 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
936 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800937 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
938 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800939 break;
940
941 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
942 handleNullReturnEvent(msg, "setVoicemailNumber");
943 break;
944
Stuart Scott54788802015-03-30 13:18:01 -0700945 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
948 request);
949 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
950 break;
951
952 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
953 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
954 break;
955
Shishir Agrawal302c8692015-06-19 13:49:39 -0700956 case CMD_PERFORM_NETWORK_SCAN:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
959 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
960 break;
961
Hall Liu27d24262020-09-18 19:04:59 -0700962 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700965 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
966 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
967 request.argument;
968 int callForwardingReason = args.first;
969 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800970 break;
Hall Liu27d24262020-09-18 19:04:59 -0700971 }
972 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700975 TelephonyManager.CallForwardingInfoCallback callback =
976 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
977 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800978 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700979 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800980 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
981 for (CallForwardInfo callForwardInfo : callForwardInfos) {
982 // Service Class is a bit mask per 3gpp 27.007. Search for
983 // any service for voice call.
984 if ((callForwardInfo.serviceClass
985 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700986 callForwardingInfo = new CallForwardingInfo(true,
987 callForwardInfo.reason,
988 callForwardInfo.number,
989 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800990 break;
991 }
992 }
993 // Didn't find a call forward info for voice call.
994 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700995 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
996 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800997 }
Hall Liu27d24262020-09-18 19:04:59 -0700998 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800999 } else {
1000 if (ar.result == null) {
1001 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1002 }
1003 if (ar.exception != null) {
1004 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1005 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001006 int errorCode = TelephonyManager
1007 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001008 if (ar.exception instanceof CommandException) {
1009 CommandException.Error error =
1010 ((CommandException) (ar.exception)).getCommandError();
1011 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001012 errorCode = TelephonyManager
1013 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001014 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001015 errorCode = TelephonyManager
1016 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001017 }
1018 }
Hall Liu27d24262020-09-18 19:04:59 -07001019 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001020 }
Shuo Qian4a594052020-01-23 11:59:30 -08001021 break;
Hall Liu27d24262020-09-18 19:04:59 -07001022 }
Shuo Qian4a594052020-01-23 11:59:30 -08001023
Hall Liu27d24262020-09-18 19:04:59 -07001024 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001027 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001028 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001029 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1030 request.argument).first;
1031 request.phone.setCallForwardingOption(
1032 callForwardingInfoToSet.isEnabled()
1033 ? CommandsInterface.CF_ACTION_ENABLE
1034 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001035 callForwardingInfoToSet.getReason(),
1036 callForwardingInfoToSet.getNumber(),
1037 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1038 break;
Hall Liu27d24262020-09-18 19:04:59 -07001039 }
Shuo Qian4a594052020-01-23 11:59:30 -08001040
Hall Liu27d24262020-09-18 19:04:59 -07001041 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001044 Consumer<Integer> callback =
1045 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1046 request.argument).second;
1047 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001048 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001049 int errorCode = TelephonyManager.CallForwardingInfoCallback
1050 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001051 if (ar.exception instanceof CommandException) {
1052 CommandException.Error error =
1053 ((CommandException) (ar.exception)).getCommandError();
1054 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001055 errorCode = TelephonyManager.CallForwardingInfoCallback
1056 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001057 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001058 errorCode = TelephonyManager.CallForwardingInfoCallback
1059 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001060 }
1061 }
1062 callback.accept(errorCode);
1063 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001064 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001065 }
Shuo Qian4a594052020-01-23 11:59:30 -08001066 break;
Hall Liu27d24262020-09-18 19:04:59 -07001067 }
Shuo Qian4a594052020-01-23 11:59:30 -08001068
Hall Liu27d24262020-09-18 19:04:59 -07001069 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1072 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1073 break;
Hall Liu27d24262020-09-18 19:04:59 -07001074 }
Shuo Qian4a594052020-01-23 11:59:30 -08001075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001079 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001080 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1081 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001082 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001083 // Service Class is a bit mask per 3gpp 27.007.
1084 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001085 if (callForwardResults.length > 1
1086 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001087 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001088 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001089 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1090 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001091 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001092 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 }
1094 } else {
1095 if (ar.result == null) {
1096 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1097 }
1098 if (ar.exception != null) {
1099 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1100 }
1101 if (ar.exception instanceof CommandException) {
1102 CommandException.Error error =
1103 ((CommandException) (ar.exception)).getCommandError();
1104 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1105 callForwardingStatus =
1106 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1107 }
1108 }
1109 }
Hall Liu27d24262020-09-18 19:04:59 -07001110 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001111 break;
Hall Liu27d24262020-09-18 19:04:59 -07001112 }
Shuo Qian4a594052020-01-23 11:59:30 -08001113
Hall Liu27d24262020-09-18 19:04:59 -07001114 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001115 request = (MainThreadRequest) msg.obj;
1116 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001117 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1118 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001119 break;
Hall Liu27d24262020-09-18 19:04:59 -07001120 }
Shuo Qian4a594052020-01-23 11:59:30 -08001121
Hall Liu27d24262020-09-18 19:04:59 -07001122 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001125 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1126 Consumer<Integer> callback =
1127 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1128 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001129 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001130 if (ar.exception instanceof CommandException) {
1131 CommandException.Error error =
1132 ((CommandException) (ar.exception)).getCommandError();
1133 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1134 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1135 } else {
1136 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1137 }
1138 } else {
1139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1140 }
1141 } else {
1142 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1143 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001144 }
Shuo Qian4a594052020-01-23 11:59:30 -08001145 break;
Hall Liu27d24262020-09-18 19:04:59 -07001146 }
Shuo Qian4a594052020-01-23 11:59:30 -08001147
Shishir Agrawal302c8692015-06-19 13:49:39 -07001148 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 CellNetworkScanResult cellScanResult;
1152 if (ar.exception == null && ar.result != null) {
1153 cellScanResult = new CellNetworkScanResult(
1154 CellNetworkScanResult.STATUS_SUCCESS,
1155 (List<OperatorInfo>) ar.result);
1156 } else {
1157 if (ar.result == null) {
1158 loge("getCellNetworkScanResults: Empty response");
1159 }
1160 if (ar.exception != null) {
1161 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1162 }
1163 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1164 if (ar.exception instanceof CommandException) {
1165 CommandException.Error error =
1166 ((CommandException) (ar.exception)).getCommandError();
1167 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1168 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1169 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1170 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1171 }
1172 }
1173 cellScanResult = new CellNetworkScanResult(errorCode, null);
1174 }
1175 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001177 break;
1178
1179 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1180 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001181 ManualNetworkSelectionArgument selArg =
1182 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001183 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1184 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001185 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1186 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001187 break;
1188
1189 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
1192 if (ar.exception == null) {
1193 request.result = true;
1194 } else {
1195 request.result = false;
1196 loge("setNetworkSelectionModeManual " + ar.exception);
1197 }
1198 notifyRequester(request);
1199 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001200 break;
1201
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001202 case CMD_GET_MODEM_ACTIVITY_INFO:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001205 if (defaultPhone != null) {
1206 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001207 } else {
1208 ResultReceiver result = (ResultReceiver) request.argument;
1209 Bundle bundle = new Bundle();
1210 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001211 new ModemActivityInfo(0, 0, 0,
1212 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001213 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001214 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001215 break;
1216
Hall Liud0f208c2020-10-14 16:54:44 -07001217 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001218 ar = (AsyncResult) msg.obj;
1219 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001220 ResultReceiver result = (ResultReceiver) request.argument;
1221
Hall Liud0f208c2020-10-14 16:54:44 -07001222 ModemActivityInfo ret = null;
1223 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001224 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001225 // Update the last modem activity info and the result of the request.
1226 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1227 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001228 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 int[] txTimeMs = info.getTransmitTimeMillis();
1230 int[] lastModemTxTimeMs = mLastModemActivityInfo
1231 .getTransmitTimeMillis();
1232 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1233 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1234 }
Hall Liu49656c02020-10-09 19:00:11 -07001235 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001236 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1237 + mLastModemActivityInfo.getSleepTimeMillis());
1238 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1239 + mLastModemActivityInfo.getIdleTimeMillis());
1240 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1241 mLastModemActivityInfo.setReceiveTimeMillis(
1242 info.getReceiveTimeMillis()
1243 + mLastModemActivityInfo.getReceiveTimeMillis());
1244 }
Hall Liu49656c02020-10-09 19:00:11 -07001245 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001246 mLastModemActivityInfo.getSleepTimeMillis(),
1247 mLastModemActivityInfo.getIdleTimeMillis(),
1248 mLastModemActivityInfo.getTransmitTimeMillis(),
1249 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001250 } else {
1251 if (ar.result == null) {
1252 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001253 error = TelephonyManager.ModemActivityInfoException
1254 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001255 } else if (ar.exception instanceof CommandException) {
1256 loge("queryModemActivityInfo: CommandException: " +
1257 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001258 error = TelephonyManager.ModemActivityInfoException
1259 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001260 } else {
1261 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001262 error = TelephonyManager.ModemActivityInfoException
1263 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001264 }
1265 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001266 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001267 if (ret != null) {
1268 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1269 } else {
1270 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1271 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001272 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001273 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001274 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001275 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276
Meng Wang1a7c35a2016-05-05 20:56:15 -07001277 case CMD_SET_ALLOWED_CARRIERS:
1278 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001279 CarrierRestrictionRules argument =
1280 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001282 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001283 break;
1284
1285 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1286 ar = (AsyncResult) msg.obj;
1287 request = (MainThreadRequest) ar.userObj;
1288 if (ar.exception == null && ar.result != null) {
1289 request.result = ar.result;
1290 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001291 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1292 if (ar.exception instanceof CommandException) {
1293 loge("setAllowedCarriers: CommandException: " + ar.exception);
1294 CommandException.Error error =
1295 ((CommandException) (ar.exception)).getCommandError();
1296 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1297 request.result =
1298 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1299 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 } else {
1301 loge("setAllowedCarriers: Unknown exception");
1302 }
1303 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001304 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 break;
1306
1307 case CMD_GET_ALLOWED_CARRIERS:
1308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001310 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001311 break;
1312
1313 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1314 ar = (AsyncResult) msg.obj;
1315 request = (MainThreadRequest) ar.userObj;
1316 if (ar.exception == null && ar.result != null) {
1317 request.result = ar.result;
1318 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001319 request.result = new IllegalStateException(
1320 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001321 if (ar.result == null) {
1322 loge("getAllowedCarriers: Empty response");
1323 } else if (ar.exception instanceof CommandException) {
1324 loge("getAllowedCarriers: CommandException: " +
1325 ar.exception);
1326 } else {
1327 loge("getAllowedCarriers: Unknown exception");
1328 }
1329 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001330 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001331 break;
1332
Nathan Haroldb3014052017-01-25 15:57:32 -08001333 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1334 ar = (AsyncResult) msg.obj;
1335 request = (MainThreadRequest) ar.userObj;
1336 if (ar.exception == null && ar.result != null) {
1337 request.result = ar.result;
1338 } else {
1339 request.result = new IllegalArgumentException(
1340 "Failed to retrieve Forbidden Plmns");
1341 if (ar.result == null) {
1342 loge("getForbiddenPlmns: Empty response");
1343 } else {
1344 loge("getForbiddenPlmns: Unknown exception");
1345 }
1346 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001347 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001348 break;
1349
1350 case CMD_GET_FORBIDDEN_PLMNS:
1351 request = (MainThreadRequest) msg.obj;
1352 uiccCard = getUiccCardFromRequest(request);
1353 if (uiccCard == null) {
1354 loge("getForbiddenPlmns() UiccCard is null");
1355 request.result = new IllegalArgumentException(
1356 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001358 break;
1359 }
1360 Integer appType = (Integer) request.argument;
1361 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1362 if (uiccApp == null) {
1363 loge("getForbiddenPlmns() no app with specified type -- "
1364 + appType);
1365 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001366 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001367 break;
1368 } else {
1369 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1370 + " specified type -- " + appType);
1371 }
1372 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1373 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1374 onCompleted);
1375 break;
1376
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001377 case CMD_SWITCH_SLOTS:
1378 request = (MainThreadRequest) msg.obj;
1379 int[] physicalSlots = (int[]) request.argument;
1380 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1381 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1382 break;
1383
1384 case EVENT_SWITCH_SLOTS_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
1389 break;
1390 case CMD_GET_NETWORK_SELECTION_MODE:
1391 request = (MainThreadRequest) msg.obj;
1392 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1393 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1394 break;
1395
1396 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 if (ar.exception != null) {
1400 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1401 } else {
1402 int mode = ((int[]) ar.result)[0];
1403 if (mode == 0) {
1404 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1405 } else {
1406 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1407 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001408 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 notifyRequester(request);
1410 break;
1411 case CMD_GET_CDMA_ROAMING_MODE:
1412 request = (MainThreadRequest) msg.obj;
1413 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1414 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1415 break;
1416 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
1419 if (ar.exception != null) {
1420 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1421 } else {
1422 request.result = ((int[]) ar.result)[0];
1423 }
1424 notifyRequester(request);
1425 break;
1426 case CMD_SET_CDMA_ROAMING_MODE:
1427 request = (MainThreadRequest) msg.obj;
1428 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1429 int mode = (int) request.argument;
1430 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1431 break;
1432 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 request.result = ar.exception == null;
1436 notifyRequester(request);
1437 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001438 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1441 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1442 break;
1443 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception != null) {
1447 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1448 } else {
1449 request.result = ((int[]) ar.result)[0];
1450 }
1451 notifyRequester(request);
1452 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001453 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1456 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001457 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1458 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001459 break;
1460 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
1463 request.result = ar.exception == null;
1464 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001465 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 case CMD_GET_ALL_CELL_INFO:
1467 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001468 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001469 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001471 case EVENT_GET_ALL_CELL_INFO_DONE:
1472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001474 // If a timeout occurs, the response will be null
1475 request.result = (ar.exception == null && ar.result != null)
1476 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 synchronized (request) {
1478 request.notifyAll();
1479 }
1480 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 case CMD_REQUEST_CELL_INFO_UPDATE:
1482 request = (MainThreadRequest) msg.obj;
1483 request.phone.requestCellInfoUpdate(request.workSource,
1484 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1485 break;
1486 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1487 ar = (AsyncResult) msg.obj;
1488 request = (MainThreadRequest) ar.userObj;
1489 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1490 try {
1491 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001492 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001493 cb.onError(
1494 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1495 ar.exception.getClass().getName(),
1496 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001497 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001498 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001499 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001500 } else {
1501 // use the result as returned
1502 cb.onCellInfo((List<CellInfo>) ar.result);
1503 }
1504 } catch (RemoteException re) {
1505 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1506 }
1507 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001508 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001509 request = (MainThreadRequest) msg.obj;
1510 WorkSource ws = (WorkSource) request.argument;
1511 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001512 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001513 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001514 }
1515 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001516 ar = (AsyncResult) msg.obj;
1517 request = (MainThreadRequest) ar.userObj;
1518 if (ar.exception == null) {
1519 request.result = ar.result;
1520 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001521 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001522 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001523 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001524 }
1525
1526 synchronized (request) {
1527 request.notifyAll();
1528 }
1529 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001530 }
chen xu6dac5ab2018-10-26 17:39:23 -07001531 case CMD_MODEM_REBOOT:
1532 request = (MainThreadRequest) msg.obj;
1533 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001534 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001535 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001536 case EVENT_CMD_MODEM_REBOOT_DONE:
1537 handleNullReturnEvent(msg, "rebootModem");
1538 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001539 case CMD_REQUEST_ENABLE_MODEM:
1540 request = (MainThreadRequest) msg.obj;
1541 boolean enable = (boolean) request.argument;
1542 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001543 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001544 PhoneConfigurationManager.getInstance()
1545 .enablePhone(request.phone, enable, onCompleted);
1546 break;
1547 case EVENT_ENABLE_MODEM_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001551 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001552 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001553 if ((boolean) request.result) {
1554 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1555 updateModemStateMetrics();
1556 } else {
1557 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1558 + ar.exception);
1559 }
1560 notifyRequester(request);
1561 break;
1562 case CMD_GET_MODEM_STATUS:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1565 PhoneConfigurationManager.getInstance()
1566 .getPhoneStatusFromModem(request.phone, onCompleted);
1567 break;
1568 case EVENT_GET_MODEM_STATUS_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 int id = request.phone.getPhoneId();
1572 if (ar.exception == null && ar.result != null) {
1573 request.result = ar.result;
1574 //update the cache as modem status has changed
1575 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1576 (boolean) request.result);
1577 } else {
1578 // Return true if modem status cannot be retrieved. For most cases,
1579 // modem status is on. And for older version modems, GET_MODEM_STATUS
1580 // and disable modem are not supported. Modem is always on.
1581 // TODO: this should be fixed in R to support a third
1582 // status UNKNOWN b/131631629
1583 request.result = true;
1584 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1585 + ar.exception);
1586 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001587 notifyRequester(request);
1588 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001589 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1592 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1593 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1594 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1595 break;
1596 }
1597 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1601 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1602 args.second.accept(ar.exception == null);
1603 notifyRequester(request);
1604 break;
1605 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001606 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1609 Phone phone = getPhoneFromRequest(request);
1610 if (phone != null) {
1611 phone.getSystemSelectionChannels(onCompleted);
1612 } else {
1613 loge("getSystemSelectionChannels: No phone object");
1614 request.result = new ArrayList<RadioAccessSpecifier>();
1615 notifyRequester(request);
1616 }
1617 break;
1618 }
1619 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 if (ar.exception == null && ar.result != null) {
1623 request.result = ar.result;
1624 } else {
1625 request.result = new IllegalArgumentException(
1626 "Failed to retrieve system selection channels");
1627 if (ar.result == null) {
1628 loge("getSystemSelectionChannels: Empty response");
1629 } else {
1630 loge("getSystemSelectionChannels: Unknown exception");
1631 }
1632 }
1633 notifyRequester(request);
1634 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001635 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception == null && ar.result != null) {
1639 request.result = ar.result;
1640 } else {
1641 request.result = -1;
1642 loge("Failed to set Forbidden Plmns");
1643 if (ar.result == null) {
1644 loge("setForbidenPlmns: Empty response");
1645 } else if (ar.exception != null) {
1646 loge("setForbiddenPlmns: Exception: " + ar.exception);
1647 request.result = -1;
1648 } else {
1649 loge("setForbiddenPlmns: Unknown exception");
1650 }
1651 }
1652 notifyRequester(request);
1653 break;
1654 case CMD_SET_FORBIDDEN_PLMNS:
1655 request = (MainThreadRequest) msg.obj;
1656 uiccCard = getUiccCardFromRequest(request);
1657 if (uiccCard == null) {
1658 loge("setForbiddenPlmns: UiccCard is null");
1659 request.result = -1;
1660 notifyRequester(request);
1661 break;
1662 }
1663 Pair<Integer, List<String>> setFplmnsArgs =
1664 (Pair<Integer, List<String>>) request.argument;
1665 appType = setFplmnsArgs.first;
1666 List<String> fplmns = setFplmnsArgs.second;
1667 uiccApp = uiccCard.getApplicationByType(appType);
1668 if (uiccApp == null) {
1669 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1670 request.result = -1;
1671 loge("Failed to get UICC App");
1672 notifyRequester(request);
1673 } else {
1674 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1675 ((SIMRecords) uiccApp.getIccRecords())
1676 .setForbiddenPlmns(onCompleted, fplmns);
1677 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001678 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001679 case CMD_ERASE_MODEM_CONFIG:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1682 defaultPhone.eraseModemConfig(onCompleted);
1683 break;
1684 case EVENT_ERASE_MODEM_CONFIG_DONE:
1685 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001686 break;
zoey chene02881a2019-12-30 16:11:23 +08001687
1688 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1691 Pair<String, String> changed = (Pair<String, String>) request.argument;
1692 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1693 changed.first, changed.second, onCompleted);
1694 break;
1695 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1700 } else {
1701 request.result = msg.arg1;
1702 }
1703 notifyRequester(request);
1704 break;
1705
1706 case CMD_SET_ICC_LOCK_ENABLED:
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1709 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1710 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1711 enabled.first, enabled.second, onCompleted);
1712 break;
1713 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception == null) {
1717 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1718 } else {
1719 request.result = msg.arg1;
1720 }
1721 notifyRequester(request);
1722 break;
1723
Peter Wangdafb9ac2020-01-15 14:13:38 -08001724 case MSG_NOTIFY_USER_ACTIVITY:
1725 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001726 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001727 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1728 getDefaultPhone().getContext().sendBroadcastAsUser(
1729 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1730 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001731
1732 case CMD_SET_DATA_THROTTLING: {
1733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1735 DataThrottlingRequest dataThrottlingRequest =
1736 (DataThrottlingRequest) request.argument;
1737 Phone phone = getPhoneFromRequest(request);
1738 if (phone != null) {
1739 phone.setDataThrottling(onCompleted,
1740 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1741 dataThrottlingRequest.getCompletionDurationMillis());
1742 } else {
1743 loge("setDataThrottling: No phone object");
1744 request.result =
1745 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1746 notifyRequester(request);
1747 }
1748
1749 break;
1750 }
1751 case EVENT_SET_DATA_THROTTLING_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754
1755 if (ar.exception == null) {
1756 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1757 } else if (ar.exception instanceof CommandException) {
1758 loge("setDataThrottling: CommandException: " + ar.exception);
1759 CommandException.Error error =
1760 ((CommandException) (ar.exception)).getCommandError();
1761
1762 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1763 request.result = TelephonyManager
1764 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1765 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1766 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1767 } else {
1768 request.result =
1769 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1770 }
1771 } else {
1772 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1773 }
1774 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1775 notifyRequester(request);
1776 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001777
1778 case CMD_SET_SIM_POWER: {
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1781 request = (MainThreadRequest) msg.obj;
1782 int stateToSet =
1783 ((Pair<Integer, IIntegerConsumer>)
1784 request.argument).first;
1785 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1786 break;
1787 }
1788 case EVENT_SET_SIM_POWER_DONE: {
1789 ar = (AsyncResult) msg.obj;
1790 request = (MainThreadRequest) ar.userObj;
1791 IIntegerConsumer callback =
1792 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1793 if (ar.exception != null) {
1794 loge("setSimPower exception: " + ar.exception);
1795 int errorCode = TelephonyManager.CallForwardingInfoCallback
1796 .RESULT_ERROR_UNKNOWN;
1797 if (ar.exception instanceof CommandException) {
1798 CommandException.Error error =
1799 ((CommandException) (ar.exception)).getCommandError();
1800 if (error == CommandException.Error.SIM_ERR) {
1801 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1802 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1803 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1804 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1805 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1806 } else {
1807 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1808 }
1809 }
1810 try {
1811 callback.accept(errorCode);
1812 } catch (RemoteException e) {
1813 // Ignore if the remote process is no longer available to call back.
1814 Log.w(LOG_TAG, "setSimPower: callback not available.");
1815 }
1816 } else {
1817 try {
1818 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1819 } catch (RemoteException e) {
1820 // Ignore if the remote process is no longer available to call back.
1821 Log.w(LOG_TAG, "setSimPower: callback not available.");
1822 }
1823 }
1824 break;
1825 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001826 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1827 request = (MainThreadRequest) msg.obj;
1828
1829 final Phone phone = getPhoneFromRequest(request);
1830 if (phone == null || phone.getServiceStateTracker() == null) {
1831 request.result = new IllegalStateException("Phone or SST is null");
1832 notifyRequester(request);
1833 break;
1834 }
1835
1836 Pair<Integer, SignalStrengthUpdateRequest> pair =
1837 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1838 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1839 request);
1840 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1841 request.subId, pair.first /*callingUid*/,
1842 pair.second /*request*/, onCompleted);
1843 break;
1844 }
1845 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1846 ar = (AsyncResult) msg.obj;
1847 request = (MainThreadRequest) ar.userObj;
1848 // request.result will be the exception of ar if present, true otherwise.
1849 // Be cautious not to leave result null which will wait() forever
1850 request.result = ar.exception != null ? ar.exception : true;
1851 notifyRequester(request);
1852 break;
1853 }
1854 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1855 request = (MainThreadRequest) msg.obj;
1856
1857 Phone phone = getPhoneFromRequest(request);
1858 if (phone == null || phone.getServiceStateTracker() == null) {
1859 request.result = new IllegalStateException("Phone or SST is null");
1860 notifyRequester(request);
1861 break;
1862 }
1863
1864 Pair<Integer, SignalStrengthUpdateRequest> pair =
1865 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1866 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1867 request);
1868 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1869 request.subId, pair.first /*callingUid*/,
1870 pair.second /*request*/, onCompleted);
1871 break;
1872 }
1873 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1874 ar = (AsyncResult) msg.obj;
1875 request = (MainThreadRequest) ar.userObj;
1876 request.result = ar.exception != null ? ar.exception : true;
1877 notifyRequester(request);
1878 break;
1879 }
Jordan Liu109698e2020-11-24 14:50:34 -08001880
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 default:
1882 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1883 break;
1884 }
1885 }
Jake Hambye994d462014-02-03 13:10:13 -08001886
Pengquan Menga1bb6272018-09-06 09:59:22 -07001887 private void notifyRequester(MainThreadRequest request) {
1888 synchronized (request) {
1889 request.notifyAll();
1890 }
1891 }
1892
Jake Hambye994d462014-02-03 13:10:13 -08001893 private void handleNullReturnEvent(Message msg, String command) {
1894 AsyncResult ar = (AsyncResult) msg.obj;
1895 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1896 if (ar.exception == null) {
1897 request.result = true;
1898 } else {
1899 request.result = false;
1900 if (ar.exception instanceof CommandException) {
1901 loge(command + ": CommandException: " + ar.exception);
1902 } else {
1903 loge(command + ": Unknown exception");
1904 }
1905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001906 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 /**
1911 * Posts the specified command to be executed on the main thread,
1912 * waits for the request to complete, and returns the result.
1913 * @see #sendRequestAsync
1914 */
1915 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001916 return sendRequest(
1917 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001918 }
1919
1920 /**
1921 * Posts the specified command to be executed on the main thread,
1922 * waits for the request to complete, and returns the result.
1923 * @see #sendRequestAsync
1924 */
1925 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1926 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001927 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001928 }
1929
1930 /**
1931 * Posts the specified command to be executed on the main thread,
1932 * waits for the request to complete, and returns the result.
1933 * @see #sendRequestAsync
1934 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001935 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001936 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001937 }
1938
1939 /**
1940 * Posts the specified command to be executed on the main thread,
1941 * waits for the request to complete, and returns the result.
1942 * @see #sendRequestAsync
1943 */
Nathan Harold92bed182018-10-12 18:16:49 -07001944 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1945 return sendRequest(command, argument, subId, null, workSource);
1946 }
1947
1948 /**
1949 * Posts the specified command to be executed on the main thread,
1950 * waits for the request to complete, and returns the result.
1951 * @see #sendRequestAsync
1952 */
1953 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1954 return sendRequest(
1955 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1956 }
1957
1958 /**
1959 * Posts the specified command to be executed on the main thread,
1960 * waits for the request to complete, and returns the result.
1961 * @see #sendRequestAsync
1962 */
1963 private Object sendRequest(
1964 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1966 throw new RuntimeException("This method will deadlock if called from the main thread.");
1967 }
1968
Nathan Harold92bed182018-10-12 18:16:49 -07001969 MainThreadRequest request = null;
1970 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1971 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1972 } else if (phone != null) {
1973 request = new MainThreadRequest(argument, phone, workSource);
1974 } else {
1975 request = new MainThreadRequest(argument, subId, workSource);
1976 }
1977
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 Message msg = mMainThreadHandler.obtainMessage(command, request);
1979 msg.sendToTarget();
1980
1981 // Wait for the request to complete
1982 synchronized (request) {
1983 while (request.result == null) {
1984 try {
1985 request.wait();
1986 } catch (InterruptedException e) {
1987 // Do nothing, go back and wait until the request is complete
1988 }
1989 }
1990 }
1991 return request.result;
1992 }
1993
1994 /**
1995 * Asynchronous ("fire and forget") version of sendRequest():
1996 * Posts the specified command to be executed on the main thread, and
1997 * returns immediately.
1998 * @see #sendRequest
1999 */
2000 private void sendRequestAsync(int command) {
2001 mMainThreadHandler.sendEmptyMessage(command);
2002 }
2003
2004 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002005 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002006 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002007 */
2008 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002009 sendRequestAsync(command, argument, null, null);
2010 }
2011
2012 /**
2013 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2014 * @see {@link #sendRequest(int,Object)}
2015 */
2016 private void sendRequestAsync(
2017 int command, Object argument, Phone phone, WorkSource workSource) {
2018 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002019 Message msg = mMainThreadHandler.obtainMessage(command, request);
2020 msg.sendToTarget();
2021 }
2022
2023 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002024 * Initialize the singleton PhoneInterfaceManager instance.
2025 * This is only done once, at startup, from PhoneApp.onCreate().
2026 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002027 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 synchronized (PhoneInterfaceManager.class) {
2029 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002030 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 } else {
2032 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2033 }
2034 return sInstance;
2035 }
2036 }
2037
2038 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002039 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002042 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002043 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2045 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002046 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002047 mTelephonySharedPreferences =
2048 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002049 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002050 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002051 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 publish();
2054 }
2055
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002056 private Phone getDefaultPhone() {
2057 Phone thePhone = getPhone(getDefaultSubscription());
2058 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2059 }
2060
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 private void publish() {
2062 if (DBG) log("publish: " + this);
2063
Peter Wangc035ce42020-01-08 21:00:22 -08002064 TelephonyFrameworkInitializer
2065 .getTelephonyServiceManager()
2066 .getTelephonyServiceRegisterer()
2067 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 }
2069
Stuart Scott584921c2015-01-15 17:10:34 -08002070 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002071 if (request.phone != null) {
2072 return request.phone;
2073 } else {
2074 return getPhoneFromSubId(request.subId);
2075 }
2076 }
2077
2078 private Phone getPhoneFromSubId(int subId) {
2079 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2080 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002081 }
2082
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002083 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2084 Phone phone = getPhoneFromRequest(request);
2085 return phone == null ? null :
2086 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2087 }
2088
Wink Saville36469e72014-06-11 15:17:00 -07002089 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002090 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002091 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093
Naina Nallurid63128d2019-09-17 14:10:30 -07002094 private void sendEraseModemConfig(Phone phone) {
2095 if (phone != null) {
2096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2097 mApp, phone.getSubId(), "eraseModemConfig");
2098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2101 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2102 } finally {
2103 Binder.restoreCallingIdentity(identity);
2104 }
2105 }
2106 }
2107
Peter Wang44b186e2020-01-13 23:33:09 -08002108 private boolean isImsAvailableOnDevice() {
2109 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2110 if (pm == null) {
2111 // For some reason package manger is not available.. This will fail internally anyway,
2112 // so do not throw error and allow.
2113 return true;
2114 }
2115 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2116 }
2117
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002119 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002120 }
2121
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 if (DBG) log("dial: " + number);
2124 // No permission check needed here: This is just a wrapper around the
2125 // ACTION_DIAL intent, which is available to any app since it puts up
2126 // the UI before it does anything.
2127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002128 final long identity = Binder.clearCallingIdentity();
2129 try {
2130 String url = createTelUrl(number);
2131 if (url == null) {
2132 return;
2133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002135 // PENDING: should we just silently fail if phone is offhook or ringing?
2136 PhoneConstants.State state = mCM.getState(subId);
2137 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2138 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2139 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2140 mApp.startActivity(intent);
2141 }
2142 } finally {
2143 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145 }
2146
2147 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002148 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002149 }
2150
Wink Savilleb564aae2014-10-23 10:18:09 -07002151 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 if (DBG) log("call: " + number);
2153
2154 // This is just a wrapper around the ACTION_CALL intent, but we still
2155 // need to do a permission check since we're calling startActivity()
2156 // from the context of the phone app.
2157 enforceCallPermission();
2158
Jordan Liu1617b712019-07-10 15:06:26 -07002159 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 != AppOpsManager.MODE_ALLOWED) {
2161 return;
2162 }
2163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 String url = createTelUrl(number);
2167 if (url == null) {
2168 return;
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 boolean isValid = false;
2172 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2173 if (slist != null) {
2174 for (SubscriptionInfo subInfoRecord : slist) {
2175 if (subInfoRecord.getSubscriptionId() == subId) {
2176 isValid = true;
2177 break;
2178 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002179 }
Wink Saville08874612014-08-31 19:19:58 -07002180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181 if (!isValid) {
2182 return;
2183 }
Wink Saville08874612014-08-31 19:19:58 -07002184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2186 intent.putExtra(SUBSCRIPTION_KEY, subId);
2187 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2188 mApp.startActivity(intent);
2189 } finally {
2190 Binder.restoreCallingIdentity(identity);
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002195 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002196 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2197 }
2198
Wink Savilleb564aae2014-10-23 10:18:09 -07002199 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002200 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002201 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2202 }
2203
Wink Savilleb564aae2014-10-23 10:18:09 -07002204 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206
2207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2210 checkSimPin.start();
2211 return checkSimPin.unlockSim(null, pin);
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
2214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Wink Savilleb564aae2014-10-23 10:18:09 -07002217 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219
2220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2223 checkSimPuk.start();
2224 return checkSimPuk.unlockSim(puk, pin);
2225 } finally {
2226 Binder.restoreCallingIdentity(identity);
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
2230 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002231 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 * a synchronous one.
2233 */
2234 private static class UnlockSim extends Thread {
2235
2236 private final IccCard mSimCard;
2237
2238 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002239 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2240 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241
2242 // For replies from SimCard interface
2243 private Handler mHandler;
2244
2245 // For async handler to identify request type
2246 private static final int SUPPLY_PIN_COMPLETE = 100;
2247
2248 public UnlockSim(IccCard simCard) {
2249 mSimCard = simCard;
2250 }
2251
2252 @Override
2253 public void run() {
2254 Looper.prepare();
2255 synchronized (UnlockSim.this) {
2256 mHandler = new Handler() {
2257 @Override
2258 public void handleMessage(Message msg) {
2259 AsyncResult ar = (AsyncResult) msg.obj;
2260 switch (msg.what) {
2261 case SUPPLY_PIN_COMPLETE:
2262 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2263 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002264 mRetryCount = msg.arg1;
2265 if (ar.exception != null) {
2266 if (ar.exception instanceof CommandException &&
2267 ((CommandException)(ar.exception)).getCommandError()
2268 == CommandException.Error.PASSWORD_INCORRECT) {
2269 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002270 } //When UiccCardApp dispose,handle message and return exception
2271 else if (ar.exception instanceof CommandException &&
2272 ((CommandException) (ar.exception)).getCommandError()
2273 == CommandException.Error.ABORTED) {
2274 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002275 } else {
2276 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2277 }
2278 } else {
2279 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 mDone = true;
2282 UnlockSim.this.notifyAll();
2283 }
2284 break;
2285 }
2286 }
2287 };
2288 UnlockSim.this.notifyAll();
2289 }
2290 Looper.loop();
2291 }
2292
2293 /*
2294 * Use PIN or PUK to unlock SIM card
2295 *
2296 * If PUK is null, unlock SIM card with PIN
2297 *
2298 * If PUK is not null, unlock SIM card with PUK and set PIN code
2299 */
Wink Saville9de0f752013-10-22 19:04:03 -07002300 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301
2302 while (mHandler == null) {
2303 try {
2304 wait();
2305 } catch (InterruptedException e) {
2306 Thread.currentThread().interrupt();
2307 }
2308 }
2309 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2310
2311 if (puk == null) {
2312 mSimCard.supplyPin(pin, callback);
2313 } else {
2314 mSimCard.supplyPuk(puk, pin, callback);
2315 }
2316
2317 while (!mDone) {
2318 try {
2319 Log.d(LOG_TAG, "wait for done");
2320 wait();
2321 } catch (InterruptedException e) {
2322 // Restore the interrupted status
2323 Thread.currentThread().interrupt();
2324 }
2325 }
2326 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002327 int[] resultArray = new int[2];
2328 resultArray[0] = mResult;
2329 resultArray[1] = mRetryCount;
2330 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332 }
2333
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002334 /**
2335 * This method has been removed due to privacy and stability concerns.
2336 */
2337 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002339 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2340 return;
Wink Saville36469e72014-06-11 15:17:00 -07002341 }
2342
Nathan Harold1f889d82020-06-04 17:05:26 -07002343 @Override
2344 public void updateServiceLocationWithPackageName(String callingPackage) {
2345 mApp.getSystemService(AppOpsManager.class)
2346 .checkPackage(Binder.getCallingUid(), callingPackage);
2347
Nathan Haroldf096d982020-11-18 17:18:06 -08002348 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002349 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2350 // Callers targeting S have no business invoking this method.
2351 return;
2352 }
2353
2354 LocationAccessPolicy.LocationPermissionResult locationResult =
2355 LocationAccessPolicy.checkLocationPermission(mApp,
2356 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2357 .setCallingPackage(callingPackage)
2358 .setCallingFeatureId(null)
2359 .setCallingPid(Binder.getCallingPid())
2360 .setCallingUid(Binder.getCallingUid())
2361 .setMethod("updateServiceLocation")
2362 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2363 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2364 .build());
2365 // Apps that lack location permission have no business calling this method;
2366 // however, because no permission was declared in the public API, denials must
2367 // all be "soft".
2368 switch (locationResult) {
2369 case DENIED_HARD: /* fall through */
2370 case DENIED_SOFT:
2371 return;
2372 }
2373
2374 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375 final long identity = Binder.clearCallingIdentity();
2376 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002377 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002379 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380 }
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 }
2385
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002386 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002387 @Override
2388 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002389 return isRadioOnWithFeature(callingPackage, null);
2390 }
2391
2392
2393 @Override
2394 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2395 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2396 callingFeatureId);
2397 }
2398
2399 @Deprecated
2400 @Override
2401 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2402 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002403 }
2404
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002406 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2407 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002409 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002410 return false;
2411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 return isRadioOnForSubscriber(subId);
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
2418 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002419 }
2420
2421 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 final Phone phone = getPhone(subId);
2425 if (phone != null) {
2426 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2427 } else {
2428 return false;
2429 }
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 }
2434
2435 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002436 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
Wink Saville36469e72014-06-11 15:17:00 -07002438
Wink Savilleb564aae2014-10-23 10:18:09 -07002439 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 final Phone phone = getPhone(subId);
2445 if (phone != null) {
2446 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2447 }
2448 } finally {
2449 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 }
Wink Saville36469e72014-06-11 15:17:00 -07002451 }
2452
2453 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002454 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002455 }
2456
Wink Savilleb564aae2014-10-23 10:18:09 -07002457 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002458 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459
2460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 final Phone phone = getPhone(subId);
2463 if (phone == null) {
2464 return false;
2465 }
2466 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2467 toggleRadioOnOffForSubscriber(subId);
2468 }
2469 return true;
2470 } finally {
2471 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 }
Wink Saville36469e72014-06-11 15:17:00 -07002474
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002475 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002476 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002477 /*
2478 * If any of the Radios are available, it will need to be
2479 * shutdown. So return true if any Radio is available.
2480 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2484 Phone phone = PhoneFactory.getPhone(i);
2485 if (phone != null && phone.isRadioAvailable()) return true;
2486 }
2487 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2488 return false;
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002491 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002492 }
2493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002495 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 enforceModifyPermission();
2497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2501 logv("Shutting down Phone " + i);
2502 shutdownRadioUsingPhoneId(i);
2503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002506 }
2507 }
2508
2509 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002510 Phone phone = PhoneFactory.getPhone(phoneId);
2511 if (phone != null && phone.isRadioAvailable()) {
2512 phone.shutdownRadio();
2513 }
2514 }
2515
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2522 if (defaultPhone != null) {
2523 defaultPhone.setRadioPower(turnOn);
2524 return true;
2525 } else {
2526 loge("There's no default phone.");
2527 return false;
2528 }
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002531 }
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
2533
Wink Savilleb564aae2014-10-23 10:18:09 -07002534 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 phone.setRadioPower(turnOn);
2542 return true;
2543 } else {
2544 return false;
2545 }
2546 } finally {
2547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 }
2550
Wink Saville36469e72014-06-11 15:17:00 -07002551 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 public boolean enableDataConnectivity() {
2554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 int subId = mSubscriptionController.getDefaultDataSubId();
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002561 phone.getDataEnabledSettings().setDataEnabled(
2562 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 return true;
2564 } else {
2565 return false;
2566 }
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
2571
Wink Saville36469e72014-06-11 15:17:00 -07002572 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 public boolean disableDataConnectivity() {
2575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 int subId = mSubscriptionController.getDefaultDataSubId();
2580 final Phone phone = getPhone(subId);
2581 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002582 phone.getDataEnabledSettings().setDataEnabled(
2583 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584 return true;
2585 } else {
2586 return false;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 }
2592
Sanket Padawe356d7632015-06-22 14:03:32 -07002593 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002594 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
2598 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002599 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 } else {
2601 return false;
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
2608 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002609 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002610 }
2611
pkanwarae03a6b2016-11-06 20:37:09 -08002612 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 enforceCallPermission();
2614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2618 return;
2619 }
2620 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2621 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
pkanwar32d516d2016-10-14 19:37:38 -07002625 };
2626
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2633 return false;
2634 }
2635 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002642 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002643 }
2644
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002645 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 Phone phone = PhoneFactory.getPhone(slotIndex);
2649 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2650 PhoneConstantConversions.convertCallState(phone.getState());
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
Sanket Padawe356d7632015-06-22 14:03:32 -07002656 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002657 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002658 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2659 }
2660
2661 @Override
2662 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002665 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 if (phone != null) {
2667 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2668 } else {
2669 return PhoneConstantConversions.convertDataState(
2670 PhoneConstants.DataState.DISCONNECTED);
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002678 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002679 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2680 }
2681
2682 @Override
2683 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 final long identity = Binder.clearCallingIdentity();
2685 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002686 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 if (phone != null) {
2688 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2689 } else {
2690 return TelephonyManager.DATA_ACTIVITY_NONE;
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
2697 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002698 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002699 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002700 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002701
2702 LocationAccessPolicy.LocationPermissionResult locationResult =
2703 LocationAccessPolicy.checkLocationPermission(mApp,
2704 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2705 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002706 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002707 .setCallingPid(Binder.getCallingPid())
2708 .setCallingUid(Binder.getCallingUid())
2709 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002710 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002711 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2712 .build());
2713 switch (locationResult) {
2714 case DENIED_HARD:
2715 throw new SecurityException("Not allowed to access cell location");
2716 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002717 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2718 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 }
2720
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002725 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002726 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Svetoslav64fad262015-04-14 14:35:21 -07002730 }
2731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002733 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002734 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2735 // registered cell info, so return a NULL country instead.
2736 final long identity = Binder.clearCallingIdentity();
2737 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002738 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2739 // Get default phone in this case.
2740 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2741 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002742 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002744 if (phone == null) return "";
2745 ServiceStateTracker sst = phone.getServiceStateTracker();
2746 if (sst == null) return "";
2747 LocaleTracker lt = sst.getLocaleTracker();
2748 if (lt == null) return "";
2749 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2750 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2751 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002755 }
2756
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002757 /**
2758 * This method was removed due to potential issues caused by performing partial
2759 * updates of service state, and lack of a credible use case.
2760 *
2761 * This has the ability to break the telephony implementation by disabling notification of
2762 * changes in device connectivity. DO NOT USE THIS!
2763 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002764 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 public void enableLocationUpdates() {
2766 mApp.enforceCallingOrSelfPermission(
2767 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002770 /**
2771 * This method was removed due to potential issues caused by performing partial
2772 * updates of service state, and lack of a credible use case.
2773 *
2774 * This has the ability to break the telephony implementation by disabling notification of
2775 * changes in device connectivity. DO NOT USE THIS!
2776 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 @Override
2778 public void disableLocationUpdates() {
2779 mApp.enforceCallingOrSelfPermission(
2780 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
2782
2783 @Override
2784 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002785 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2786 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002787 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002788 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2789 throw new SecurityException(
2790 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2791 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002792
Jordan Liu1617b712019-07-10 15:06:26 -07002793 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2795 return null;
2796 }
Svetoslav64fad262015-04-14 14:35:21 -07002797
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002798 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002800 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002801 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802
Nathan Haroldf180aac2018-06-01 18:43:55 -07002803 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2804 for (CellInfo ci : info) {
2805 if (ci instanceof CellInfoGsm) {
2806 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2807 } else if (ci instanceof CellInfoWcdma) {
2808 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002811 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002814 private List<CellInfo> getCachedCellInfo() {
2815 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2816 for (Phone phone : PhoneFactory.getPhones()) {
2817 List<CellInfo> info = phone.getAllCellInfo();
2818 if (info != null) cellInfos.addAll(info);
2819 }
2820 return cellInfos;
2821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822
2823 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002824 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002826 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002827
2828 LocationAccessPolicy.LocationPermissionResult locationResult =
2829 LocationAccessPolicy.checkLocationPermission(mApp,
2830 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2831 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002832 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002833 .setCallingPid(Binder.getCallingPid())
2834 .setCallingUid(Binder.getCallingUid())
2835 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002836 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002837 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2838 .build());
2839 switch (locationResult) {
2840 case DENIED_HARD:
2841 throw new SecurityException("Not allowed to access cell info");
2842 case DENIED_SOFT:
2843 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
Nathan Haroldf096d982020-11-18 17:18:06 -08002846 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002847 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2848 return getCachedCellInfo();
2849 }
2850
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002851 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002852 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2856 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002857 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002858 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 if (info != null) cellInfos.addAll(info);
2860 }
2861 return cellInfos;
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865 }
2866
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002867 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002868 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2869 String callingFeatureId) {
2870 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2871 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002872 }
2873
2874 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002875 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2876 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002877 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002878 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002879 }
2880
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002881 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2882 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002883 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002884 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002885
2886 LocationAccessPolicy.LocationPermissionResult locationResult =
2887 LocationAccessPolicy.checkLocationPermission(mApp,
2888 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2889 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002890 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002891 .setCallingPid(Binder.getCallingPid())
2892 .setCallingUid(Binder.getCallingUid())
2893 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002894 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2895 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002896 .build());
2897 switch (locationResult) {
2898 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002899 if (TelephonyPermissions
2900 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002901 // Safetynet logging for b/154934934
2902 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2903 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002904 throw new SecurityException("Not allowed to access cell info");
2905 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002906 if (TelephonyPermissions
2907 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002908 // Safetynet logging for b/154934934
2909 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2910 }
Nathan Harold5320c422019-05-09 10:26:08 -07002911 try {
2912 cb.onCellInfo(new ArrayList<CellInfo>());
2913 } catch (RemoteException re) {
2914 // Drop without consequences
2915 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002916 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002917 }
2918
Nathan Harolda939a962019-05-09 10:13:47 -07002919
2920 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002921 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2922
2923 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2924 }
2925
2926 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002928 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 } finally {
2935 Binder.restoreCallingIdentity(identity);
2936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
2938
Shishir Agrawala9f32182016-04-12 12:00:16 -07002939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002940 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002941 Phone phone = PhoneFactory.getPhone(slotIndex);
2942 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002943 return null;
2944 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002945 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002946 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002947 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002948 return null;
2949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 return phone.getImei();
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002957 }
2958
2959 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002960 public String getTypeAllocationCodeForSlot(int slotIndex) {
2961 Phone phone = PhoneFactory.getPhone(slotIndex);
2962 String tac = null;
2963 if (phone != null) {
2964 String imei = phone.getImei();
2965 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2966 }
2967 return tac;
2968 }
2969
2970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002971 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002972 Phone phone = PhoneFactory.getPhone(slotIndex);
2973 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002974 return null;
2975 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002976
Jeff Davidson913390f2018-02-23 17:11:49 -08002977 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002978 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002979 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002980 return null;
2981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 return phone.getMeid();
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Jack Yu2af8d712017-03-15 17:14:14 -07002989 }
2990
2991 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002992 public String getManufacturerCodeForSlot(int slotIndex) {
2993 Phone phone = PhoneFactory.getPhone(slotIndex);
2994 String manufacturerCode = null;
2995 if (phone != null) {
2996 String meid = phone.getMeid();
2997 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2998 }
2999 return manufacturerCode;
3000 }
3001
3002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003003 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3004 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003005 Phone phone = PhoneFactory.getPhone(slotIndex);
3006 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003007 return null;
3008 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003009 int subId = phone.getSubId();
3010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003011 mApp, subId, callingPackage, callingFeatureId,
3012 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003013 return null;
3014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 return phone.getDeviceSvn();
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003022 }
3023
fionaxu43304da2017-11-27 22:51:16 -08003024 @Override
3025 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 final Phone phone = getPhone(subId);
3029 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
fionaxu43304da2017-11-27 22:51:16 -08003033 }
3034
3035 @Override
3036 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 final Phone phone = getPhone(subId);
3040 return phone == null ? null : phone.getCarrierName();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
fionaxu43304da2017-11-27 22:51:16 -08003044 }
3045
calvinpanffe225e2018-11-01 19:43:06 +08003046 @Override
chen xu0026ca62019-03-06 15:28:50 -08003047 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone phone = getPhone(subId);
3051 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003052 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
3056 }
3057
3058 @Override
chen xu0026ca62019-03-06 15:28:50 -08003059 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003063 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
3067 }
3068
chen xu651eec72018-11-11 19:03:44 -08003069 @Override
chen xu864e11c2018-12-06 22:10:03 -08003070 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3071 if (!isSubscriptionMccMnc) {
3072 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3073 }
chen xu651eec72018-11-11 19:03:44 -08003074 final Phone phone = PhoneFactory.getPhone(slotIndex);
3075 if (phone == null) {
3076 return TelephonyManager.UNKNOWN_CARRIER_ID;
3077 }
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
3084 }
3085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 //
3087 // Internal helper methods.
3088 //
3089
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003090 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3092 *
3093 * @throws SecurityException if the caller does not have the required permission
3094 */
3095 private void enforceModifyPermission() {
3096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3097 }
3098
Shuo Qiancd19c462020-01-16 20:51:11 -08003099 /**
3100 * Make sure the caller is system.
3101 *
3102 * @throws SecurityException if the caller is not system.
3103 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003104 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003105 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3106 throw new SecurityException("Caller must be system");
3107 }
3108 }
3109
Shuo Qian3b6ee772019-11-13 17:43:31 -08003110 private void enforceActiveEmergencySessionPermission() {
3111 mApp.enforceCallingOrSelfPermission(
3112 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3113 }
3114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 /**
3116 * Make sure the caller has the CALL_PHONE permission.
3117 *
3118 * @throws SecurityException if the caller does not have the required permission
3119 */
3120 private void enforceCallPermission() {
3121 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3122 }
3123
paulhu5a773602019-08-23 19:17:33 +08003124 private void enforceSettingsPermission() {
3125 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003126 }
3127
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 private String createTelUrl(String number) {
3129 if (TextUtils.isEmpty(number)) {
3130 return null;
3131 }
3132
Jake Hambye994d462014-02-03 13:10:13 -08003133 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003134 }
3135
Ihab Awadf9e92732013-12-05 18:02:52 -08003136 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3138 }
3139
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003140 private static void logv(String msg) {
3141 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3142 }
3143
Ihab Awadf9e92732013-12-05 18:02:52 -08003144 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3146 }
3147
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003148 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003150 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003151 }
3152
Sanket Padawe356d7632015-06-22 14:03:32 -07003153 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003154 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 final Phone phone = PhoneFactory.getPhone(slotIndex);
3158 if (phone == null) {
3159 return PhoneConstants.PHONE_TYPE_NONE;
3160 } else {
3161 return phone.getPhoneType();
3162 }
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 }
3167
3168 /**
3169 * Returns the CDMA ERI icon index to display
3170 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003172 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3173 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3174 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003175 }
3176
Sanket Padawe356d7632015-06-22 14:03:32 -07003177 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003178 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3179 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003181 mApp, subId, callingPackage, callingFeatureId,
3182 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003183 return -1;
3184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final Phone phone = getPhone(subId);
3189 if (phone != null) {
3190 return phone.getCdmaEriIconIndex();
3191 } else {
3192 return -1;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
3199 /**
3200 * Returns the CDMA ERI icon mode,
3201 * 0 - ON
3202 * 1 - FLASHING
3203 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003205 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3206 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3207 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003208 }
3209
Sanket Padawe356d7632015-06-22 14:03:32 -07003210 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003211 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3212 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003214 mApp, subId, callingPackage, callingFeatureId,
3215 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 return -1;
3217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218
3219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 final Phone phone = getPhone(subId);
3222 if (phone != null) {
3223 return phone.getCdmaEriIconMode();
3224 } else {
3225 return -1;
3226 }
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003230 }
3231
3232 /**
3233 * Returns the CDMA ERI text,
3234 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003236 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3237 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3238 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003239 }
3240
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003242 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3243 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003245 mApp, subId, callingPackage, callingFeatureId,
3246 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003247 return null;
3248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249
3250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 final Phone phone = getPhone(subId);
3253 if (phone != null) {
3254 return phone.getCdmaEriText();
3255 } else {
3256 return null;
3257 }
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
3263 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003264 * Returns the CDMA MDN.
3265 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003267 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3269 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 return phone.getLine1Number();
3276 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 return null;
3279 }
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003282 }
3283 }
3284
3285 /**
3286 * Returns the CDMA MIN.
3287 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003288 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003289 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 final Phone phone = getPhone(subId);
3296 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3297 return phone.getCdmaMin();
3298 } else {
3299 return null;
3300 }
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003303 }
3304 }
3305
Hall Liud892bec2018-11-30 14:51:45 -08003306 @Override
3307 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3308 INumberVerificationCallback callback, String callingPackage) {
3309 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3310 != PERMISSION_GRANTED) {
3311 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3312 }
3313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3314
3315 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3316 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003317 throw new SecurityException("Calling package must be configured in the device config: "
3318 + "calling package: " + callingPackage
3319 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003320 }
3321
3322 if (range == null) {
3323 throw new NullPointerException("Range must be non-null");
3324 }
3325
3326 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003327 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003328
3329 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3330 }
3331
Junda Liuca05d5d2014-08-14 22:36:34 -07003332 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 * Returns true if CDMA provisioning needs to run.
3334 */
3335 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 final long identity = Binder.clearCallingIdentity();
3337 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003338 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 }
3343
3344 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003345 * Sets the voice mail number of a given subId.
3346 */
3347 @Override
3348 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003349 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3350 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3355 new Pair<String, String>(alphaTag, number), new Integer(subId));
3356 return success;
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003360 }
3361
Ta-wei Yen87c49842016-05-13 21:19:52 -07003362 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003363 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003365 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3366 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003367 if (!TextUtils.equals(callingPackage, systemDialer)) {
3368 throw new SecurityException("caller must be system dialer");
3369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370
3371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3374 if (phoneAccountHandle == null) {
3375 return null;
3376 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 } finally {
3379 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003380 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003381 }
3382
3383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003384 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3385 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003388 mApp, subId, callingPackage, callingFeatureId,
3389 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003390 return null;
3391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003393 final long identity = Binder.clearCallingIdentity();
3394 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003399 }
3400
3401 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003402 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3403 VisualVoicemailSmsFilterSettings settings) {
3404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003413 }
3414
3415 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003416 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003422 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003426 }
3427
3428 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003429 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3430 String callingPackage, int subId) {
3431 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003436 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003440 }
3441
3442 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003443 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003449 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003453 }
3454
3455 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003456 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3457 String callingAttributionTag, int subId, String number, int port, String text,
3458 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003460 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003461 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003462 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003463 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3464 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003465 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003466
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003467 /**
fionaxu0152e512016-11-14 13:36:14 -08003468 * Sets the voice activation state of a given subId.
3469 */
3470 @Override
3471 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3473 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 final Phone phone = getPhone(subId);
3478 if (phone != null) {
3479 phone.setVoiceActivationState(activationState);
3480 } else {
3481 loge("setVoiceActivationState fails with invalid subId: " + subId);
3482 }
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003485 }
3486 }
3487
3488 /**
3489 * Sets the data activation state of a given subId.
3490 */
3491 @Override
3492 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3494 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 final Phone phone = getPhone(subId);
3499 if (phone != null) {
3500 phone.setDataActivationState(activationState);
3501 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003502 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003506 }
3507 }
3508
3509 /**
3510 * Returns the voice activation state of a given subId.
3511 */
3512 @Override
3513 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
fionaxu0152e512016-11-14 13:36:14 -08003516 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 if (phone != null) {
3520 return phone.getVoiceActivationState();
3521 } else {
3522 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003526 }
3527 }
3528
3529 /**
3530 * Returns the data activation state of a given subId.
3531 */
3532 @Override
3533 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
fionaxu0152e512016-11-14 13:36:14 -08003536 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 if (phone != null) {
3540 return phone.getDataActivationState();
3541 } else {
3542 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003546 }
3547 }
3548
3549 /**
Wink Saville36469e72014-06-11 15:17:00 -07003550 * Returns the unread count of voicemails for a subId
3551 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3554 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 mApp, subId, callingPackage, callingFeatureId,
3557 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003558 return 0;
3559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 if (phone != null) {
3564 return phone.getVoiceMessageCount();
3565 } else {
3566 return 0;
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 }
3572
3573 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003574 * returns true, if the device is in a state where both voice and data
3575 * are supported simultaneously. This can change based on location or network condition.
3576 */
3577 @Override
3578 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003586 }
3587
3588 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003589 * Send the dialer code if called from the current default dialer or the caller has
3590 * carrier privilege.
3591 * @param inputCode The dialer code to send
3592 */
3593 @Override
3594 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003596 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003597 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3598 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003599 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003600 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003601 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
fionaxu235cc5e2017-03-06 22:25:57 -08003610 }
3611
Pengquan Menga1bb6272018-09-06 09:59:22 -07003612 @Override
3613 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003614 TelephonyPermissions
3615 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3616 mApp, subId, "getNetworkSelectionMode");
3617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 if (!isActiveSubscription(subId)) {
3620 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3621 }
3622 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3623 } finally {
3624 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003626 }
3627
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003629 public boolean isInEmergencySmsMode() {
3630 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 for (Phone phone : PhoneFactory.getPhones()) {
3634 if (phone.isInEmergencySmsMode()) {
3635 return true;
3636 }
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
3641 return false;
3642 }
3643
shilu366312e2019-12-17 09:28:10 -08003644 /**
3645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3646 * @param subId The subscription to use to check the configuration.
3647 * @param c The callback that will be used to send the result.
3648 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003649 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003650 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3651 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003652 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3653 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003654
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003655 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3656 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3657 "IMS not available on device.");
3658 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 final long token = Binder.clearCallingIdentity();
3660 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (ImsException e) {
3665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 } finally {
3667 Binder.restoreCallingIdentity(token);
3668 }
3669 }
3670
shilu366312e2019-12-17 09:28:10 -08003671 /**
3672 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3673 * @param subId The subscription to use to check the configuration.
3674 * @param c The callback that will be used to send the result.
3675 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003677 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003678 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3679 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3681 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3682 }
Meng Wangafbc5852019-09-19 17:37:13 -07003683 final long token = Binder.clearCallingIdentity();
3684 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003685 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003686 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3687 .removeRegistrationCallbackForSubscription(c, subId);
3688 } catch (ImsException e) {
3689 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3690 + "is inactive, ignoring unregister.");
3691 // If the subscription is no longer active, just return, since the callback
3692 // will already have been removed internally.
3693 } finally {
3694 Binder.restoreCallingIdentity(token);
3695 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 }
3697
Brad Ebingera34a6c22019-10-22 17:36:18 -07003698 /**
3699 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3700 */
3701 @Override
3702 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3703 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3704 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3706 "IMS not available on device.");
3707 }
3708 final long token = Binder.clearCallingIdentity();
3709 try {
3710 Phone phone = getPhone(subId);
3711 if (phone == null) {
3712 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3713 + subId + "'");
3714 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3715 }
3716 phone.getImsRegistrationState(regState -> {
3717 try {
3718 consumer.accept((regState == null)
3719 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3720 } catch (RemoteException e) {
3721 // Ignore if the remote process is no longer available to call back.
3722 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3723 }
3724 });
3725 } finally {
3726 Binder.restoreCallingIdentity(token);
3727 }
3728 }
3729
3730 /**
3731 * Get the transport type for the IMS service registration state.
3732 */
3733 @Override
3734 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003735 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3736 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003737 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3739 "IMS not available on device.");
3740 }
3741 final long token = Binder.clearCallingIdentity();
3742 try {
3743 Phone phone = getPhone(subId);
3744 if (phone == null) {
3745 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3746 + subId + "'");
3747 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3748 }
3749 phone.getImsRegistrationTech(regTech -> {
3750 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3751 int regTechConverted = (regTech == null)
3752 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3753 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3754 regTechConverted);
3755 try {
3756 consumer.accept(regTechConverted);
3757 } catch (RemoteException e) {
3758 // Ignore if the remote process is no longer available to call back.
3759 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3760 }
3761 });
3762 } finally {
3763 Binder.restoreCallingIdentity(token);
3764 }
3765 }
3766
shilu366312e2019-12-17 09:28:10 -08003767 /**
3768 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3769 * @param subId The subscription to use to check the configuration.
3770 * @param c The callback that will be used to send the result.
3771 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003772 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003773 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3774 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003775 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3776 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003777 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3778 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3779 "IMS not available on device.");
3780 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003781 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3782 final long token = Binder.clearCallingIdentity();
3783 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003784 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003786 } catch (ImsException e) {
3787 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 } finally {
3789 Binder.restoreCallingIdentity(token);
3790 }
3791 }
3792
shilu366312e2019-12-17 09:28:10 -08003793 /**
3794 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3795 * @param subId The subscription to use to check the configuration.
3796 * @param c The callback that will be used to send the result.
3797 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003799 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003800 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3801 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003802 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3803 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3804 }
Meng Wangafbc5852019-09-19 17:37:13 -07003805
3806 final long token = Binder.clearCallingIdentity();
3807 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003808 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003809 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003810 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003811 } catch (ImsException e) {
3812 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3813 + "is inactive, ignoring unregister.");
3814 // If the subscription is no longer active, just return, since the callback
3815 // will already have been removed internally.
3816 } finally {
3817 Binder.restoreCallingIdentity(token);
3818 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 }
3820
3821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003822 public boolean isCapable(int subId, int capability, int regTech) {
3823 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3825 final long token = Binder.clearCallingIdentity();
3826 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003827 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003829 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3831 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003832 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003833 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3834 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 } finally {
3836 Binder.restoreCallingIdentity(token);
3837 }
3838 }
3839
3840 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003841 public boolean isAvailable(int subId, int capability, int regTech) {
3842 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 final long token = Binder.clearCallingIdentity();
3844 try {
3845 Phone phone = getPhone(subId);
3846 if (phone == null) return false;
3847 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003848 } catch (com.android.ims.ImsException e) {
3849 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3850 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 } finally {
3852 Binder.restoreCallingIdentity(token);
3853 }
3854 }
3855
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003856 /**
3857 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3858 * subscription.
3859 * @param subId The subscription to use to check the configuration.
3860 * @param callback The callback that will be used to send the result.
3861 * @param capability The MmTelFeature capability that will be used to send the result.
3862 * @param transportType The transport type of the MmTelFeature capability.
3863 */
3864 @Override
3865 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3866 int transportType) {
3867 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3868 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3870 "IMS not available on device.");
3871 }
3872 final long token = Binder.clearCallingIdentity();
3873 try {
3874 int slotId = getSlotIndex(subId);
3875 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3876 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3877 + subId + "'");
3878 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3879 }
3880 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3881 transportType, aBoolean -> {
3882 try {
3883 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3884 } catch (RemoteException e) {
3885 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3886 + "running. Ignore");
3887 }
3888 });
3889 } finally {
3890 Binder.restoreCallingIdentity(token);
3891 }
3892 }
3893
shilu366312e2019-12-17 09:28:10 -08003894 /**
3895 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3896 * @param subId The subscription to use to check the configuration.
3897 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 @Override
3899 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003900 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3901 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003902
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3904 final long token = Binder.clearCallingIdentity();
3905 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003908 } catch (ImsException e) {
3909 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 } finally {
3911 Binder.restoreCallingIdentity(token);
3912 }
3913 }
3914
3915 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003916 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003918 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003924 } catch (ImsException e) {
3925 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 } finally {
3927 Binder.restoreCallingIdentity(identity);
3928 }
3929 }
3930
shilu366312e2019-12-17 09:28:10 -08003931 /**
3932 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3933 * @param subId The subscription to use to check the configuration.
3934 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003936 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003937 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3938 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003942 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3943 } catch (ImsException e) {
3944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
3948 }
3949
3950 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003951 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003953 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003958 } catch (ImsException e) {
3959 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
3963 }
3964
shilu366312e2019-12-17 09:28:10 -08003965 /**
3966 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3967 * @param subId The subscription to use to check the configuration.
3968 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 @Override
3970 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003971 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3972 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
3983 }
3984
3985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003986 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003988 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003992 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999
shilu366312e2019-12-17 09:28:10 -08004000 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004001 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4002 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4003 * @param subId The subscription to use to check the configuration.
4004 */
4005 @Override
4006 public boolean isCrossSimCallingEnabledByUser(int subId) {
4007 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4008 mApp, subId, "isCrossSimCallingEnabledByUser");
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4012 return ImsManager.getInstance(mApp,
4013 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4014 } catch (ImsException e) {
4015 throw new ServiceSpecificException(e.getCode());
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
4019 }
4020
4021 /**
4022 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4023 * Requires MODIFY_PHONE_STATE permission.
4024 * @param subId The subscription to use to check the configuration.
4025 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4026 * false otherwise
4027 */
4028 @Override
4029 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4031 "setCrossSimCallingEnabled");
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4035 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4036 .setCrossSimCallingEnabled(isEnabled);
4037 } catch (ImsException e) {
4038 throw new ServiceSpecificException(e.getCode());
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
4042 }
4043
4044 /**
shilu366312e2019-12-17 09:28:10 -08004045 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4046 * @param subId The subscription to use to check the configuration.
4047 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 @Override
4049 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004050 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4051 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004057 } catch (ImsException e) {
4058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
4062 }
4063
4064 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004065 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004067 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004071 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 } catch (ImsException e) {
4074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
4078 }
4079
4080 @Override
4081 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4083 "setVoWiFiNonPersistent");
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004088 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
shilu366312e2019-12-17 09:28:10 -08004096 /**
4097 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4098 * @param subId The subscription to use to check the configuration.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
4101 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004102 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4103 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004109 } catch (ImsException e) {
4110 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
4114 }
4115
4116 @Override
4117 public void setVoWiFiModeSetting(int subId, int mode) {
4118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4119 "setVoWiFiModeSetting");
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004125 } catch (ImsException e) {
4126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131
4132 @Override
4133 public int getVoWiFiRoamingModeSetting(int subId) {
4134 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (ImsException e) {
4141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
4145 }
4146
4147 @Override
4148 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4150 "setVoWiFiRoamingModeSetting");
4151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (ImsException e) {
4157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4166 "setRttCapabilityEnabled");
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004170 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4171 } catch (ImsException e) {
4172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
4176 }
4177
shilu366312e2019-12-17 09:28:10 -08004178 /**
4179 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4180 * @param subId The subscription to use to check the configuration.
4181 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 @Override
4183 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004184 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4185 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004189 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004191 } catch (ImsException e) {
4192 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 } finally {
4194 Binder.restoreCallingIdentity(identity);
4195 }
4196 }
4197
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004198 @Override
4199 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4200 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4201 final long identity = Binder.clearCallingIdentity();
4202 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004203 if (!isImsAvailableOnDevice()) {
4204 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4205 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004206 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004208 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004209 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
4211 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
4215 }
4216
4217 @Override
4218 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4219 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4220 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004221 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4222 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4223 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004224 try {
4225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004226 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004227 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004228 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004229 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4230 + "is inactive, ignoring unregister.");
4231 // If the subscription is no longer active, just return, since the callback will already
4232 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004233 } finally {
4234 Binder.restoreCallingIdentity(identity);
4235 }
4236 }
4237
allenwtsu99c623b2020-01-03 18:24:23 +08004238
4239 private void checkModifyPhoneStatePermission(int subId, String message) {
4240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4241 message);
4242 }
4243
4244 private boolean isImsProvisioningRequired(int subId, int capability,
4245 boolean isMmtelCapability) {
4246 Phone phone = getPhone(subId);
4247 if (phone == null) {
4248 loge("phone instance null for subid " + subId);
4249 return false;
4250 }
4251 if (isMmtelCapability) {
4252 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4253 return false;
4254 }
4255 } else {
4256 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4257 return false;
4258 }
4259 }
4260 return true;
4261 }
4262
4263 @Override
4264 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4265 boolean isProvisioned) {
4266 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4267
4268 final long identity = Binder.clearCallingIdentity();
4269 try {
4270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4271 if (!isImsProvisioningRequired(subId, capability, false)) {
4272 return;
4273 }
4274
4275 // this capability requires provisioning, route to the correct API.
4276 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4277 switch (capability) {
4278 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4279 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4280 ims.setEabProvisioned(isProvisioned);
4281 break;
4282 default: {
4283 throw new IllegalArgumentException("Tried to set provisioning for "
4284 + "rcs capability '" + capability + "', which does not require "
4285 + "provisioning.");
4286 }
4287 }
4288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
4291
4292 }
4293
4294
4295 @Override
4296 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4297 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4301 if (!isImsProvisioningRequired(subId, capability, false)) {
4302 return true;
4303 }
4304
4305 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4306 switch (capability) {
4307 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4308 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4309 return ims.isEabProvisionedOnDevice();
4310
4311 default: {
4312 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4313 + "capability '" + capability + "', which does not require "
4314 + "provisioning.");
4315 }
4316 }
4317
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004323 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004324 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4325 boolean isProvisioned) {
4326 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4327 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4328 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4329 }
allenwtsu99c623b2020-01-03 18:24:23 +08004330 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004334 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004335 return;
4336 }
4337
4338 // this capability requires provisioning, route to the correct API.
4339 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4340 switch (capability) {
4341 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4342 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4343 ims.setVolteProvisioned(isProvisioned);
4344 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4345 ims.setWfcProvisioned(isProvisioned);
4346 }
4347 break;
4348 }
4349 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4350 // There is currently no difference in VT provisioning type.
4351 ims.setVtProvisioned(isProvisioned);
4352 break;
4353 }
4354 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4355 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4356 // change the capability of the feature instead if needed.
4357 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4358 == isProvisioned) {
4359 // No change in provisioning.
4360 return;
4361 }
4362 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4363 try {
4364 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004365 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004366 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4367 + ", Exception" + e.getMessage());
4368 }
4369 break;
4370 }
4371 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004372 throw new IllegalArgumentException("Tried to set provisioning for "
4373 + "MmTel capability '" + capability + "', which does not require "
4374 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004375 }
4376 }
4377
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
4383 @Override
4384 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4385 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4386 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4387 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4388 }
4389 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
4392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004393 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004394 return true;
4395 }
4396
4397 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4398 switch (capability) {
4399 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4400 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4401 return ims.isVolteProvisionedOnDevice();
4402 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4403 return ims.isWfcProvisionedOnDevice();
4404 }
4405 // This should never happen, since we are checking tech above to make sure it
4406 // is either LTE or IWLAN.
4407 throw new IllegalArgumentException("Invalid radio technology for voice "
4408 + "capability.");
4409 }
4410 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4411 // There is currently no difference in VT provisioning type.
4412 return ims.isVtProvisionedOnDevice();
4413 }
4414 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4415 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4416 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4417 }
4418 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004419 throw new IllegalArgumentException(
4420 "Tried to get provisioning for MmTel capability '" + capability
4421 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004422 }
4423 }
4424
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
4428 }
4429
4430 @Override
4431 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4432 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4433 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4434 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4435 }
4436 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4437 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4438 return (provisionedBits & capability) > 0;
4439 }
4440
4441 @Override
4442 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4443 boolean isProvisioned) {
4444 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4445 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4446 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4447 }
4448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4449 "setProvisioningStatusForCapability");
4450 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4451 // If the current provisioning status for capability already matches isProvisioned,
4452 // do nothing.
4453 if (((provisionedBits & capability) > 0) == isProvisioned) {
4454 return;
4455 }
4456 if (isProvisioned) {
4457 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4458 } else {
4459 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4460 }
4461 }
4462
4463 /**
4464 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4465 * technology. The bitfield should mirror the bitfield defined by
4466 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4467 */
4468 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4469 String key = getMmTelProvisioningKey(subId, tech);
4470 // Default is no capabilities are provisioned.
4471 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4472 }
4473
4474 /**
4475 * Sets the MmTel capability provisioning bitfield (defined by
4476 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4477 * technology specified.
4478 *
4479 * Note: This is a synchronous command and should not be called on UI thread.
4480 */
4481 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4482 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4483 String key = getMmTelProvisioningKey(subId, tech);
4484 editor.putInt(key, newField);
4485 editor.commit();
4486 }
4487
4488 private static String getMmTelProvisioningKey(int subId, int tech) {
4489 // resulting key is provision_ims_mmtel_{subId}_{tech}
4490 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4491 }
4492
4493 /**
4494 * Query CarrierConfig to see if the specified capability requires provisioning for the
4495 * carrier associated with the subscription id.
4496 */
4497 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4498 int capability) {
4499 CarrierConfigManager configManager = new CarrierConfigManager(context);
4500 PersistableBundle c = configManager.getConfigForSubId(subId);
4501 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004502 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004503 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4504 false);
4505 boolean requireVoiceVtProvisioning = c.getBoolean(
4506 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4507
4508 // First check to make sure that the capability requires provisioning.
4509 switch (capability) {
4510 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4511 // intentional fallthrough
4512 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4513 if (requireVoiceVtProvisioning) {
4514 // Voice and Video requires provisioning
4515 return true;
4516 }
4517 break;
4518 }
4519 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4520 if (requireUtProvisioning) {
4521 // UT requires provisioning
4522 return true;
4523 }
4524 break;
4525 }
4526 }
4527 return false;
4528 }
4529
allenwtsu99c623b2020-01-03 18:24:23 +08004530 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4531 int capability) {
4532 CarrierConfigManager configManager = new CarrierConfigManager(context);
4533 PersistableBundle c = configManager.getConfigForSubId(subId);
4534
4535 boolean requireRcsProvisioning = c.getBoolean(
4536 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4537
4538 // First check to make sure that the capability requires provisioning.
4539 switch (capability) {
4540 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4541 // intentional fallthrough
4542 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4543 if (requireRcsProvisioning) {
4544 // OPTION or PRESENCE requires provisioning
4545 return true;
4546 }
4547 break;
4548 }
4549 }
4550 return false;
4551 }
4552
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004553 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004554 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4556 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4557 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004558 enforceReadPrivilegedPermission("getImsProvisioningInt");
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
4561 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562 int slotId = getSlotIndex(subId);
4563 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4564 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4565 + subId + "' for key:" + key);
4566 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4567 }
4568 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004569 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004570 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4571 + subId + "' for key:" + key);
4572 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
4576 }
4577
4578 @Override
4579 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4581 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4582 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004583 enforceReadPrivilegedPermission("getImsProvisioningString");
4584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 int slotId = getSlotIndex(subId);
4588 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4589 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4590 + subId + "' for key:" + key);
4591 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4592 }
4593 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004594 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004595 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4596 + subId + "' for key:" + key);
4597 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601 }
4602
4603 @Override
4604 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4606 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4607 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4609 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004610 final long identity = Binder.clearCallingIdentity();
4611 try {
4612 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004613 int slotId = getSlotIndex(subId);
4614 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4615 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4616 + subId + "' for key:" + key);
4617 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4618 }
4619 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004620 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4622 + "' for key:" + key);
4623 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
4627 }
4628
4629 @Override
4630 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4632 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4633 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4635 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 int slotId = getSlotIndex(subId);
4640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4641 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4642 + subId + "' for key:" + key);
4643 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4644 }
4645 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004646 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4648 + "' for key:" + key);
4649 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004655 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 int slotId = SubscriptionManager.getSlotIndex(subId);
4657 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4659 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 }
4661 return slotId;
4662 }
4663
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 private int getSlotIndex(int subId) {
4665 int slotId = SubscriptionManager.getSlotIndex(subId);
4666 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4667 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4668 }
4669 return slotId;
4670 }
4671
Wink Saville36469e72014-06-11 15:17:00 -07004672 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004673 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004674 */
4675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004676 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4677 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004678 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004679 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004680 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004681 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004682 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004683 mApp, subId, callingPackage, callingFeatureId,
4684 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004685 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4686 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 final Phone phone = getPhone(subId);
4691 if (phone != null) {
4692 return phone.getServiceState().getDataNetworkType();
4693 } else {
4694 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4695 }
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004699 }
4700
4701 /**
4702 * Returns the data network type
4703 */
4704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004705 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4706 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4707 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004708 }
4709
4710 /**
4711 * Returns the data network type for a subId
4712 */
4713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004714 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004717 mApp, subId, callingPackage, callingFeatureId,
4718 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004719 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4720 }
4721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 final Phone phone = getPhone(subId);
4725 if (phone != null) {
4726 return phone.getServiceState().getDataNetworkType();
4727 } else {
4728 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4729 }
4730 } finally {
4731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004733 }
4734
4735 /**
Wink Saville36469e72014-06-11 15:17:00 -07004736 * Returns the Voice network type for a subId
4737 */
4738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004739 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4740 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004742 mApp, subId, callingPackage, callingFeatureId,
4743 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004744 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4745 }
4746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
4749 final Phone phone = getPhone(subId);
4750 if (phone != null) {
4751 return phone.getServiceState().getVoiceNetworkType();
4752 } else {
4753 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4754 }
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004758 }
4759
4760 /**
4761 * @return true if a ICC card is present
4762 */
4763 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004764 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004765 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4766 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004767 }
4768
4769 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004770 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004771 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004772 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004773 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 final Phone phone = PhoneFactory.getPhone(slotIndex);
4777 if (phone != null) {
4778 return phone.getIccCard().hasIccCard();
4779 } else {
4780 return false;
4781 }
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004785 }
4786
4787 /**
4788 * Return if the current radio is LTE on CDMA. This
4789 * is a tri-state return value as for a period of time
4790 * the mode may be unknown.
4791 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004792 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004793 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004794 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004795 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004797 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4798 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4799 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004800 }
4801
Sanket Padawe356d7632015-06-22 14:03:32 -07004802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004803 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4804 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004805 try {
4806 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4807 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004808 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4809 }
4810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 final long identity = Binder.clearCallingIdentity();
4812 try {
4813 final Phone phone = getPhone(subId);
4814 if (phone == null) {
4815 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4816 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004817 return TelephonyProperties.lte_on_cdma_device()
4818 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 }
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004822 }
Wink Saville36469e72014-06-11 15:17:00 -07004823 }
4824
Wink Saville36469e72014-06-11 15:17:00 -07004825 /**
4826 * {@hide}
4827 * Returns Default subId, 0 in the case of single standby.
4828 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004829 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004830 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004831 }
4832
Shishir Agrawala9f32182016-04-12 12:00:16 -07004833 private int getSlotForDefaultSubscription() {
4834 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4835 }
4836
Wink Savilleb564aae2014-10-23 10:18:09 -07004837 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004838 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004839 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004840
Pengquan Menge92a50d2018-09-21 15:54:48 -07004841 private boolean isActiveSubscription(int subId) {
4842 return mSubscriptionController.isActiveSubId(subId);
4843 }
4844
Ihab Awadf2177b72013-11-25 13:33:23 -08004845 /**
4846 * @see android.telephony.TelephonyManager.WifiCallingChoices
4847 */
4848 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 final long identity = Binder.clearCallingIdentity();
4850 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004851 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4853 getWhenToMakeWifiCallsDefaultPreference());
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004857 }
4858
4859 /**
4860 * @see android.telephony.TelephonyManager.WifiCallingChoices
4861 */
4862 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004866 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4868 } finally {
4869 Binder.restoreCallingIdentity(identity);
4870 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004871 }
4872
Sailesh Nepald1e68152013-12-12 19:08:02 -08004873 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004874 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004875 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004876 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004877
Jordan Liu4c733742019-02-28 12:03:40 -08004878 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4879 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4880 if (phoneId == -1) {
4881 throw new IllegalArgumentException("Given slot index: " + slotIndex
4882 + " does not correspond to an active phone");
4883 }
4884 return PhoneFactory.getPhone(phoneId);
4885 }
4886
Shishir Agrawal566b7612013-10-28 14:41:00 -07004887 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004888 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4889 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4891 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004893 if (DBG) {
4894 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4895 }
4896 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4897 p2);
4898 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004899
Jordan Liu4c733742019-02-28 12:03:40 -08004900
4901 @Override
4902 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4903 int slotIndex, String callingPackage, String aid, int p2) {
4904 enforceModifyPermission();
4905 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4906 if (DBG) {
4907 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4908 }
4909 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4910 callingPackage, aid, p2);
4911 }
4912
4913 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4914 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 if (TextUtils.equals(ISDR_AID, aid)) {
4918 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004919 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4920 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 if (bestComponent == null
4922 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4923 loge("The calling package is not allowed to access ISD-R.");
4924 throw new SecurityException(
4925 "The calling package is not allowed to access ISD-R.");
4926 }
Derek Tan740e1672017-06-27 14:56:27 -07004927 }
Derek Tan740e1672017-06-27 14:56:27 -07004928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004930 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4931 null /* workSource */);
4932 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 return response;
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004937 }
4938
4939 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004940 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4942 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004943 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4944 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4945 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004946
Jordan Liu4c733742019-02-28 12:03:40 -08004947 @Override
4948 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4949 enforceModifyPermission();
4950 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4951 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4952 channel);
4953 }
4954
4955 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 if (channel < 0) {
4959 return false;
4960 }
Jordan Liu4c733742019-02-28 12:03:40 -08004961 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4962 null /* workSource */);
4963 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 return success;
4965 } finally {
4966 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004967 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004968 }
4969
4970 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004971 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004972 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004975 if (DBG) {
4976 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4977 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4978 + p3 + " data=" + data);
4979 }
4980 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4981 command, p1, p2, p3, data);
4982 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004983
Jordan Liu4c733742019-02-28 12:03:40 -08004984 @Override
4985 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4986 int command, int p1, int p2, int p3, String data) {
4987 enforceModifyPermission();
4988 if (DBG) {
4989 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4990 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4991 + p3 + " data=" + data);
4992 }
4993 return iccTransmitApduLogicalChannelWithPermission(
4994 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4995 data);
4996 }
4997
4998 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4999 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
5001 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005002 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 return "";
5004 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005007 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5008 null /* workSource */);
5009 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 // Append the returned status code to the end of the response payload.
5012 String s = Integer.toHexString(
5013 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5014 if (response.payload != null) {
5015 s = IccUtils.bytesToHexString(response.payload) + s;
5016 }
5017 return s;
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005020 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005021 }
Jake Hambye994d462014-02-03 13:10:13 -08005022
Evan Charltonc66da362014-05-16 14:06:40 -07005023 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005024 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5025 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5027 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005029 if (DBG) {
5030 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5031 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5032 }
5033 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5034 cla, command, p1, p2, p3, data);
5035 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005036
Jordan Liu4c733742019-02-28 12:03:40 -08005037 @Override
5038 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5039 int command, int p1, int p2, int p3, String data) {
5040 enforceModifyPermission();
5041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5042 if (DBG) {
5043 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5044 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5045 + " data=" + data);
5046 }
5047
5048 return iccTransmitApduBasicChannelWithPermission(
5049 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5050 p2, p3, data);
5051 }
5052
5053 // open APDU basic channel assuming the caller has sufficient permissions
5054 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5055 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
5058 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5059 && TextUtils.equals(ISDR_AID, data)) {
5060 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005061 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5062 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 if (bestComponent == null
5064 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5065 loge("The calling package is not allowed to select ISD-R.");
5066 throw new SecurityException(
5067 "The calling package is not allowed to select ISD-R.");
5068 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005069 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005072 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5073 null /* workSource */);
5074 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 // Append the returned status code to the end of the response payload.
5077 String s = Integer.toHexString(
5078 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5079 if (response.payload != null) {
5080 s = IccUtils.bytesToHexString(response.payload) + s;
5081 }
5082 return s;
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005085 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005086 }
5087
5088 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005089 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005090 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5092 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 if (DBG) {
5097 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5098 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5099 }
5100
5101 IccIoResult response =
5102 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5103 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5104 subId);
5105
5106 if (DBG) {
5107 log("Exchange SIM_IO [R]" + response);
5108 }
5109
5110 byte[] result = null;
5111 int length = 2;
5112 if (response.payload != null) {
5113 length = 2 + response.payload.length;
5114 result = new byte[length];
5115 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5116 } else {
5117 result = new byte[length];
5118 }
5119
5120 result[length - 1] = (byte) response.sw2;
5121 result[length - 2] = (byte) response.sw1;
5122 return result;
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005125 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005126 }
5127
Nathan Haroldb3014052017-01-25 15:57:32 -08005128 /**
5129 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5130 * on a particular subscription
5131 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005132 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5133 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005135 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005136 return null;
5137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138
5139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 if (appType != TelephonyManager.APPTYPE_USIM
5142 && appType != TelephonyManager.APPTYPE_SIM) {
5143 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5144 return null;
5145 }
5146 Object response = sendRequest(
5147 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5148 if (response instanceof String[]) {
5149 return (String[]) response;
5150 }
yincheng zhao2737e882019-09-06 17:06:54 -07005151 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005153 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005156 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005157 }
5158
yincheng zhao2737e882019-09-06 17:06:54 -07005159 /**
5160 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5161 * subscription.
5162 *
5163 * @param subId the id of the subscription.
5164 * @param appType the uicc app type, must be USIM or SIM.
5165 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5166 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005167 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005168 * @return number of fplmns that is successfully written to the SIM.
5169 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005170 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5171 String callingFeatureId) {
5172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5173 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005174 if (DBG) logv("no permissions for setForbiddenplmns");
5175 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5176 }
5177 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5178 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5179 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5180 }
5181 if (fplmns == null) {
5182 throw new IllegalArgumentException("Fplmn List provided is null");
5183 }
5184 for (String fplmn : fplmns) {
5185 if (!CellIdentity.isValidPlmn(fplmn)) {
5186 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5187 }
5188 }
5189 final long identity = Binder.clearCallingIdentity();
5190 try {
5191 Object response = sendRequest(
5192 CMD_SET_FORBIDDEN_PLMNS,
5193 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5194 subId);
5195 return (int) response;
5196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
5199 }
5200
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005201 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005202 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5204 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 final long identity = Binder.clearCallingIdentity();
5207 try {
5208 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5209 if (response.payload == null) {
5210 return "";
5211 }
Evan Charltonc66da362014-05-16 14:06:40 -07005212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 // Append the returned status code to the end of the response payload.
5214 String s = Integer.toHexString(
5215 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5216 s = IccUtils.bytesToHexString(response.payload) + s;
5217 return s;
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Evan Charltonc66da362014-05-16 14:06:40 -07005221 }
5222
Jake Hambye994d462014-02-03 13:10:13 -08005223 /**
5224 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5225 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5226 *
5227 * @param itemID the ID of the item to read
5228 * @return the NV item as a String, or null on error.
5229 */
5230 @Override
5231 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005232 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5234 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235
5236 final long identity = Binder.clearCallingIdentity();
5237 try {
5238 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005239 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5241 return value;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Jake Hambye994d462014-02-03 13:10:13 -08005245 }
5246
5247 /**
5248 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5249 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5250 *
5251 * @param itemID the ID of the item to read
5252 * @param itemValue the value to write, as a String
5253 * @return true on success; false on any failure
5254 */
5255 @Override
5256 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005257 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5264 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005265 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5267 return success;
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Jake Hambye994d462014-02-03 13:10:13 -08005271 }
5272
5273 /**
5274 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5275 * Used for device configuration by some CDMA operators.
5276 *
5277 * @param preferredRoamingList byte array containing the new PRL
5278 * @return true on success; false on any failure
5279 */
5280 @Override
5281 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5283 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284
5285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5288 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5289 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5290 return success;
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Jake Hambye994d462014-02-03 13:10:13 -08005294 }
5295
5296 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005297 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005298 * Used for device configuration by some CDMA operators.
5299 *
chen xu6dac5ab2018-10-26 17:39:23 -07005300 * @param slotIndex - device slot.
5301 *
Jake Hambye994d462014-02-03 13:10:13 -08005302 * @return true on success; false on any failure
5303 */
5304 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005305 public boolean resetModemConfig(int slotIndex) {
5306 Phone phone = PhoneFactory.getPhone(slotIndex);
5307 if (phone != null) {
5308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5309 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310
chen xu6dac5ab2018-10-26 17:39:23 -07005311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5314 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5315 return success;
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 }
chen xu6dac5ab2018-10-26 17:39:23 -07005320 return false;
5321 }
5322
5323 /**
5324 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5325 *
5326 * @param slotIndex - device slot.
5327 *
5328 * @return true on success; false on any failure
5329 */
5330 @Override
5331 public boolean rebootModem(int slotIndex) {
5332 Phone phone = PhoneFactory.getPhone(slotIndex);
5333 if (phone != null) {
5334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5335 mApp, phone.getSubId(), "rebootModem");
5336
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5340 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5341 return success;
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
5344 }
5345 }
5346 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005347 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005348
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005349 public String[] getPcscfAddress(String apnType, String callingPackage,
5350 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005351 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5353 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005354 return new String[0];
5355 }
5356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005359 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Wink Saville36469e72014-06-11 15:17:00 -07005363 }
5364
Brad Ebinger51f743a2017-01-23 13:50:20 -08005365 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005366 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5367 * {@link #disableIms(int)}.
5368 * @param slotIndex device slot.
5369 */
5370 public void resetIms(int slotIndex) {
5371 enforceModifyPermission();
5372
5373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 if (mImsResolver == null) {
5376 // may happen if the does not support IMS.
5377 return;
5378 }
5379 mImsResolver.disableIms(slotIndex);
5380 mImsResolver.enableIms(slotIndex);
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
5384 }
5385
5386 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005387 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5388 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005389 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005390 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005391 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392
5393 final long identity = Binder.clearCallingIdentity();
5394 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005395 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005396 // may happen if the device does not support IMS.
5397 return;
5398 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005399 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005403 }
5404
5405 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005406 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5407 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005408 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005409 public void disableIms(int slotId) {
5410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005414 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005415 // may happen if the device does not support IMS.
5416 return;
5417 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005418 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005422 }
5423
5424 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005425 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5426 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005427 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005428 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005429 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431
5432 final long identity = Binder.clearCallingIdentity();
5433 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005434 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005435 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5436 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005437 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005438 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005442 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005443 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005444 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5445 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005446 @Override
5447 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005448 enforceModifyPermission();
5449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005453 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
5457 }
5458
5459 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005460 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005461 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005462 */
5463 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5464 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005468 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005469 // may happen if the device does not support IMS.
5470 return null;
5471 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005472 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005476 }
5477
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005478 /**
5479 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005480 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005481 */
5482 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5483 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005487 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005488 // may happen if the device does not support IMS.
5489 return null;
5490 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005491 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005495 }
5496
Brad Ebinger884c07b2018-02-15 16:17:40 -08005497 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005498 * Sets the ImsService Package Name that Telephony will bind to.
5499 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005500 * @param slotIndex the slot ID that the ImsService should bind for.
5501 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005502 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005503 * @param featureTypes An integer array of feature types associated with a packageName.
5504 * @param packageName The name of the package that the current configuration will be replaced
5505 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005506 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005507 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005508 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5509 int[] featureTypes, String packageName) {
5510 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5511 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5513 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005514 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 final long identity = Binder.clearCallingIdentity();
5517 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005518 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005519 // may happen if the device does not support IMS.
5520 return false;
5521 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005522 Map<Integer, String> featureConfig = new HashMap<>();
5523 for (int featureType : featureTypes) {
5524 featureConfig.put(featureType, packageName);
5525 }
5526 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5527 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005531 }
5532
5533 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005534 * Clears any carrier ImsService overrides for the slot index specified that were previously
5535 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5536 *
5537 * This should only be used for testing.
5538 *
5539 * @param slotIndex the slot ID that the ImsService should bind for.
5540 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5541 */
5542 @Override
5543 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5544 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5546 "clearCarrierImsServiceOverride");
5547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5548 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5549 "clearCarrierImsServiceOverride");
5550
5551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 if (mImsResolver == null) {
5554 // may happen if the device does not support IMS.
5555 return false;
5556 }
5557 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
5561 }
5562
5563 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005564 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005565 *
5566 * @param slotId The slot that the ImsService is associated with.
5567 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5568 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005569 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005570 * @return the package name of the ImsService configuration.
5571 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005572 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5573 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005574 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005575 TelephonyPermissions
5576 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5577 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5578 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 final long identity = Binder.clearCallingIdentity();
5581 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005582 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005583 // may happen if the device does not support IMS.
5584 return "";
5585 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005586 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005587 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5588 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005592 }
5593
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005594 /**
5595 * Get the MmTelFeature state associated with the requested subscription id.
5596 * @param subId The subscription that the MmTelFeature is associated with.
5597 * @param callback A callback with an integer containing the
5598 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5599 */
5600 @Override
5601 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5602 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5603 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5604 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5605 "IMS not available on device.");
5606 }
5607 final long token = Binder.clearCallingIdentity();
5608 try {
5609 int slotId = getSlotIndex(subId);
5610 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5611 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5612 + subId + "'");
5613 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5614 }
5615 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5616 try {
5617 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5618 } catch (RemoteException e) {
5619 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5620 + "Ignore");
5621 }
5622 });
5623 } finally {
5624 Binder.restoreCallingIdentity(token);
5625 }
5626 }
5627
Daniel Brightbb5840b2021-01-12 15:48:18 -08005628 /**
5629 * Sets the ims registration state on all valid {@link Phone}s.
5630 */
5631 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005636 // NOTE: Before S, this method only set the default phone.
5637 for (final Phone phone : PhoneFactory.getPhones()) {
5638 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5639 phone.setImsRegistrationState(registered);
5640 }
5641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Wink Saville36469e72014-06-11 15:17:00 -07005645 }
5646
5647 /**
Stuart Scott54788802015-03-30 13:18:01 -07005648 * Set the network selection mode to automatic.
5649 *
5650 */
5651 @Override
5652 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5654 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
shilufc958392020-01-20 11:36:01 -08005658 if (!isActiveSubscription(subId)) {
5659 return;
5660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5662 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Stuart Scott54788802015-03-30 13:18:01 -07005666 }
5667
Jack Yud10cdd42020-09-28 20:28:01 -07005668 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005669 * Ask the radio to connect to the input network and change selection mode to manual.
5670 *
5671 * @param subId the id of the subscription.
5672 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5673 * the operator to attach to.
5674 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5675 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5676 * normal network selection next time.
5677 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005678 */
5679 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005680 public boolean setNetworkSelectionModeManual(
5681 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5683 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005684
5685 if (!isActiveSubscription(subId)) {
5686 return false;
5687 }
5688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 final long identity = Binder.clearCallingIdentity();
5690 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005691 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005693 if (DBG) {
5694 log("setNetworkSelectionModeManual: subId: " + subId
5695 + " operator: " + operatorInfo);
5696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005701 }
shilu84f6e8b2019-12-19 13:58:01 -08005702 /**
5703 * Get the manual network selection
5704 *
5705 * @param subId the id of the subscription.
5706 *
5707 * @return the previously saved user selected PLMN
5708 */
5709 @Override
5710 public String getManualNetworkSelectionPlmn(int subId) {
5711 TelephonyPermissions
5712 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5713 mApp, subId, "getManualNetworkSelectionPlmn");
5714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
5717 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005718 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005719 }
5720
5721 final Phone phone = getPhone(subId);
5722 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005723 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005724 }
5725 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5726 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5727 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
5731 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005732
5733 /**
5734 * Scans for available networks.
5735 */
5736 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005737 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5738 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5740 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005741 LocationAccessPolicy.LocationPermissionResult locationResult =
5742 LocationAccessPolicy.checkLocationPermission(mApp,
5743 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5744 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005745 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005746 .setCallingPid(Binder.getCallingPid())
5747 .setCallingUid(Binder.getCallingUid())
5748 .setMethod("getCellNetworkScanResults")
5749 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005750 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5751 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005752 .build());
5753 switch (locationResult) {
5754 case DENIED_HARD:
5755 throw new SecurityException("Not allowed to access scan results -- location");
5756 case DENIED_SOFT:
5757 return null;
5758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759
Pengquan Menga1bb6272018-09-06 09:59:22 -07005760 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 try {
5762 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005763 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005768 }
5769
5770 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005771 * Get the call forwarding info, given the call forwarding reason.
5772 */
5773 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005774 public void getCallForwarding(int subId, int callForwardingReason,
5775 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005776 enforceReadPrivilegedPermission("getCallForwarding");
5777 long identity = Binder.clearCallingIdentity();
5778 try {
5779 if (DBG) {
5780 log("getCallForwarding: subId " + subId
5781 + " callForwardingReason" + callForwardingReason);
5782 }
Hall Liu27d24262020-09-18 19:04:59 -07005783
5784 Phone phone = getPhone(subId);
5785 if (phone == null) {
5786 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005787 callback.onError(
5788 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005789 } catch (RemoteException e) {
5790 // ignore
5791 }
5792 return;
5793 }
5794
5795 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5796 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5797 @Override
5798 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5799 try {
5800 callback.onCallForwardingInfoAvailable(info);
5801 } catch (RemoteException e) {
5802 // ignore
5803 }
5804 }
5805
5806 @Override
5807 public void onError(int error) {
5808 try {
5809 callback.onError(error);
5810 } catch (RemoteException e) {
5811 // ignore
5812 }
5813 }
5814 });
5815 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
5819 }
5820
5821 /**
5822 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5823 * reason, the number to forward, and the timeout before the forwarding is attempted.
5824 */
5825 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005826 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5827 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005828 enforceModifyPermission();
5829 long identity = Binder.clearCallingIdentity();
5830 try {
5831 if (DBG) {
5832 log("setCallForwarding: subId " + subId
5833 + " callForwardingInfo" + callForwardingInfo);
5834 }
Hall Liu27d24262020-09-18 19:04:59 -07005835
5836 Phone phone = getPhone(subId);
5837 if (phone == null) {
5838 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005839 callback.accept(
5840 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005841 } catch (RemoteException e) {
5842 // ignore
5843 }
5844 return;
5845 }
5846
5847 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5848 FunctionalUtils.ignoreRemoteException(callback::accept));
5849
5850 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
5854 }
5855
5856 /**
Hall Liu27d24262020-09-18 19:04:59 -07005857 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005858 */
5859 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005860 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005861 enforceReadPrivilegedPermission("getCallForwarding");
5862 long identity = Binder.clearCallingIdentity();
5863 try {
Hall Liu27d24262020-09-18 19:04:59 -07005864
5865 Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 try {
5868 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5869 } catch (RemoteException e) {
5870 // ignore
5871 }
5872 return;
5873 }
5874
5875 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5876
Shuo Qian4a594052020-01-23 11:59:30 -08005877 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005878 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005879 } finally {
5880 Binder.restoreCallingIdentity(identity);
5881 }
5882 }
5883
5884 /**
Hall Liu27d24262020-09-18 19:04:59 -07005885 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005886 */
5887 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005888 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005889 enforceModifyPermission();
5890 long identity = Binder.clearCallingIdentity();
5891 try {
Hall Liu27d24262020-09-18 19:04:59 -07005892 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5893
5894 Phone phone = getPhone(subId);
5895 if (phone == null) {
5896 try {
5897 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5898 } catch (RemoteException e) {
5899 // ignore
5900 }
5901 return;
5902 }
5903
5904 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5905 FunctionalUtils.ignoreRemoteException(callback::accept));
5906
5907 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
5911 }
5912
5913 /**
yinxub1bed742017-04-17 11:45:04 -07005914 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005915 *
yinxub1bed742017-04-17 11:45:04 -07005916 * @param subId id of the subscription
5917 * @param request contains the radio access networks with bands/channels to scan
5918 * @param messenger callback messenger for scan results or errors
5919 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005920 * @return the id of the requested scan which can be used to stop the scan.
5921 */
5922 @Override
5923 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005924 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5926 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005927 LocationAccessPolicy.LocationPermissionResult locationResult =
5928 LocationAccessPolicy.checkLocationPermission(mApp,
5929 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5930 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005931 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005932 .setCallingPid(Binder.getCallingPid())
5933 .setCallingUid(Binder.getCallingUid())
5934 .setMethod("requestNetworkScan")
5935 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005936 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5937 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005938 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005939 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005940 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5941 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005942 if (e != null) {
5943 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5944 throw e;
5945 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005946 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005947 return TelephonyScanManager.INVALID_SCAN_ID;
5948 }
5949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 }
Hall Liu912dfd32019-04-25 14:02:26 -07005951 int callingUid = Binder.getCallingUid();
5952 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 return mNetworkScanRequestTracker.startNetworkScan(
5956 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005957 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
yinxu504e1392017-04-12 16:03:22 -07005961 }
5962
Hall Liub2ac8ef2019-02-28 15:56:23 -08005963 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005964 NetworkScanRequest request, int subId, String callingPackage) {
5965 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005966 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5967 boolean hasNetworkScanPermission =
5968 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5969 == PERMISSION_GRANTED;
5970
5971 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5972 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5973 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005974 }
5975
5976 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5977 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005978 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5979 return new SecurityException("Specific channels must not be"
5980 + " scanned without location access.");
5981 }
5982 }
5983 }
5984
Hall Liub2ac8ef2019-02-28 15:56:23 -08005985 return null;
5986 }
5987
yinxu504e1392017-04-12 16:03:22 -07005988 /**
5989 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005990 *
5991 * @param subId id of the subscription
5992 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005993 */
5994 @Override
5995 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5997 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998
Hall Liu912dfd32019-04-25 14:02:26 -07005999 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006002 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 } finally {
6004 Binder.restoreCallingIdentity(identity);
6005 }
yinxu504e1392017-04-12 16:03:22 -07006006 }
6007
6008 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006009 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006010 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006011 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006012 */
6013 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006014 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006015 TelephonyPermissions
6016 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006017 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018
6019 final long identity = Binder.clearCallingIdentity();
6020 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006021 if (DBG) log("getAllowedNetworkTypesBitmask");
6022 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6023 int networkTypesBitmask = (result != null ? result[0] : -1);
6024 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6025 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006029 }
6030
6031 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006032 * Get the allowed network types for certain reason.
6033 *
6034 * @param subId the id of the subscription.
6035 * @param reason the reason the allowed network type change is taking place
6036 * @return the allowed network types.
6037 */
6038 @Override
6039 public long getAllowedNetworkTypesForReason(int subId,
6040 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6041 TelephonyPermissions
6042 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6043 mApp, subId, "getAllowedNetworkTypesForReason");
6044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
6050 }
6051
6052 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006053 * Enable/Disable E-UTRA-NR Dual Connectivity
6054 * @param subId subscription id of the sim card
6055 * @param nrDualConnectivityState expected NR dual connectivity state
6056 * This can be passed following states
6057 * <ol>
6058 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6059 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6060 * <li>Disable NR dual connectivity and force secondary cell to be released
6061 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6062 * </ol>
6063 * @return operation result.
6064 */
6065 @Override
6066 public int setNrDualConnectivityState(int subId,
6067 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6069 mApp, subId, "enableNRDualConnectivity");
6070 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6074 nrDualConnectivityState, subId,
6075 workSource);
6076 if (DBG) log("enableNRDualConnectivity result: " + result);
6077 return result;
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
6080 }
6081 }
6082
6083 /**
6084 * Is E-UTRA-NR Dual Connectivity enabled
6085 * @return true if dual connectivity is enabled else false
6086 */
6087 @Override
6088 public boolean isNrDualConnectivityEnabled(int subId) {
6089 TelephonyPermissions
6090 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6091 mApp, subId, "isNRDualConnectivityEnabled");
6092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6096 null, subId, workSource);
6097 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6098 return isEnabled;
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
6103
6104 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006105 * get carrier bandwidth per primary and secondary carrier
6106 * @param subId subscription id of the sim card
6107 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6108 */
6109 @Override
6110 public CarrierBandwidth getCarrierBandwidth(int subId) {
6111 TelephonyPermissions
6112 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6113 mApp, subId, "isNRDualConnectivityEnabled");
6114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6115 final long identity = Binder.clearCallingIdentity();
6116 try {
6117 CarrierBandwidth carrierBandwidth =
6118 getPhoneFromSubId(subId).getCarrierBandwidth();
6119 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6120 return carrierBandwidth;
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
6124 }
6125
6126 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006127 * Set the allowed network types of the device and
6128 * provide the reason triggering the allowed network change.
6129 *
6130 * @param subId the id of the subscription.
6131 * @param reason the reason the allowed network type change is taking place
6132 * @param allowedNetworkTypes the allowed network types.
6133 * @return true on success; false on any failure.
6134 */
6135 @Override
6136 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006137 @TelephonyManager.AllowedNetworkTypesReason int reason,
6138 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6140 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006141 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6142 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6143 return false;
6144 }
6145
6146 if (DBG) {
6147 log("setAllowedNetworkTypesForReason: " + reason
6148 + " value: " + allowedNetworkTypes);
6149 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006150 final long identity = Binder.clearCallingIdentity();
6151 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006152 Boolean success = (Boolean) sendRequest(
6153 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6154 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6155
6156 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6157 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
6161 }
6162
6163 /**
Miaoa84611c2019-03-15 09:21:10 +08006164 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006165 *
Miaoa84611c2019-03-15 09:21:10 +08006166 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006167 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006168 * @hide
6169 */
6170 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006171 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006174 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 try {
Miaoa84611c2019-03-15 09:21:10 +08006176 if (phone != null) {
6177 return phone.hasMatchedTetherApnSetting();
6178 } else {
6179 return false;
6180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 } finally {
6182 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006183 }
Junda Liu475951f2014-11-07 16:45:03 -08006184 }
6185
6186 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006187 * Enable or disable always reporting signal strength changes from radio.
6188 *
6189 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6190 */
6191 @Override
6192 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6193 enforceModifyPermission();
6194 enforceSystemCaller();
6195
6196 final long identity = Binder.clearCallingIdentity();
6197 final Phone phone = getPhone(subId);
6198 try {
6199 if (phone != null) {
6200 if (DBG) {
6201 log("setAlwaysReportSignalStrength: subId=" + subId
6202 + " isEnable=" + isEnable);
6203 }
6204 phone.setAlwaysReportSignalStrength(isEnable);
6205 } else {
6206 loge("setAlwaysReportSignalStrength: no phone found for subId="
6207 + subId);
6208 }
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
6213
6214 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006215 * Get the user enabled state of Mobile Data.
6216 *
6217 * TODO: remove and use isUserDataEnabled.
6218 * This can't be removed now because some vendor codes
6219 * calls through ITelephony directly while they should
6220 * use TelephonyManager.
6221 *
6222 * @return true on enabled
6223 */
6224 @Override
6225 public boolean getDataEnabled(int subId) {
6226 return isUserDataEnabled(subId);
6227 }
6228
6229 /**
6230 * Get whether mobile data is enabled per user setting.
6231 *
6232 * There are other factors deciding whether mobile data is actually enabled, but they are
6233 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006234 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006235 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006236 *
6237 * @return {@code true} if data is enabled else {@code false}
6238 */
6239 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006240 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006241 try {
6242 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6243 null);
6244 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6246 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 int phoneId = mSubscriptionController.getPhoneId(subId);
6252 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6253 Phone phone = PhoneFactory.getPhone(phoneId);
6254 if (phone != null) {
6255 boolean retVal = phone.isUserDataEnabled();
6256 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6257 return retVal;
6258 } else {
6259 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6260 return false;
6261 }
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006264 }
6265 }
6266
6267 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006268 * Checks if the device is capable of mobile data by considering whether whether the
6269 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6270 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006271 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006272 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006273 */
6274 @Override
6275 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006276 try {
6277 try {
6278 mApp.enforceCallingOrSelfPermission(
6279 android.Manifest.permission.ACCESS_NETWORK_STATE,
6280 null);
6281 } catch (Exception e) {
6282 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6283 "isDataEnabled");
6284 }
6285 } catch (Exception e) {
6286 enforceReadPrivilegedPermission("isDataEnabled");
6287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 int phoneId = mSubscriptionController.getPhoneId(subId);
6292 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6293 Phone phone = PhoneFactory.getPhone(phoneId);
6294 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006295 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6297 return retVal;
6298 } else {
6299 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6300 return false;
6301 }
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006304 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006305 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006306
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006307 /**
6308 * Check if data is enabled for a specific reason
6309 * @param subId Subscription index
6310 * @param reason the reason the data enable change is taking place
6311 * @return {@code true} if the overall data is enabled; {@code false} if not.
6312 */
6313 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006314 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006315 @TelephonyManager.DataEnabledReason int reason) {
6316 try {
6317 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6318 null);
6319 } catch (Exception e) {
6320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006321 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006322 }
6323
6324
6325 final long identity = Binder.clearCallingIdentity();
6326 try {
6327 int phoneId = mSubscriptionController.getPhoneId(subId);
6328 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006329 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006330 + " reason=" + reason);
6331 }
6332 Phone phone = PhoneFactory.getPhone(phoneId);
6333 if (phone != null) {
6334 boolean retVal;
6335 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6336 retVal = phone.isUserDataEnabled();
6337 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006338 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006339 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006340 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006341 return retVal;
6342 } else {
6343 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006344 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006345 + subId + " retVal=false");
6346 }
6347 return false;
6348 }
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
6352 }
6353
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006354 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006355 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006356 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6357 // Skip the check if it's one of these special uids
6358 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6359 }
6360
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006361 //load access rules from carrier configs, and check those as well: b/139133814
6362 SubscriptionController subController = SubscriptionController.getInstance();
6363 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6364 || subController == null) return privilegeFromSim;
6365
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006366 PackageManager pkgMgr = phone.getContext().getPackageManager();
6367 String[] packages = pkgMgr.getPackagesForUid(uid);
6368
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006371 int subId = phone.getSubId();
6372 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6373 // A test override is in place for the privileges for this subId, so don't try to
6374 // read the subscription privileges.
6375 return privilegeFromSim;
6376 }
6377 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006378 SubscriptionManager subManager = (SubscriptionManager)
6379 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6380 for (String pkg : packages) {
6381 if (subManager.canManageSubscription(subInfo, pkg)) {
6382 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6383 }
6384 }
6385 return privilegeFromSim;
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
6389 }
6390
6391 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6392 String pkgName) {
6393 //load access rules from carrier configs, and check those as well: b/139133814
6394 SubscriptionController subController = SubscriptionController.getInstance();
6395 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6396 || subController == null) return privilegeFromSim;
6397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006400 int subId = phone.getSubId();
6401 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6402 // A test override is in place for the privileges for this subId, so don't try to
6403 // read the subscription privileges.
6404 return privilegeFromSim;
6405 }
6406 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006407 SubscriptionManager subManager = (SubscriptionManager)
6408 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6409 return subManager.canManageSubscription(subInfo, pkgName)
6410 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
6414 }
6415
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006416 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006417 public int getCarrierPrivilegeStatus(int subId) {
6418 final Phone phone = getPhone(subId);
6419 if (phone == null) {
6420 loge("getCarrierPrivilegeStatus: Invalid subId");
6421 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6422 }
6423 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006424 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006425 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006426 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6427 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006428
6429 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6430 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006431 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006432 }
Junda Liu29340342014-07-10 15:23:27 -07006433
6434 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006435 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006436 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006437 final Phone phone = getPhone(subId);
6438 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006439 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006440 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6441 }
6442 UiccProfile profile =
6443 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6444 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006445 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006446 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6447 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006448 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006449 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006450 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006451 }
6452
6453 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006454 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6455 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006456 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006457 }
6458
6459 int phoneId = SubscriptionManager.getPhoneId(subId);
6460 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006461 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006462 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6464 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006465 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6466 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6467 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006468 }
6469
6470 @Override
6471 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006472 if (TextUtils.isEmpty(pkgName))
6473 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006474 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6475 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6476 UiccCard card = UiccController.getInstance().getUiccCard(i);
6477 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006478 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006479 continue;
6480 }
6481
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006482 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6483 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6484 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006485 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6486 break;
6487 }
6488 }
6489
6490 return result;
Junda Liu29340342014-07-10 15:23:27 -07006491 }
Derek Tan89e89d42014-07-08 17:00:10 -07006492
6493 @Override
Junda Liue64de782015-04-16 17:19:16 -07006494 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6495 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6496 loge("phoneId " + phoneId + " is not valid.");
6497 return null;
6498 }
6499 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006500 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006501 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006502 return null ;
6503 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006504 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006505 }
6506
Amith Yamasani6e118872016-02-19 12:53:51 -08006507 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006508 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006509 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006510 List<String> privilegedPackages = new ArrayList<>();
6511 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006512 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6513 // has UICC in that slot.
6514 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006515 if (card.hasCarrierPrivilegeRules()) {
6516 if (packages == null) {
6517 // Only check packages in user 0 for now
6518 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006519 PackageManager.MATCH_DISABLED_COMPONENTS
6520 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006521 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006522 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006523 }
6524 for (int p = packages.size() - 1; p >= 0; p--) {
6525 PackageInfo pkgInfo = packages.get(p);
6526 if (pkgInfo != null && pkgInfo.packageName != null
6527 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006528 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006529 privilegedPackages.add(pkgInfo.packageName);
6530 }
6531 }
6532 }
6533 }
6534 return privilegedPackages;
6535 }
6536
chen xuf7e9fe82019-05-09 19:31:02 -07006537 @Override
6538 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006539 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6540
6541 final long identity = Binder.clearCallingIdentity();
6542
chen xuf7e9fe82019-05-09 19:31:02 -07006543 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006544 try {
6545 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6546 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6547 }
6548 } finally {
6549 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006550 }
6551 return privilegedPackages;
6552 }
6553
Wink Savilleb564aae2014-10-23 10:18:09 -07006554 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006555 final Phone phone = getPhone(subId);
6556 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006557 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006558 return null;
6559 }
6560 String iccId = card.getIccId();
6561 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006562 return null;
6563 }
6564 return iccId;
6565 }
6566
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006567 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006568 public void setCallComposerStatus(int subId, int status) {
6569 enforceModifyPermission();
6570
6571 final long identity = Binder.clearCallingIdentity();
6572 try {
6573 Phone phone = getPhone(subId);
6574 if (phone != null) {
6575 Phone defaultPhone = phone.getImsPhone();
6576 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6577 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6578 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006579 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6580 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006581 }
6582 }
Shuo Qian284ae752020-12-22 19:10:14 -08006583 } catch (ImsException e) {
6584 throw new ServiceSpecificException(e.getCode());
6585 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006586 Binder.restoreCallingIdentity(identity);
6587 }
6588 }
6589
6590 @Override
6591 public int getCallComposerStatus(int subId) {
6592 enforceReadPrivilegedPermission("getCallComposerStatus");
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 Phone phone = getPhone(subId);
6597 if (phone != null) {
6598 Phone defaultPhone = phone.getImsPhone();
6599 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6600 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6601 return imsPhone.getCallComposerStatus();
6602 }
6603 }
6604 } finally {
6605 Binder.restoreCallingIdentity(identity);
6606 }
6607 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6608 }
6609
6610 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006611 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6612 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006613 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006614 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 final long identity = Binder.clearCallingIdentity();
6617 try {
6618 final String iccId = getIccId(subId);
6619 final Phone phone = getPhone(subId);
6620 if (phone == null) {
6621 return false;
6622 }
6623 final String subscriberId = phone.getSubscriberId();
6624
6625 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006626 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 + subscriberId + " to " + number);
6628 }
6629
6630 if (TextUtils.isEmpty(iccId)) {
6631 return false;
6632 }
6633
6634 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6635
6636 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6637 if (alphaTag == null) {
6638 editor.remove(alphaTagPrefKey);
6639 } else {
6640 editor.putString(alphaTagPrefKey, alphaTag);
6641 }
6642
6643 // Record both the line number and IMSI for this ICCID, since we need to
6644 // track all merged IMSIs based on line number
6645 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6646 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6647 if (number == null) {
6648 editor.remove(numberPrefKey);
6649 editor.remove(subscriberPrefKey);
6650 } else {
6651 editor.putString(numberPrefKey, number);
6652 editor.putString(subscriberPrefKey, subscriberId);
6653 }
6654
6655 editor.commit();
6656 return true;
6657 } finally {
6658 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006659 }
Derek Tan7226c842014-07-02 17:42:23 -07006660 }
6661
6662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006663 public String getLine1NumberForDisplay(int subId, String callingPackage,
6664 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006665 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006667 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006668 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006669 return null;
6670 }
Derek Tan97ebb422014-09-05 16:55:38 -07006671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 String iccId = getIccId(subId);
6675 if (iccId != null) {
6676 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6677 if (DBG_MERGE) {
6678 log("getLine1NumberForDisplay returning "
6679 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6680 }
6681 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6684 return null;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006687 }
Derek Tan7226c842014-07-02 17:42:23 -07006688 }
6689
6690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006691 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6692 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006694 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006695 return null;
6696 }
Derek Tan97ebb422014-09-05 16:55:38 -07006697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 String iccId = getIccId(subId);
6701 if (iccId != null) {
6702 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6703 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6704 }
6705 return null;
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006708 }
Derek Tan7226c842014-07-02 17:42:23 -07006709 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006710
6711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006712 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6713 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006714 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6715 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006717 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006718 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006719 return null;
6720 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006721
Jordan Liub49b04b2019-05-06 14:45:15 -07006722 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6723 // the process, where TelephonyManager was instantiated.
6724 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006725 final long identity = Binder.clearCallingIdentity();
6726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006727 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 final TelephonyManager tele = TelephonyManager.from(context);
6729 final SubscriptionManager sub = SubscriptionManager.from(context);
6730
6731 // Figure out what subscribers are currently active
6732 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
Jordan Liub49b04b2019-05-06 14:45:15 -07006734 // Only consider subs which match the current subId
6735 // This logic can be simplified. See b/131189269 for progress.
6736 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006737 activeSubscriberIds.add(tele.getSubscriberId(subId));
6738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739
6740 // First pass, find a number override for an active subscriber
6741 String mergeNumber = null;
6742 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6743 for (String key : prefs.keySet()) {
6744 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6745 final String subscriberId = (String) prefs.get(key);
6746 if (activeSubscriberIds.contains(subscriberId)) {
6747 final String iccId = key.substring(
6748 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6749 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6750 mergeNumber = (String) prefs.get(numberKey);
6751 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006752 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 + " for active subscriber " + subscriberId);
6754 }
6755 if (!TextUtils.isEmpty(mergeNumber)) {
6756 break;
6757 }
6758 }
6759 }
6760 }
6761
6762 // Shortcut when no active merged subscribers
6763 if (TextUtils.isEmpty(mergeNumber)) {
6764 return null;
6765 }
6766
6767 // Second pass, find all subscribers under that line override
6768 final ArraySet<String> result = new ArraySet<>();
6769 for (String key : prefs.keySet()) {
6770 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6771 final String number = (String) prefs.get(key);
6772 if (mergeNumber.equals(number)) {
6773 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6774 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6775 final String subscriberId = (String) prefs.get(subscriberKey);
6776 if (!TextUtils.isEmpty(subscriberId)) {
6777 result.add(subscriberId);
6778 }
6779 }
6780 }
6781 }
6782
6783 final String[] resultArray = result.toArray(new String[result.size()]);
6784 Arrays.sort(resultArray);
6785 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006786 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6788 }
6789 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006790 } finally {
6791 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006792 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006793 }
6794
6795 @Override
zoey chen38003472019-12-13 17:16:31 +08006796 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6797 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006798
6799 final long identity = Binder.clearCallingIdentity();
6800 try {
6801 final TelephonyManager telephonyManager = mApp.getSystemService(
6802 TelephonyManager.class);
6803 String subscriberId = telephonyManager.getSubscriberId(subId);
6804 if (subscriberId == null) {
6805 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006806 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006807 + subId);
6808 }
6809 return null;
6810 }
6811
6812 final SubscriptionInfo info = SubscriptionController.getInstance()
6813 .getSubscriptionInfo(subId);
6814 final ParcelUuid groupUuid = info.getGroupUuid();
6815 // If it doesn't belong to any group, return just subscriberId of itself.
6816 if (groupUuid == null) {
6817 return new String[]{subscriberId};
6818 }
6819
6820 // Get all subscriberIds from the group.
6821 final List<String> mergedSubscriberIds = new ArrayList<>();
6822 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006823 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006824 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006825 for (SubscriptionInfo subInfo : groupInfos) {
6826 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6827 if (subscriberId != null) {
6828 mergedSubscriberIds.add(subscriberId);
6829 }
6830 }
6831
6832 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
6835
6836 }
6837 }
6838
6839 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006840 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006841 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006842 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006843
6844 final long identity = Binder.clearCallingIdentity();
6845 try {
6846 final Phone phone = getPhone(subId);
6847 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006851 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006852
6853 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006854 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006855 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6856 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006857 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6858 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859
6860 final long identity = Binder.clearCallingIdentity();
6861 try {
6862 final Phone phone = getPhone(subId);
6863 if (phone == null) {
6864 return false;
6865 }
6866 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6867 cdmaNonRoamingList);
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006870 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006871 }
6872
6873 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006874 @Deprecated
6875 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6876 enforceModifyPermission();
6877
6878 int returnValue = 0;
6879 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006880 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006881 if(result.exception == null) {
6882 if (result.result != null) {
6883 byte[] responseData = (byte[])(result.result);
6884 if(responseData.length > oemResp.length) {
6885 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6886 responseData.length + "bytes. Buffer Size is " +
6887 oemResp.length + "bytes.");
6888 }
6889 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6890 returnValue = responseData.length;
6891 }
6892 } else {
6893 CommandException ex = (CommandException) result.exception;
6894 returnValue = ex.getCommandError().ordinal();
6895 if(returnValue > 0) returnValue *= -1;
6896 }
6897 } catch (RuntimeException e) {
6898 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6899 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6900 if(returnValue > 0) returnValue *= -1;
6901 }
6902
6903 return returnValue;
6904 }
6905
6906 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006907 public void setRadioCapability(RadioAccessFamily[] rafs) {
6908 try {
6909 ProxyController.getInstance().setRadioCapability(rafs);
6910 } catch (RuntimeException e) {
6911 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6912 }
6913 }
6914
6915 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006916 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006917 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006918 try {
6919 TelephonyPermissions
6920 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6921 mApp, phone.getSubId(), "getRadioAccessFamily");
6922 } catch (SecurityException e) {
6923 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6924 throw e;
6925 }
chen xub97461a2018-10-26 14:17:57 -07006926 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006927 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006928 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 final long identity = Binder.clearCallingIdentity();
6931 try {
chen xub97461a2018-10-26 14:17:57 -07006932 TelephonyPermissions
6933 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6934 mApp, phone.getSubId(), "getRadioAccessFamily");
6935 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
chen xub97461a2018-10-26 14:17:57 -07006939 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006940 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006941
6942 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006943 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08006944 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08006945 try {
6946 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6947 Binder.getCallingUid())) {
6948 throw new SecurityException("Package uid and package name do not match: "
6949 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6950 }
6951 } catch (PackageManager.NameNotFoundException e) {
6952 throw new SecurityException("Package name invalid:" + callingPackage);
6953 }
6954 RoleManager rm = mApp.getSystemService(RoleManager.class);
6955 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6956 if (!dialerRoleHolders.contains(callingPackage)) {
6957 throw new SecurityException("App must be the dialer role holder to"
6958 + " upload a call composer pic");
6959 }
6960
6961 Executors.newSingleThreadExecutor().execute(() -> {
6962 ByteArrayOutputStream output = new ByteArrayOutputStream(
6963 (int) TelephonyManager.getMaximumCallComposerPictureSize());
6964 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
6965 boolean readUntilEnd = false;
6966 int totalBytesRead = 0;
6967 byte[] buffer = new byte[16 * 1024];
6968 while (true) {
6969 int numRead;
6970 try {
6971 numRead = input.read(buffer);
6972 } catch (IOException e) {
6973 try {
6974 fd.checkError();
6975 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
6976 null);
6977 } catch (IOException e1) {
6978 // This means that the other side closed explicitly with an error. If this
6979 // happens, log and ignore.
6980 loge("Remote end of call composer picture pipe closed: " + e1);
6981 }
6982 break;
6983 }
6984 if (numRead == -1) {
6985 readUntilEnd = true;
6986 break;
6987 }
6988 totalBytesRead += numRead;
6989 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
6990 loge("Too many bytes read for call composer picture: " + totalBytesRead);
6991 try {
6992 input.close();
6993 } catch (IOException e) {
6994 // ignore
6995 }
6996 break;
6997 }
6998 output.write(buffer, 0, numRead);
6999 }
7000 // Generally, the remote end will close the file descriptors. The only case where we
7001 // close is above, where the picture size is too big.
7002
7003 try {
7004 fd.checkError();
7005 } catch (IOException e) {
7006 loge("Remote end for call composer closed with an error: " + e);
7007 return;
7008 }
7009
7010 // TODO: pass along the bytes read to the carrier somehow
7011
7012 ParcelUuid result = new ParcelUuid(UUID.randomUUID());
7013 // TODO: cache this uuid that's been associated with the picture
7014 Bundle outputResult = new Bundle();
7015 outputResult.putParcelable(TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, result);
7016 callback.send(-1, outputResult);
7017 });
7018 }
7019
7020 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007021 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007022 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007027 ImsManager.getInstance(defaultPhone.getContext(),
7028 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007032 }
7033
7034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007035 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007036 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7038 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007039 return false;
7040 }
Svet Ganovb320e182015-04-16 12:30:10 -07007041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 // Check the user preference and the system-level IMS setting. Even if the user has
7045 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7046 // In the long run, we may instead need to check if there exists a connection service
7047 // which can support video calling.
7048 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007049 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 return imsManager.isVtEnabledByPlatform()
7051 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7052 && imsManager.isVtEnabledByUser();
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007056 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007057
Andrew Leea1239f22015-03-02 17:44:07 -08007058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007059 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7060 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007062 mApp, subId, callingPackage, callingFeatureId,
7063 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 return false;
7065 }
7066
7067 final long identity = Binder.clearCallingIdentity();
7068 try {
7069 CarrierConfigManager configManager =
7070 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007071 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
Andrew Leea1239f22015-03-02 17:44:07 -08007076 }
7077
7078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007079 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007081 mApp, subId, callingPackage, callingFeatureId, "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_WORLD_PHONE_BOOL);
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
Andrew Leea1239f22015-03-02 17:44:07 -08007094 }
7095
Andrew Lee9431b832015-03-09 18:46:45 -07007096 @Override
7097 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007098 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007099 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007100 }
7101
7102 @Override
7103 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 final long identity = Binder.clearCallingIdentity();
7105 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007106 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
Andrew Lee9431b832015-03-09 18:46:45 -07007110 }
7111
Hall Liuf6668912018-10-31 17:05:23 -07007112 /**
7113 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7114 * support for the feature and device firmware support.
7115 *
7116 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7117 */
7118 @Override
7119 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 final Phone phone = getPhone(subscriptionId);
7122 if (phone == null) {
7123 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7124 return false;
7125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007127 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7129 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007130 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 return isCarrierSupported && isDeviceSupported;
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
Hall Liu98187582018-01-22 19:15:32 -08007135 }
7136
Hall Liuf6668912018-10-31 17:05:23 -07007137 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007138 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7139 * RTT setting, will return true if the device and carrier both support RTT.
7140 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007141 */
7142 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 final long identity = Binder.clearCallingIdentity();
7144 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007145 boolean isRttSupported = isRttSupported(subscriptionId);
7146 boolean isUserRttSettingOn = Settings.Secure.getInt(
7147 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7148 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7149 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7150 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007154 }
7155
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007156 @Deprecated
7157 @Override
7158 public String getDeviceId(String callingPackage) {
7159 return getDeviceIdWithFeature(callingPackage, null);
7160 }
7161
Sanket Padawe7310cc72015-01-14 09:53:20 -08007162 /**
7163 * Returns the unique device ID of phone, for example, the IMEI for
7164 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7165 *
7166 * <p>Requires Permission:
7167 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7168 */
7169 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007170 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007171 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007173 return null;
7174 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007175 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007176 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007177 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007178 return null;
7179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180
7181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 return phone.getDeviceId();
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007187 }
7188
Ping Sunc67b7c22016-03-02 19:16:45 +08007189 /**
7190 * {@hide}
7191 * Returns the IMS Registration Status on a particular subid
7192 *
7193 * @param subId
7194 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007195 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007196 Phone phone = getPhone(subId);
7197 if (phone != null) {
7198 return phone.isImsRegistered();
7199 } else {
7200 return false;
7201 }
7202 }
7203
Santos Cordon7a1885b2015-02-03 11:15:19 -08007204 @Override
7205 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007212 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007213
Tyler Gunnf70ed162019-04-03 15:28:53 -07007214 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007215 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007216 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007218 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007219 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7220 }
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
7223 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
7227 }
7228
7229 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007230 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007231 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7232 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007233 final long identity = Binder.clearCallingIdentity();
7234 try {
7235 Phone phone = getPhone(subscriptionId);
7236 if (phone == null) {
7237 return null;
7238 }
7239 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
7243 }
7244
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007245 /**
7246 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007247 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007248 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 final long identity = Binder.clearCallingIdentity();
7250 try {
7251 Phone phone = getPhone(subId);
7252 if (phone != null) {
7253 return phone.isWifiCallingEnabled();
7254 } else {
7255 return false;
7256 }
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007259 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007260 }
7261
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007262 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007263 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007264 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007265 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 Phone phone = getPhone(subId);
7269 if (phone != null) {
7270 return phone.isVideoEnabled();
7271 } else {
7272 return false;
7273 }
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007276 }
7277 }
7278
7279 /**
7280 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7281 * defined in {@link ImsRegistrationImplBase}.
7282 */
7283 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(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.getImsRegistrationTech();
7289 } else {
7290 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7291 }
7292 } finally {
7293 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007294 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007295 }
7296
Stuart Scott8eef64f2015-04-08 15:13:54 -07007297 @Override
7298 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007299 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007300 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7301 return;
7302 }
7303
Svet Ganovcc087f82015-05-12 20:35:54 -07007304 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007305
Svet Ganovcc087f82015-05-12 20:35:54 -07007306 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007307 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7308 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007309 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007310 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007311 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007312 setAllowedNetworkTypesForReason(subId,
7313 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7314 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7315 setAllowedNetworkTypesForReason(subId,
7316 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7317 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7318 setAllowedNetworkTypesForReason(subId,
7319 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7320 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007321 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7322 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007323 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007324 // There has been issues when Sms raw table somehow stores orphan
7325 // fragments. They lead to garbled message when new fragments come
7326 // in and combined with those stale ones. In case this happens again,
7327 // user can reset all network settings which will clean up this table.
7328 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007329 // Clean up IMS settings as well here.
7330 int slotId = getSlotIndex(subId);
7331 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7332 ImsManager.getInstance(mApp, slotId).factoryReset();
7333 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007334
7335 // Erase modem config if erase modem on network setting is enabled.
7336 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7337 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7338 if (configValue != null && Boolean.parseBoolean(configValue)) {
7339 sendEraseModemConfig(getDefaultPhone());
7340 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007341 } finally {
7342 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007343 }
7344 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007345
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007346 private void cleanUpSmsRawTable(Context context) {
7347 ContentResolver resolver = context.getContentResolver();
7348 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7349 resolver.delete(uri, null, null);
7350 }
7351
Narayan Kamath1c496c22015-04-16 14:40:19 +01007352 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007353 public String getSimLocaleForSubscriber(int subId) {
7354 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7355 final Phone phone = getPhone(subId);
7356 if (phone == null) {
7357 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007358 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
chen xu5d3637b2019-01-21 23:31:38 -08007362 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007363 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007364 if (info == null) {
7365 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7366 return null;
7367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 // Try and fetch the locale from the carrier properties or from the SIM language
7369 // preferences (EF-PL and EF-LI)...
7370 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007372 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7373 if (localeFromDefaultSim != null) {
7374 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7375 if (DBG) log("Using locale from subId: " + subId + " locale: "
7376 + localeFromDefaultSim);
7377 return localeFromDefaultSim.toLanguageTag();
7378 } else {
7379 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 }
7381 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 // The SIM language preferences only store a language (e.g. fr = French), not an
7384 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7385 // the SIM and carrier preferences does not include a country we add the country
7386 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007387 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007389 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 return mccLocale.toLanguageTag();
7391 }
7392
7393 if (DBG) log("No locale found - returning null");
7394 return null;
7395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007398 }
7399
7400 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007401 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007402 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007403 }
7404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 /**
7406 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7407 */
7408 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007409 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007410 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007411 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007412
Chenjie Yu1ba97252018-01-11 18:16:20 -08007413 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007414 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007415
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007416 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007417 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7418 * representing the state of the modem.
7419 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007420 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7421 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007422 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007423 */
7424 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007425 public void requestModemActivityInfo(ResultReceiver result) {
7426 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007427 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428
7429 final long identity = Binder.clearCallingIdentity();
7430 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007431 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007434 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007435 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007436
Siddharth Rayb8114062018-06-17 15:02:38 -07007437 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7438 // less than total activity duration.
7439 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7440 if (info == null) {
7441 return false;
7442 }
7443 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007444 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7445 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7446
Siddharth Rayb8114062018-06-17 15:02:38 -07007447 return (info.isValid()
7448 && (info.getSleepTimeMillis() <= activityDurationMs)
7449 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007450 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007451 && (totalTxTimeMs <= activityDurationMs));
7452 }
7453
Jack Yu85bd38a2015-11-09 11:34:32 -08007454 /**
7455 * {@hide}
7456 * Returns the service state information on specified subscription.
7457 */
7458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007459 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7460 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007463 return null;
7464 }
7465
Hall Liuf19c44f2018-11-27 14:38:17 -08007466 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7467 LocationAccessPolicy.checkLocationPermission(mApp,
7468 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7469 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007470 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007471 .setCallingPid(Binder.getCallingPid())
7472 .setCallingUid(Binder.getCallingUid())
7473 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007474 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007475 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007476 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7477 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007478 .build());
7479
7480 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7481 LocationAccessPolicy.checkLocationPermission(mApp,
7482 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7483 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007484 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007485 .setCallingPid(Binder.getCallingPid())
7486 .setCallingUid(Binder.getCallingUid())
7487 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007488 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007489 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007490 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7491 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007492 .build());
7493 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7494 boolean hasFinePermission =
7495 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7496 boolean hasCoarsePermission =
7497 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7498
Jack Yu479f40e2020-10-27 21:29:25 -07007499 final Phone phone = getPhone(subId);
7500 if (phone == null) {
7501 return null;
7502 }
7503
Jordan Liu0f2bc442020-11-18 16:47:37 -08007504 final long identity = Binder.clearCallingIdentity();
7505
Jack Yu479f40e2020-10-27 21:29:25 -07007506 boolean isCallingPackageDataService = phone.getDataServicePackages()
7507 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007509 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7510 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7511 Rlog.d(LOG_TAG,
7512 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7513 return null;
7514 }
7515
Hall Liuf19c44f2018-11-27 14:38:17 -08007516 ServiceState ss = phone.getServiceState();
7517
7518 // Scrub out the location info in ServiceState depending on what level of access
7519 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007520 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007521 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7522 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007526 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007527
7528 /**
7529 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7530 *
7531 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7532 * voicemail ringtone.
7533 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7534 * PhoneAccount.
7535 */
7536 @Override
7537 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7541 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007549 }
7550
7551 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007552 * Sets the per-account voicemail ringtone.
7553 *
7554 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7555 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7556 *
7557 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7558 * voicemail ringtone.
7559 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7560 * PhoneAccount.
7561 */
7562 @Override
7563 public void setVoicemailRingtoneUri(String callingPackage,
7564 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007565 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007567 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7568 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7570 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7571 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7577 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 }
7580 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007583 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007584 }
7585
7586 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007587 * Returns whether vibration is set for voicemail notification in Phone settings.
7588 *
7589 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7590 * voicemail vibration setting.
7591 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7592 */
7593 @Override
7594 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7598 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007606 }
7607
Youhan Wange64578a2016-05-02 15:32:42 -07007608 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007609 * Sets the per-account voicemail vibration.
7610 *
7611 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7612 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7613 *
7614 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7615 * voicemail vibration setting.
7616 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7617 * specific PhoneAccount.
7618 */
7619 @Override
7620 public void setVoicemailVibrationEnabled(String callingPackage,
7621 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007622 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007624 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7625 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7627 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7628 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007629 }
7630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7634 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007635 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 }
7637 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007640 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007641 }
7642
7643 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007644 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7645 *
7646 * @throws SecurityException if the caller does not have the required permission
7647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007648 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007649 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007650 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007651 }
7652
7653 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007654 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7655 * permission.
7656 *
7657 * @throws SecurityException if the caller does not have the required permission
7658 */
7659 private void enforceSendSmsPermission() {
7660 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7661 }
7662
7663 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007664 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007665 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007666 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007667 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007668 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007672 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 if (componentName == null) {
7674 throw new SecurityException(
7675 "Caller not current active visual voicemail package[null]");
7676 }
7677 String vvmPackage = componentName.getPackageName();
7678 if (!callingPackage.equals(vvmPackage)) {
7679 throw new SecurityException("Caller not current active visual voicemail package["
7680 + vvmPackage + "]");
7681 }
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007684 }
7685 }
7686
7687 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007688 * Return the application ID for the app type.
7689 *
7690 * @param subId the subscription ID that this request applies to.
7691 * @param appType the uicc app type.
7692 * @return Application ID for specificied app type, or null if no uicc.
7693 */
7694 @Override
7695 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007696 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007697 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698
7699 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007700 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 if (phone == null) {
7702 return null;
7703 }
7704 String aid = null;
7705 try {
7706 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7707 .getApplicationByType(appType).getAid();
7708 } catch (Exception e) {
7709 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7710 }
7711 return aid;
7712 } finally {
7713 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007714 }
Youhan Wange64578a2016-05-02 15:32:42 -07007715 }
7716
Youhan Wang4001d252016-05-11 10:29:41 -07007717 /**
7718 * Return the Electronic Serial Number.
7719 *
7720 * @param subId the subscription ID that this request applies to.
7721 * @return ESN or null if error.
7722 */
7723 @Override
7724 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007725 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007726 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727
7728 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007729 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 if (phone == null) {
7731 return null;
7732 }
7733 String esn = null;
7734 try {
7735 esn = phone.getEsn();
7736 } catch (Exception e) {
7737 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7738 }
7739 return esn;
7740 } finally {
7741 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007742 }
Youhan Wang4001d252016-05-11 10:29:41 -07007743 }
7744
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007745 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007746 * Return the Preferred Roaming List Version.
7747 *
7748 * @param subId the subscription ID that this request applies to.
7749 * @return PRLVersion or null if error.
7750 */
7751 @Override
7752 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007753 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007754 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755
7756 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007757 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 if (phone == null) {
7759 return null;
7760 }
7761 String cdmaPrlVersion = null;
7762 try {
7763 cdmaPrlVersion = phone.getCdmaPrlVersion();
7764 } catch (Exception e) {
7765 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7766 }
7767 return cdmaPrlVersion;
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007770 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007771 }
7772
7773 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007774 * Get snapshot of Telephony histograms
7775 * @return List of Telephony histograms
7776 * @hide
7777 */
7778 @Override
7779 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7781 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782
7783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 return RIL.getTelephonyRILTimingHistograms();
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007789 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007790
7791 /**
7792 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007793 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7794 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007795 * Require system privileges. In the future we may add this to carrier APIs.
7796 *
Michele Berionne482f8202018-11-27 18:57:59 -08007797 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007798 */
7799 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007800 @TelephonyManager.SetCarrierRestrictionResult
7801 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007802 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007803 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007804
Michele Berionne482f8202018-11-27 18:57:59 -08007805 if (carrierRestrictionRules == null) {
7806 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007807 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 final long identity = Binder.clearCallingIdentity();
7810 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007811 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007812 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 } finally {
7814 Binder.restoreCallingIdentity(identity);
7815 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007816 }
7817
7818 /**
7819 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007820 * Get the allowed carrier list and the excluded carrier list, including the priority between
7821 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007822 * Require system privileges. In the future we may add this to carrier APIs.
7823 *
Michele Berionne482f8202018-11-27 18:57:59 -08007824 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007825 */
7826 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007827 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007828 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007829 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007833 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7834 if (response instanceof CarrierRestrictionRules) {
7835 return (CarrierRestrictionRules) response;
7836 }
7837 // Response is an Exception of some kind,
7838 // which is signalled to the user as a NULL retval
7839 return null;
7840 } catch (Exception e) {
7841 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7842 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007846 }
7847
fionaxu59545b42016-05-25 15:53:37 -07007848 /**
fionaxu59545b42016-05-25 15:53:37 -07007849 * Action set from carrier signalling broadcast receivers to enable/disable radio
7850 * @param subId the subscription ID that this action applies to.
7851 * @param enabled control enable or disable radio.
7852 * {@hide}
7853 */
7854 @Override
7855 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7856 enforceModifyPermission();
7857 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858
7859 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007860 if (phone == null) {
7861 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7862 return;
7863 }
7864 try {
7865 phone.carrierActionSetRadioEnabled(enabled);
7866 } catch (Exception e) {
7867 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 } finally {
7869 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007870 }
7871 }
7872
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007873 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007874 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7875 * network status based on which carrier apps could apply actions accordingly,
7876 * enable/disable default url handler for example.
7877 *
7878 * @param subId the subscription ID that this action applies to.
7879 * @param report control start/stop reporting the default network status.
7880 * {@hide}
7881 */
7882 @Override
7883 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7884 enforceModifyPermission();
7885 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886
7887 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007888 if (phone == null) {
7889 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7890 return;
7891 }
7892 try {
7893 phone.carrierActionReportDefaultNetworkStatus(report);
7894 } catch (Exception e) {
7895 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 } finally {
7897 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007898 }
7899 }
7900
7901 /**
fionaxud9622282017-07-17 17:51:30 -07007902 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7903 * @param subId the subscription ID that this action applies to.
7904 * {@hide}
7905 */
7906 @Override
7907 public void carrierActionResetAll(int subId) {
7908 enforceModifyPermission();
7909 final Phone phone = getPhone(subId);
7910 if (phone == null) {
7911 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7912 return;
7913 }
7914 try {
7915 phone.carrierActionResetAll();
7916 } catch (Exception e) {
7917 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7918 }
7919 }
7920
7921 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007922 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7923 * bug report is being generated.
7924 */
7925 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007926 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007927 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7928 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007929 writer.println("Permission Denial: can't dump Phone from pid="
7930 + Binder.getCallingPid()
7931 + ", uid=" + Binder.getCallingUid()
7932 + "without permission "
7933 + android.Manifest.permission.DUMP);
7934 return;
7935 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007936 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007937 }
Jack Yueb89b242016-06-22 13:27:47 -07007938
Brad Ebingerdac2f002018-04-03 15:17:52 -07007939 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007940 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7941 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7942 @NonNull String[] args) {
7943 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7944 this, in.getFileDescriptor(), out.getFileDescriptor(),
7945 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007946 }
7947
Jack Yueb89b242016-06-22 13:27:47 -07007948 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007949 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007950 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007951 * @param reason the reason the data enable change is taking place
7952 * @param enabled True if enabling the data, otherwise disabling.
7953 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007954 */
7955 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007956 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007957 boolean enabled) {
7958 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7959 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7960 try {
7961 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007962 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007963 } catch (SecurityException se) {
7964 enforceModifyPermission();
7965 }
7966 } else {
7967 enforceModifyPermission();
7968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969
7970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 Phone phone = getPhone(subId);
7973 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007974 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7975 phone.carrierActionSetMeteredApnsEnabled(enabled);
7976 } else {
7977 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979 }
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007982 }
7983 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007984
7985 /**
7986 * Get Client request stats
7987 * @return List of Client Request Stats
7988 * @hide
7989 */
7990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007991 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7992 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007994 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007995 return null;
7996 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007997 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 final long identity = Binder.clearCallingIdentity();
8000 try {
8001 if (phone != null) {
8002 return phone.getClientRequestStats();
8003 }
8004
8005 return null;
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008009 }
8010
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008011 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008012 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008013 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008014 }
Jack Yueb4124c2017-02-16 15:32:43 -08008015
8016 /**
Grace Chen70990072017-03-24 17:21:30 -07008017 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008018 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008019 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008020 * @param state State of SIM (power down, power up, pass through)
8021 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8022 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8023 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008024 *
8025 **/
8026 @Override
Grace Chen70990072017-03-24 17:21:30 -07008027 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008028 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008029 Phone phone = PhoneFactory.getPhone(slotIndex);
8030
vagdeviaf9a5b92018-08-15 16:01:53 -07008031 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 final long identity = Binder.clearCallingIdentity();
8034 try {
8035 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008036 phone.setSimPowerState(state, null, workSource);
8037 }
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
8041 }
8042
8043 /**
8044 * Set SIM card power state.
8045 *
8046 * @param slotIndex SIM slot id.
8047 * @param state State of SIM (power down, power up, pass through)
8048 * @param callback callback to trigger after success or failure
8049 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8050 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8051 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8052 *
8053 **/
8054 @Override
8055 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8056 IIntegerConsumer callback) {
8057 enforceModifyPermission();
8058 Phone phone = PhoneFactory.getPhone(slotIndex);
8059
8060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8061
8062 final long identity = Binder.clearCallingIdentity();
8063 try {
8064 if (phone != null) {
8065 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8066 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 }
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008070 }
8071 }
Shuo Qiandd210312017-04-12 22:11:33 +00008072
Tyler Gunn65d45c22017-06-05 11:22:26 -07008073 private boolean isUssdApiAllowed(int subId) {
8074 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008075 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008076 if (configManager == null) {
8077 return false;
8078 }
8079 PersistableBundle pb = configManager.getConfigForSubId(subId);
8080 if (pb == null) {
8081 return false;
8082 }
8083 return pb.getBoolean(
8084 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8085 }
8086
Shuo Qiandd210312017-04-12 22:11:33 +00008087 /**
8088 * Check if phone is in emergency callback mode
8089 * @return true if phone is in emergency callback mode
8090 * @param subId sub id
8091 */
goneil9c5f4872017-12-05 14:07:56 -08008092 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008093 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008094 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008095 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096
8097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 if (phone != null) {
8100 return phone.isInEcm();
8101 } else {
8102 return false;
8103 }
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008106 }
8107 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008108
8109 /**
8110 * Get the current signal strength information for the given subscription.
8111 * Because this information is not updated when the device is in a low power state
8112 * it should not be relied-upon to be current.
8113 * @param subId Subscription index
8114 * @return the most recent cached signal strength info from the modem
8115 */
8116 @Override
8117 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 Phone p = getPhone(subId);
8121 if (p == null) {
8122 return null;
8123 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 return p.getSignalStrength();
8126 } finally {
8127 Binder.restoreCallingIdentity(identity);
8128 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008129 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008130
Pengquan Meng77b7f132018-08-22 14:49:57 -07008131 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008132 * Get the current modem radio state for the given slot.
8133 * @param slotIndex slot index.
8134 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008135 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008136 * @return the current radio power state from the modem
8137 */
8138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008139 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008140 Phone phone = PhoneFactory.getPhone(slotIndex);
8141 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8143 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008144 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8145 }
8146
8147 final long identity = Binder.clearCallingIdentity();
8148 try {
8149 return phone.getRadioPowerState();
8150 } finally {
8151 Binder.restoreCallingIdentity(identity);
8152 }
8153 }
8154 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8155 }
8156
8157 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008158 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8159 *
8160 * <p>Requires one of the following permissions:
8161 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8162 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8163 * privileges.
8164 *
8165 * @param subId subscription id
8166 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8167 * {@code false}.
8168 */
8169 @Override
8170 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008171 try {
8172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8173 null);
8174 } catch (Exception e) {
8175 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8176 mApp, subId, "isDataRoamingEnabled");
8177 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008178
Pengquan Menga1bb6272018-09-06 09:59:22 -07008179 boolean isEnabled = false;
8180 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008181 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008182 Phone phone = getPhone(subId);
8183 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008184 } finally {
8185 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008186 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008187 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008188 }
8189
8190
8191 /**
8192 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8193 *
8194 * <p> Requires permission:
8195 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8196 * privileges.
8197 *
8198 * @param subId subscription id
8199 * @param isEnabled {@code true} means enable, {@code false} means disable.
8200 */
8201 @Override
8202 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8204 mApp, subId, "setDataRoamingEnabled");
8205
Pengquan Menga1bb6272018-09-06 09:59:22 -07008206 final long identity = Binder.clearCallingIdentity();
8207 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008208 Phone phone = getPhone(subId);
8209 if (phone != null) {
8210 phone.setDataRoamingEnabled(isEnabled);
8211 }
8212 } finally {
8213 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008214 }
8215 }
8216
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008217 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008218 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008219 TelephonyPermissions
8220 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008221 mApp, subId, "isManualNetworkSelectionAllowed");
8222
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008223 boolean isAllowed = true;
8224 final long identity = Binder.clearCallingIdentity();
8225 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008226 Phone phone = getPhone(subId);
8227 if (phone != null) {
8228 isAllowed = phone.isCspPlmnEnabled();
8229 }
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
8232 }
8233 return isAllowed;
8234 }
8235
8236 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008237 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008238 // Verify that tha callingPackage belongs to the calling UID
8239 mApp.getSystemService(AppOpsManager.class)
8240 .checkPackage(Binder.getCallingUid(), callingPackage);
8241
Jordan Liu1e142fc2019-04-22 15:10:43 -07008242 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008243 try {
8244 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008245 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008246 } catch (SecurityException e) {
8247 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8248 // has carrier privileges on an active UICC
8249 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8250 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008251 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008252 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008253 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008254
8255 final long identity = Binder.clearCallingIdentity();
8256 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008257 UiccController uiccController = UiccController.getInstance();
8258 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008259 if (hasReadPermission) {
8260 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008261 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008262
8263 // Remove private info if the caller doesn't have access
8264 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8265 for (UiccCardInfo cardInfo : cardInfos) {
8266 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8267 // is available
8268 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8269 if (card == null || card.getUiccProfile() == null) {
8270 // assume no access if the card or profile is unavailable
8271 filteredInfos.add(cardInfo.getUnprivileged());
8272 continue;
8273 }
8274 UiccProfile profile = card.getUiccProfile();
8275 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8276 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8277 filteredInfos.add(cardInfo);
8278 } else {
8279 filteredInfos.add(cardInfo.getUnprivileged());
8280 }
8281 }
8282 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
8287
8288 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008289 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008290 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8295 if (slots == null) {
8296 Rlog.i(LOG_TAG, "slots is null.");
8297 return null;
8298 }
8299
8300 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8301 for (int i = 0; i < slots.length; i++) {
8302 UiccSlot slot = slots[i];
8303 if (slot == null) {
8304 continue;
8305 }
8306
Jordan Liu7be7e652019-05-06 18:55:02 +00008307 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 UiccCard card = slot.getUiccCard();
8309 if (card != null) {
8310 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008311 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008312 cardId = slot.getEid();
8313 if (TextUtils.isEmpty(cardId)) {
8314 cardId = slot.getIccId();
8315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 }
8317
Jordan Liu857451f2019-05-09 16:35:35 -07008318 if (cardId != null) {
8319 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8320 // if cardId is an EID, it's all digits so this is fine
8321 cardId = IccUtils.stripTrailingFs(cardId);
8322 }
8323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 int cardState = 0;
8325 switch (slot.getCardState()) {
8326 case CARDSTATE_ABSENT:
8327 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8328 break;
8329 case CARDSTATE_PRESENT:
8330 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8331 break;
8332 case CARDSTATE_ERROR:
8333 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8334 break;
8335 case CARDSTATE_RESTRICTED:
8336 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8337 break;
8338 default:
8339 break;
8340
8341 }
8342
8343 infos[i] = new UiccSlotInfo(
8344 slot.isActive(),
8345 slot.isEuicc(),
8346 cardId,
8347 cardState,
8348 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008349 slot.isExtendedApduSupported(),
8350 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 }
8352 return infos;
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008355 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008356 }
8357
8358 @Override
8359 public boolean switchSlots(int[] physicalSlots) {
8360 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
8364 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8365 } finally {
8366 Binder.restoreCallingIdentity(identity);
8367 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008368 }
Jack Yu4c988042018-02-27 15:30:01 -08008369
8370 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008371 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008372 final long identity = Binder.clearCallingIdentity();
8373 try {
8374 return UiccController.getInstance().getCardIdForDefaultEuicc();
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
8377 }
8378 }
8379
Pengquan Meng85728fb2018-03-12 16:31:21 -07008380 /**
goneil47ffb6e2018-04-06 15:40:58 -07008381 * A test API to reload the UICC profile.
8382 *
8383 * <p>Requires that the calling app has permission
8384 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8385 * @hide
8386 */
8387 @Override
8388 public void refreshUiccProfile(int subId) {
8389 enforceModifyPermission();
8390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 Phone phone = getPhone(subId);
8394 if (phone == null) {
8395 return;
8396 }
8397 UiccCard uiccCard = phone.getUiccCard();
8398 if (uiccCard == null) {
8399 return;
8400 }
8401 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8402 if (uiccProfile == null) {
8403 return;
8404 }
8405 uiccProfile.refresh();
8406 } finally {
8407 Binder.restoreCallingIdentity(identity);
8408 }
8409 }
8410
8411 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008412 * Returns false if the mobile data is disabled by default, otherwise return true.
8413 */
8414 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008415 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008416 }
8417
8418 /**
8419 * Returns true if the data roaming is enabled by default, i.e the system property
8420 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8421 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8422 */
8423 private boolean getDefaultDataRoamingEnabled(int subId) {
8424 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008425 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008426 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008427 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8428 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8429 return isDataRoamingEnabled;
8430 }
8431
8432 /**
8433 * Returns the default network type for the given {@code subId}, if the default network type is
8434 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8435 */
8436 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008437 List<Integer> list = TelephonyProperties.default_network();
8438 int phoneId = mSubscriptionController.getPhoneId(subId);
8439 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8440 return list.get(phoneId);
8441 }
8442 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008443 }
fionaxua13278b2018-03-21 00:08:13 -07008444
8445 @Override
8446 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008447 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 final Phone phone = getPhone(subId);
8453 if (phone == null) {
8454 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8455 return;
8456 }
chen xueaba88a2019-03-15 13:15:10 -07008457 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8458 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008459 if (carrierPrivilegeRules == null) {
8460 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8461 } else {
8462 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 } finally {
8465 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008466 }
fionaxua13278b2018-03-21 00:08:13 -07008467 }
8468
8469 @Override
8470 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008471 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472
8473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 final Phone phone = getPhone(subId);
8476 if (phone == null) {
8477 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8478 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8479 }
8480 return phone.getCarrierIdListVersion();
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008483 }
fionaxua13278b2018-03-21 00:08:13 -07008484 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008485
8486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008487 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8488 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008490 mApp, subId, callingPackage, callingFeatureId,
8491 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008492 return -1;
8493 }
8494
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
8500 }
8501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008502
8503 @Override
8504 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008505 TelephonyPermissions
8506 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008507 mApp, subId, "getCdmaRoamingMode");
8508
8509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
8515 }
8516
8517 @Override
8518 public boolean setCdmaRoamingMode(int subId, int mode) {
8519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8520 mApp, subId, "setCdmaRoamingMode");
8521
8522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
8528 }
8529
8530 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008531 public int getCdmaSubscriptionMode(int subId) {
8532 TelephonyPermissions
8533 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8534 mApp, subId, "getCdmaSubscriptionMode");
8535
8536 final long identity = Binder.clearCallingIdentity();
8537 try {
8538 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
8542 }
8543
8544 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008545 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8547 mApp, subId, "setCdmaSubscriptionMode");
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008556
sqianc5eccab2018-10-19 18:46:41 -07008557 @Override
sqian8c685422019-02-22 15:55:18 -08008558 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008559 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008561 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8562 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008563 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8564 }
8565 final long identity = Binder.clearCallingIdentity();
8566 try {
sqian854d44b2018-12-12 16:48:18 -08008567 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8568 for (Phone phone: PhoneFactory.getPhones()) {
8569 if (phone.getEmergencyNumberTracker() != null
8570 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8571 emergencyNumberListInternal.put(
8572 phone.getSubId(),
8573 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8574 }
sqian11b7a0e2018-12-05 18:48:28 -08008575 }
sqian854d44b2018-12-12 16:48:18 -08008576 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
sqianc5eccab2018-10-19 18:46:41 -07008580 }
8581
8582 @Override
sqian8c685422019-02-22 15:55:18 -08008583 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008584 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008585 if (!exactMatch) {
8586 TelephonyPermissions
8587 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008588 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008589 }
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
sqian854d44b2018-12-12 16:48:18 -08008592 for (Phone phone: PhoneFactory.getPhones()) {
8593 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008594 && phone.getEmergencyNumberTracker()
8595 .isEmergencyNumber(number, exactMatch)) {
8596 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008597 }
sqian11b7a0e2018-12-05 18:48:28 -08008598 }
8599 return false;
8600 } finally {
8601 Binder.restoreCallingIdentity(identity);
8602 }
8603 }
8604
sqianf4ca7ed2019-01-15 18:32:07 -08008605 /**
8606 * Update emergency number list for test mode.
8607 */
8608 @Override
8609 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8611 "updateEmergencyNumberListTestMode");
8612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 for (Phone phone: PhoneFactory.getPhones()) {
8616 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8617 if (tracker != null) {
8618 tracker.executeEmergencyNumberTestModeCommand(action, num);
8619 }
8620 }
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625
8626 /**
8627 * Get the full emergency number list for test mode.
8628 */
8629 @Override
8630 public List<String> getEmergencyNumberListTestMode() {
8631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8632 "getEmergencyNumberListTestMode");
8633
8634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 Set<String> emergencyNumbers = new HashSet<>();
8637 for (Phone phone: PhoneFactory.getPhones()) {
8638 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8639 if (tracker != null) {
8640 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8641 emergencyNumbers.add(num.getNumber());
8642 }
8643 }
8644 }
8645 return new ArrayList<>(emergencyNumbers);
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650
chen xud6b45bd2018-10-30 22:27:10 -07008651 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008652 public int getEmergencyNumberDbVersion(int subId) {
8653 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8654
8655 final long identity = Binder.clearCallingIdentity();
8656 try {
8657 final Phone phone = getPhone(subId);
8658 if (phone == null) {
8659 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8660 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8661 }
8662 return phone.getEmergencyNumberDbVersion();
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
8665 }
8666 }
8667
8668 @Override
8669 public void notifyOtaEmergencyNumberDbInstalled() {
8670 enforceModifyPermission();
8671
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 for (Phone phone: PhoneFactory.getPhones()) {
8675 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8676 if (tracker != null) {
8677 tracker.updateOtaEmergencyNumberDatabase();
8678 }
8679 }
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008686 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008687 enforceActiveEmergencySessionPermission();
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 for (Phone phone: PhoneFactory.getPhones()) {
8692 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8693 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008694 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8695 }
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
8701
8702 @Override
8703 public void resetOtaEmergencyNumberDbFilePath() {
8704 enforceActiveEmergencySessionPermission();
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 for (Phone phone: PhoneFactory.getPhones()) {
8709 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8710 if (tracker != null) {
8711 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008712 }
8713 }
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
8719 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008720 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8721 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8722 Phone phone = getPhone(subId);
8723 if (phone == null) {
8724 return null;
8725 }
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
8728 UiccProfile profile = UiccController.getInstance()
8729 .getUiccProfileForPhone(phone.getPhoneId());
8730 if (profile != null) {
8731 return profile.getCertsFromCarrierPrivilegeAccessRules();
8732 }
8733 } finally {
8734 Binder.restoreCallingIdentity(identity);
8735 }
8736 return null;
8737 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008738
8739 /**
8740 * Enable or disable a modem stack.
8741 */
8742 @Override
8743 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8744 enforceModifyPermission();
8745
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 Phone phone = PhoneFactory.getPhone(slotIndex);
8749 if (phone == null) {
8750 return false;
8751 } else {
8752 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
Michelecea4cf22018-12-21 15:00:11 -08008758
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008759 /**
8760 * Whether a modem stack is enabled or not.
8761 */
8762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008763 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8764 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008765 Phone phone = PhoneFactory.getPhone(slotIndex);
8766 if (phone == null) return false;
8767
8768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008769 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8770 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008771 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8772 }
8773
8774 final long identity = Binder.clearCallingIdentity();
8775 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008776 try {
8777 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8778 } catch (NoSuchElementException ex) {
8779 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8780 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
Michelecea4cf22018-12-21 15:00:11 -08008786 @Override
Michele0ea7d782019-03-19 14:58:42 -07008787 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008788 enforceModifyPermission();
8789
8790 final long identity = Binder.clearCallingIdentity();
8791 try {
8792 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008793 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008794 .commit();
8795 } finally {
8796 Binder.restoreCallingIdentity(identity);
8797 }
8798 }
8799
8800 @Override
Michele0ea7d782019-03-19 14:58:42 -07008801 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008802 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008804 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8805 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008806 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008807 }
Michelecea4cf22018-12-21 15:00:11 -08008808
8809 final long identity = Binder.clearCallingIdentity();
8810 try {
Michele0ea7d782019-03-19 14:58:42 -07008811 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008816
Michele0ea7d782019-03-19 14:58:42 -07008817 @TelephonyManager.IsMultiSimSupportedResult
8818 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008819 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8820 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8821 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008822 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8823 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008824 }
8825 // Check if the hardware supports multisim functionality. If usage of multisim is not
8826 // supported by the modem, indicate that it is restricted.
8827 PhoneCapability staticCapability =
8828 mPhoneConfigurationManager.getStaticPhoneCapability();
8829 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008830 loge("isMultiSimSupportedInternal: no static configuration available");
8831 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008832 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008833 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008834 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8835 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008836 }
8837 // Check if support of multiple SIMs is restricted by carrier
8838 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008839 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008840 }
8841
Michele0ea7d782019-03-19 14:58:42 -07008842 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008843 }
8844
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008845 /**
8846 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008847 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8848 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8849 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008850 * @param numOfSims number of active sims we want to switch to
8851 */
8852 @Override
8853 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008854 if (numOfSims == 1) {
8855 enforceModifyPermission();
8856 } else {
8857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8858 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8859 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008860 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008861
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008862 try {
Michele30b57b22019-03-01 12:01:14 -08008863 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008864 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008865 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8866 return;
8867 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008868 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8869 } finally {
8870 Binder.restoreCallingIdentity(identity);
8871 }
8872 }
8873
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008874 @Override
8875 public boolean isApplicationOnUicc(int subId, int appType) {
8876 enforceReadPrivilegedPermission("isApplicationOnUicc");
8877 Phone phone = getPhone(subId);
8878 if (phone == null) {
8879 return false;
8880 }
8881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 UiccCard uiccCard = phone.getUiccCard();
8884 if (uiccCard == null) {
8885 return false;
8886 }
8887 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8888 if (uiccProfile == null) {
8889 return false;
8890 }
8891 if (TelephonyManager.APPTYPE_SIM <= appType
8892 && appType <= TelephonyManager.APPTYPE_ISIM) {
8893 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8894 }
8895 return false;
8896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
8899 }
8900
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008901 /**
chen xub4baa772019-04-03 10:23:41 -07008902 * Get whether making changes to modem configurations will trigger reboot.
8903 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008904 */
8905 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008906 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8907 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008909 mApp, subId, callingPackage, callingFeatureId,
8910 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008911 return false;
8912 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008913 final long identity = Binder.clearCallingIdentity();
8914 try {
8915 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8916 } finally {
8917 Binder.restoreCallingIdentity(identity);
8918 }
8919 }
8920
Nathan Harold29f5f052019-02-15 13:41:57 -08008921 private void updateModemStateMetrics() {
8922 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8923 // TODO: check the state for each modem if the api is ready.
8924 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8925 }
8926
Pengquan Meng3889a572019-01-23 11:16:29 -08008927 @Override
8928 public int[] getSlotsMapping() {
8929 enforceReadPrivilegedPermission("getSlotsMapping");
8930
8931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8934 // All logical slots should have a mapping to a physical slot.
8935 int[] logicalSlotsMapping = new int[phoneCount];
8936 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8937 for (int i = 0; i < slotInfos.length; i++) {
8938 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8939 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8940 }
8941 }
8942 return logicalSlotsMapping;
8943 } finally {
8944 Binder.restoreCallingIdentity(identity);
8945 }
8946 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008947
8948 /**
8949 * Get the IRadio HAL Version
8950 */
8951 @Override
8952 public int getRadioHalVersion() {
8953 Phone phone = getDefaultPhone();
8954 if (phone == null) return -1;
8955 HalVersion hv = phone.getHalVersion();
8956 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8957 return hv.major * 100 + hv.minor;
8958 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008959
8960 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008961 * Get the current calling package name.
8962 * @return the current calling package name
8963 */
8964 @Override
8965 public String getCurrentPackageName() {
8966 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8967 }
8968
8969 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008970 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8971 * corresponding network requests on a subId.
8972 *
8973 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008974 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008975 * 2) APN is un-metered for this subscription, or
8976 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008977 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008978 *
8979 * @return whether data is allowed for a apn type.
8980 *
8981 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008982 */
8983 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008984 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008985 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8986 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008987
8988 // Now that all security checks passes, perform the operation as ourselves.
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 Phone phone = getPhone(subId);
8992 if (phone == null) return false;
8993
Jack Yu41407ee2019-05-13 16:54:09 -07008994 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008995 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009002 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009003 enforceReadPrivilegedPermission("isApnMetered");
9004
9005 // Now that all security checks passes, perform the operation as ourselves.
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subId);
9009 if (phone == null) return true; // By default return true.
9010
Jack Yu41407ee2019-05-13 16:54:09 -07009011 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009016
9017 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009018 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9019 int subscriptionId, IBooleanConsumer resultCallback) {
9020 enforceModifyPermission();
9021 long token = Binder.clearCallingIdentity();
9022 try {
9023 Phone phone = getPhone(subscriptionId);
9024 if (phone == null) {
9025 try {
9026 if (resultCallback != null) {
9027 resultCallback.accept(false);
9028 }
9029 } catch (RemoteException e) {
9030 // ignore
9031 }
9032 return;
9033 }
9034 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9035 Pair.create(specifiers, (x) -> {
9036 try {
9037 if (resultCallback != null) {
9038 resultCallback.accept(x);
9039 }
9040 } catch (RemoteException e) {
9041 // ignore
9042 }
9043 });
9044 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9045 } finally {
9046 Binder.restoreCallingIdentity(token);
9047 }
9048 }
9049
9050 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009051 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9052 TelephonyPermissions
9053 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9054 mApp, subId, "getSystemSelectionChannels");
9055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 List<RadioAccessSpecifier> specifiers =
9059 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9060 null, subId, workSource);
9061 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9062 return specifiers;
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
9066 }
9067
9068 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009069 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009070 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009071 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9072 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9073 if (iccRecords == null) {
9074 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9075 return false;
9076 }
9077 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9078 }
9079
9080 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009081 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9082 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009083 if (callingPackage == null) {
9084 callingPackage = getCurrentPackageName();
9085 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009086 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9087 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009088 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9089 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009090 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9091 }
9092 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9093 Intent intent = new Intent();
9094 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9095 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9096 // Bring up choose default SMS subscription dialog right now
9097 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9098 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9099 mApp.startActivity(intent);
9100 }
chen xud5ca2d52019-05-28 15:20:57 -07009101
9102 @Override
9103 public String getMmsUAProfUrl(int subId) {
9104 //TODO investigate if this API should require proper permission check in R b/133791609
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009107 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9108 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9109 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9110 return carrierUAProfUrl;
9111 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009112 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9113 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
9119 @Override
9120 public String getMmsUserAgent(int subId) {
9121 //TODO investigate if this API should require proper permission check in R b/133791609
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009124 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9125 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9126 if (!TextUtils.isEmpty(carrierUserAgent)) {
9127 return carrierUserAgent;
9128 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009129 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9130 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
9134 }
Jack Yub07d4972019-05-28 16:12:25 -07009135
9136 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009137 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9138 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009139
Jack Yub07d4972019-05-28 16:12:25 -07009140 final long identity = Binder.clearCallingIdentity();
9141 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009142 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009143 if (phone == null) return false;
9144
Hall Liua62f5da2020-09-25 10:42:19 -07009145 switch (policy) {
9146 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9147 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9148 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9149 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9150 default:
9151 throw new IllegalArgumentException(policy + " is not a valid policy");
9152 }
Jack Yub07d4972019-05-28 16:12:25 -07009153 } finally {
9154 Binder.restoreCallingIdentity(identity);
9155 }
9156 }
9157
9158 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009159 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009160 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009161 enforceModifyPermission();
9162
changbettyd5c246e2019-12-24 15:40:37 +08009163 final long identity = Binder.clearCallingIdentity();
9164 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009165 Phone phone = getPhone(subscriptionId);
9166 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009167
Hall Liua62f5da2020-09-25 10:42:19 -07009168 switch (policy) {
9169 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9170 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9171 break;
9172 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9173 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9174 break;
9175 default:
9176 throw new IllegalArgumentException(policy + " is not a valid policy");
9177 }
changbettyd5c246e2019-12-24 15:40:37 +08009178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 }
9182
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009183 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009184 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009185 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9186 * otherwise.
9187 */
9188 @Override
9189 public void setCepEnabled(boolean isCepEnabled) {
9190 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9195 for (Phone phone : PhoneFactory.getPhones()) {
9196 Phone defaultPhone = phone.getImsPhone();
9197 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9198 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9199 ImsPhoneCallTracker imsPhoneCallTracker =
9200 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9201 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9202 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9203 + imsPhone.getMsisdn());
9204 }
9205 }
9206 } finally {
9207 Binder.restoreCallingIdentity(identity);
9208 }
9209 }
allenwtsu46dcc572020-01-08 18:24:03 +08009210
9211 /**
9212 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9213 *
9214 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9215 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9216 * before being read.
9217 */
9218 @Override
9219 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9220 isCompressed) {
9221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9222 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9224 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9225 }
9226 if (!isImsAvailableOnDevice()) {
9227 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9228 "IMS not available on device.");
9229 }
9230
9231 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009232 try {
Hui Wang761a6682020-10-31 05:12:53 +00009233 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009236 }
9237 }
zoey chene02881a2019-12-30 16:11:23 +08009238
9239 @Override
9240 public boolean isIccLockEnabled(int subId) {
9241 enforceReadPrivilegedPermission("isIccLockEnabled");
9242
9243 // Now that all security checks passes, perform the operation as ourselves.
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
9246 Phone phone = getPhone(subId);
9247 if (phone != null && phone.getIccCard() != null) {
9248 return phone.getIccCard().getIccLockEnabled();
9249 } else {
9250 return false;
9251 }
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
9256
9257 /**
9258 * Set the ICC pin lock enabled or disabled.
9259 *
9260 * @return an integer representing the status of IccLock enabled or disabled in the following
9261 * three cases:
9262 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9263 * successfully.
9264 * - Positive number and zero for remaining password attempts.
9265 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9266 *
9267 */
9268 @Override
9269 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9270 enforceModifyPermission();
9271
9272 Phone phone = getPhone(subId);
9273 if (phone == null) {
9274 return 0;
9275 }
9276 // Now that all security checks passes, perform the operation as ourselves.
9277 final long identity = Binder.clearCallingIdentity();
9278 try {
9279 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9280 new Pair<Boolean, String>(enabled, password), phone, null);
9281 return attemptsRemaining;
9282
9283 } catch (Exception e) {
9284 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9285 } finally {
9286 Binder.restoreCallingIdentity(identity);
9287 }
9288 return 0;
9289 }
9290
9291 /**
9292 * Change the ICC password used in ICC pin lock.
9293 *
9294 * @return an integer representing the status of IccLock changed in the following three cases:
9295 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9296 * - Positive number and zero for remaining password attempts.
9297 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9298 *
9299 */
9300 @Override
9301 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9302 enforceModifyPermission();
9303
9304 Phone phone = getPhone(subId);
9305 if (phone == null) {
9306 return 0;
9307 }
9308 // Now that all security checks passes, perform the operation as ourselves.
9309 final long identity = Binder.clearCallingIdentity();
9310 try {
9311 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9312 new Pair<String, String>(oldPassword, newPassword), phone, null);
9313 return attemptsRemaining;
9314
9315 } catch (Exception e) {
9316 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
9320 return 0;
9321 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009322
9323 /**
9324 * Request for receiving user activity notification
9325 */
9326 @Override
9327 public void requestUserActivityNotification() {
9328 if (!mNotifyUserActivity.get()
9329 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9330 mNotifyUserActivity.set(true);
9331 }
9332 }
9333
9334 /**
9335 * Called when userActivity is signalled in the power manager.
9336 * This is safe to call from any thread, with any window manager locks held or not.
9337 */
9338 @Override
9339 public void userActivity() {
9340 // ***************************************
9341 // * Inherited from PhoneWindowManager *
9342 // ***************************************
9343 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9344 // WITH ITS LOCKS HELD.
9345 //
9346 // This code must be VERY careful about the locks
9347 // it acquires.
9348 // In fact, the current code acquires way too many,
9349 // and probably has lurking deadlocks.
9350
9351 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9352 throw new SecurityException("Only the OS may call notifyUserActivity()");
9353 }
9354
9355 if (mNotifyUserActivity.getAndSet(false)) {
9356 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9357 USER_ACTIVITY_NOTIFICATION_DELAY);
9358 }
9359 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009360
9361 @Override
9362 public boolean canConnectTo5GInDsdsMode() {
9363 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9364 }
Jack Yud10cdd42020-09-28 20:28:01 -07009365
9366 @Override
9367 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9368 String callingFeatureId) {
9369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9370 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9371 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9372 }
9373
9374 Phone phone = getPhone(subId);
9375 if (phone == null) {
9376 throw new RuntimeException("phone is not available");
9377 }
9378 // Now that all security checks passes, perform the operation as ourselves.
9379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 return phone.getEquivalentHomePlmns();
9382 } finally {
9383 Binder.restoreCallingIdentity(identity);
9384 }
9385 }
Daniel Bright59e67312020-11-13 11:49:37 -08009386
9387 @Override
9388 public boolean isRadioInterfaceCapabilitySupported(
9389 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9390 RadioInterfaceCapabilities radioInterfaceCapabilities =
9391 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9392 if (radioInterfaceCapabilities == null) {
9393 throw new RuntimeException("radio interface capabilities are not available");
9394 } else {
9395 return radioInterfaceCapabilities.isSupported(capability);
9396 }
9397 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009398
Hui Wang641e81c2020-10-12 12:14:23 -07009399 @Override
9400 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9401 UaSecurityProtocolIdentifier securityProtocol,
9402 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9403 throws RemoteException {
9404 enforceModifyPermission();
9405 if (DBG) {
9406 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9407 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9408 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9409 }
9410
9411 if (!SubscriptionManager.isValidSubscriptionId(subId)
9412 || appType < TelephonyManager.APPTYPE_UNKNOWN
9413 || appType > TelephonyManager.APPTYPE_ISIM
9414 || nafUrl == null || securityProtocol == null || callback == null) {
9415 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9416 if (callback != null) {
9417 try {
9418 callback.onAuthenticationFailure(
9419 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9420 } catch (RemoteException exception) {
9421 log("Fail to notify onAuthenticationFailure due to " + exception);
9422 }
9423 return;
9424 }
9425 }
9426
9427 final long token = Binder.clearCallingIdentity();
9428 try {
9429 getGbaManager(subId).bootstrapAuthenticationRequest(
9430 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9431 forceBootStrapping, callback));
9432 } finally {
9433 Binder.restoreCallingIdentity(token);
9434 }
9435 }
9436
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009437 /**
9438 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9439 * requested radio power state will actually be set. See {@link
9440 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9441 *
9442 * @param subId the subscription ID of the phone requesting to set the radio power state.
9443 * @param enable {@code true} if trying to turn radio on.
9444 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9445 * false}.
9446 */
9447 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9448 Phone phone = getPhone(subId);
9449 if (phone != null) {
9450 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9451 return true;
9452 }
9453 return false;
9454 }
9455
9456 private int handleDataThrottlingRequest(int subId,
9457 DataThrottlingRequest dataThrottlingRequest) {
9458 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9459 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9460 if (!setRadioPowerForThermal(subId, true)) {
9461 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9462 }
9463
9464 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9465
9466 int thermalMitigationResult =
9467 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9468 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9469 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9470 }
9471 return thermalMitigationResult;
9472 }
9473
9474 /**
9475 * Thermal mitigation request to control functionalities at modem.
9476 *
9477 * @param subId the id of the subscription.
9478 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9479 *
9480 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9481 */
9482 @Override
9483 @ThermalMitigationResult
9484 public int sendThermalMitigationRequest(
9485 int subId,
9486 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9487 enforceModifyPermission();
9488
9489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9490 final long identity = Binder.clearCallingIdentity();
9491
9492 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9493 try {
9494 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9495 switch (thermalMitigationAction) {
9496 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9497 thermalMitigationResult =
9498 handleDataThrottlingRequest(subId,
9499 thermalMitigationRequest.getDataThrottlingRequest());
9500 break;
9501 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9502 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9503 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9504 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9505 }
9506
9507 // Ensure that radio is on. If not able to power on due to phone being
9508 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9509 if (!setRadioPowerForThermal(subId, true)) {
9510 thermalMitigationResult =
9511 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9512 break;
9513 }
9514
9515 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9516 false);
9517 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9518 break;
9519 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9520 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9521 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9522 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9523 }
9524
9525 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9526 if (registry != null) {
9527 TelephonyConnectionService service =
9528 registry.getTelephonyConnectionService();
9529 Phone phone = getPhone(subId);
9530 if (phone == null) {
9531 thermalMitigationResult =
9532 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9533 break;
9534 }
9535
9536 if (PhoneConstantConversions.convertCallState(phone.getState())
9537 != TelephonyManager.CALL_STATE_IDLE
9538 || phone.isInEmergencySmsMode() || phone.isInEcm()
9539 || (service != null && service.isEmergencyCallPending())) {
9540 String errorMessage = "Phone state is not valid. call state = "
9541 + PhoneConstantConversions.convertCallState(phone.getState())
9542 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9543 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9544 errorMessage += service == null
9545 ? " TelephonyConnectionService is null"
9546 : " isEmergencyCallPending = "
9547 + service.isEmergencyCallPending();
9548 Log.e(LOG_TAG, errorMessage);
9549 thermalMitigationResult =
9550 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9551 break;
9552 }
9553 } else {
9554 thermalMitigationResult =
9555 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9556 break;
9557 }
9558
9559 // Turn radio off. If not able to power off due to phone being unavailable,
9560 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9561 if (!setRadioPowerForThermal(subId, false)) {
9562 thermalMitigationResult =
9563 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9564 break;
9565 }
9566 thermalMitigationResult =
9567 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9568 break;
9569 default:
9570 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9571 + "not exist. Requested action: " + thermalMitigationAction);
9572 }
9573 } catch (IllegalArgumentException e) {
9574 throw e;
9575 } catch (Exception e) {
9576 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9577 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581
9582 if (DBG) {
9583 log("thermalMitigationRequest returning with thermalMitigationResult: "
9584 + thermalMitigationResult);
9585 }
9586
9587 return thermalMitigationResult;
9588 }
Hui Wang641e81c2020-10-12 12:14:23 -07009589
9590 /**
9591 * Set the GbaService Package Name that Telephony will bind to.
9592 *
9593 * @param subId The sim that the GbaService is associated with.
9594 * @param packageName The name of the package to be replaced with.
9595 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9596 */
9597 @Override
9598 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9599 enforceModifyPermission();
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 return getGbaManager(subId).overrideServicePackage(packageName);
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
9606 }
9607 }
9608
9609 /**
9610 * Return the package name of the currently bound GbaService.
9611 *
9612 * @param subId The sim that the GbaService is associated with.
9613 * @return the package name of the GbaService configuration, null if GBA is not supported.
9614 */
9615 @Override
9616 public String getBoundGbaService(int subId) {
9617 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9618
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 return getGbaManager(subId).getServicePackage();
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 /**
9628 * Set the release time for telephony to unbind GbaService.
9629 *
9630 * @param subId The sim that the GbaService is associated with.
9631 * @param interval The release time to unbind GbaService by millisecond.
9632 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9633 */
9634 @Override
9635 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9636 enforceModifyPermission();
9637
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 return getGbaManager(subId).overrideReleaseTime(interval);
9641 } finally {
9642 Binder.restoreCallingIdentity(identity);
9643 }
9644 }
9645
9646 /**
9647 * Return the release time for telephony to unbind GbaService.
9648 *
9649 * @param subId The sim that the GbaService is associated with.
9650 * @return The release time to unbind GbaService by millisecond.
9651 */
9652 @Override
9653 public int getGbaReleaseTime(int subId) {
9654 enforceReadPrivilegedPermission("getGbaReleaseTime");
9655
9656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 return getGbaManager(subId).getReleaseTime();
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
9661 }
9662 }
9663
9664 private GbaManager getGbaManager(int subId) {
9665 GbaManager instance = GbaManager.getInstance(subId);
9666 if (instance == null) {
9667 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9668 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9669 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9670 }
9671 return instance;
9672 }
Hui Wang761a6682020-10-31 05:12:53 +00009673
9674 /**
9675 * indicate whether the device and the carrier can support
9676 * RCS VoLTE single registration.
9677 */
9678 @Override
9679 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9680 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9681
9682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9683 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9684 }
9685
9686 final long identity = Binder.clearCallingIdentity();
9687 try {
9688 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9689 if (rpm != null) {
9690 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9691 }
9692 return false;
9693 } finally {
9694 Binder.restoreCallingIdentity(identity);
9695 }
9696 }
9697
9698 /**
9699 * Register RCS provisioning callback.
9700 */
9701 @Override
9702 public void registerRcsProvisioningChangedCallback(int subId,
9703 IRcsConfigCallback callback) {
9704 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9705
9706 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9707 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9708 }
9709 if (!isImsAvailableOnDevice()) {
9710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9711 "IMS not available on device.");
9712 }
9713
9714 final long identity = Binder.clearCallingIdentity();
9715 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009716 if (!RcsProvisioningMonitor.getInstance()
9717 .registerRcsProvisioningChangedCallback(subId, callback)) {
9718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9719 "Service not available for the subscription.");
9720 }
Hui Wang761a6682020-10-31 05:12:53 +00009721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
9726 /**
9727 * Unregister RCS provisioning callback.
9728 */
9729 @Override
9730 public void unregisterRcsProvisioningChangedCallback(int subId,
9731 IRcsConfigCallback callback) {
9732 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9733
9734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9736 }
9737 if (!isImsAvailableOnDevice()) {
9738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9739 "IMS not available on device.");
9740 }
9741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009744 RcsProvisioningMonitor.getInstance()
9745 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009746 } finally {
9747 Binder.restoreCallingIdentity(identity);
9748 }
9749 }
9750
9751 /**
9752 * trigger RCS reconfiguration.
9753 */
9754 public void triggerRcsReconfiguration(int subId) {
9755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9756 mApp, subId, "triggerRcsReconfiguration");
9757
9758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9759 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9760 }
9761 if (!isImsAvailableOnDevice()) {
9762 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9763 "IMS not available on device.");
9764 }
9765
9766 final long identity = Binder.clearCallingIdentity();
9767 try {
9768 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 }
9773
9774 /**
9775 * Provide the client configuration parameters of the RCS application.
9776 */
9777 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9779 mApp, subId, "setRcsClientConfiguration");
9780
9781 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9782 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9783 }
9784 if (!isImsAvailableOnDevice()) {
9785 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9786 "IMS not available on device.");
9787 }
9788
9789 final long identity = Binder.clearCallingIdentity();
9790
9791 try {
9792 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9793 if (configBinder == null) {
9794 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9795 } else {
9796 configBinder.setRcsClientConfiguration(rcc);
9797 }
9798 } catch (RemoteException e) {
9799 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9800 } finally {
9801 Binder.restoreCallingIdentity(identity);
9802 }
9803 }
9804
9805 /**
9806 * Overrides the config of RCS VoLTE single registration enabled for the device.
9807 */
9808 @Override
9809 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9811 "setDeviceSingleRegistrationEnabledOverride");
9812 enforceModifyPermission();
9813
9814 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9815 : Boolean.parseBoolean(enabledStr);
9816 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9817 }
9818
9819 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009820 * Sends a device to device communication message. Only usable via shell.
9821 * @param message message to send.
9822 * @param value message value.
9823 */
9824 @Override
9825 public void sendDeviceToDeviceMessage(int message, int value) {
9826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9827 "setCarrierSingleRegistrationEnabledOverride");
9828 enforceModifyPermission();
9829
9830 final long identity = Binder.clearCallingIdentity();
9831 try {
9832 TelephonyConnectionService service =
9833 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9834 if (service == null) {
9835 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9836 return;
9837 }
9838 service.sendTestDeviceToDeviceMessage(message, value);
9839 } finally {
9840 Binder.restoreCallingIdentity(identity);
9841 }
9842 }
9843
9844
9845 /**
Hui Wang761a6682020-10-31 05:12:53 +00009846 * Gets the config of RCS VoLTE single registration enabled for the device.
9847 */
9848 @Override
9849 public boolean getDeviceSingleRegistrationEnabled() {
9850 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9851 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9852 }
9853
9854 /**
9855 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9856 */
9857 @Override
9858 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9860 "setCarrierSingleRegistrationEnabledOverride");
9861 enforceModifyPermission();
9862
9863 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9864 : Boolean.parseBoolean(enabledStr);
9865 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9866 subId, enabled);
9867 }
9868
9869 /**
9870 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9871 */
9872 @Override
9873 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9874 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9875 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9876 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009877
9878 /**
9879 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9880 * their mobile plan.
9881 */
9882 @Override
9883 public String getMobileProvisioningUrl() {
9884 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
9887 return getDefaultPhone().getMobileProvisioningUrl();
9888 } finally {
9889 Binder.restoreCallingIdentity(identity);
9890 }
9891 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009892
9893 @Override
9894 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9895 String callingPackage) {
9896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9897 mApp, subId, "setSignalStrengthUpdateRequest");
9898
9899 final int callingUid = Binder.getCallingUid();
9900 // Verify that tha callingPackage belongs to the calling UID
9901 mApp.getSystemService(AppOpsManager.class)
9902 .checkPackage(callingUid, callingPackage);
9903
9904 validateSignalStrengthUpdateRequest(request, callingUid);
9905
9906 final long identity = Binder.clearCallingIdentity();
9907 try {
9908 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9909 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9910
9911 if (result instanceof IllegalStateException) {
9912 throw (IllegalStateException) result;
9913 }
9914 } finally {
9915 Binder.restoreCallingIdentity(identity);
9916 }
9917 }
9918
9919 @Override
9920 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9921 String callingPackage) {
9922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9923 mApp, subId, "clearSignalStrengthUpdateRequest");
9924
9925 final int callingUid = Binder.getCallingUid();
9926 // Verify that tha callingPackage belongs to the calling UID
9927 mApp.getSystemService(AppOpsManager.class)
9928 .checkPackage(callingUid, callingPackage);
9929
9930 final long identity = Binder.clearCallingIdentity();
9931 try {
9932 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9933 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9934
9935 if (result instanceof IllegalStateException) {
9936 throw (IllegalStateException) result;
9937 }
9938 } finally {
9939 Binder.restoreCallingIdentity(identity);
9940 }
9941 }
9942
9943 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9944 int callingUid) {
9945 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9946 // phone/system process do not have further restriction on request
9947 return;
9948 }
9949
9950 // Applications has restrictions on how to use the request:
9951 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9952 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9953 // This is not system caller which has been checked above
9954 throw new IllegalArgumentException(
9955 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9956 }
9957
9958 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9959 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9960 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9961 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9962 || info.isEnabled()) {
9963 throw new IllegalArgumentException(
9964 "Only system can set hide fields in SignalThresholdInfo");
9965 }
9966
9967 // Thresholds length for each RAN need in range. This has been validated in
9968 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9969 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9970 final int[] thresholds = info.getThresholds();
9971 Objects.requireNonNull(thresholds);
9972 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9973 || thresholds.length
9974 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9975 throw new IllegalArgumentException(
9976 "thresholds length is out of range: " + thresholds.length);
9977 }
9978 }
9979 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009980
9981 /**
9982 * Gets the current phone capability.
9983 *
9984 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
9985 * @return the PhoneCapability which describes the data connection capability of modem.
9986 * It's used to evaluate possible phone config change, for example from single
9987 * SIM device to multi-SIM device.
9988 */
9989 @Override
9990 public PhoneCapability getPhoneCapability() {
9991 enforceReadPrivilegedPermission("getPhoneCapability");
9992 final long identity = Binder.clearCallingIdentity();
9993 try {
9994 return mPhoneConfigurationManager.getCurrentPhoneCapability();
9995 } finally {
9996 Binder.restoreCallingIdentity(identity);
9997 }
9998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009999}