blob: 8d665cb376549ee50eb1886a59dad4428f5ab550 [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;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080094import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080095import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080096import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070097import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800100import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800101import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000102import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700103import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700104import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800105import android.telephony.data.ApnSetting;
106import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700107import android.telephony.gba.GbaAuthRequest;
108import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700109import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000111import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700112import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700113import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800114import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700115import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700117import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000118import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700119import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800120import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800121import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800123import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700126import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800128import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800129
Andrew Lee312e8172014-10-23 17:01:36 -0700130import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800131import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800132import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700133import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700134import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700135import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800136import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800139import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700141import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800142import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800143import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700144import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800146import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800148import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700150import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700151import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700153import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800154import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700155import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700156import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700157import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700158import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700159import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700160import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700161import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800163import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800164import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700166import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800167import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700168import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800169import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700170import com.android.internal.telephony.imsphone.ImsPhone;
171import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800172import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700173import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800175import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700178import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800181import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000182import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800183import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700184import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700185import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800186import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700187import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700188import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800189import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700191import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800192import com.android.services.telephony.TelecomAccountRegistry;
193import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800194import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800195
Hall Liu82694d52020-12-11 18:22:04 -0800196import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700197import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800198import java.io.IOException;
199import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.util.UUID;
212import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800213import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800214import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
216/**
217 * Implementation of the ITelephony interface.
218 */
Santos Cordon117fee72014-05-16 17:56:12 -0700219public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 private static final String LOG_TAG = "PhoneInterfaceManager";
221 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
222 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
225 // Message codes used with mMainThreadHandler
226 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700227 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
228 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700229 private static final int CMD_OPEN_CHANNEL = 9;
230 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
231 private static final int CMD_CLOSE_CHANNEL = 11;
232 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800233 private static final int CMD_NV_READ_ITEM = 13;
234 private static final int EVENT_NV_READ_ITEM_DONE = 14;
235 private static final int CMD_NV_WRITE_ITEM = 15;
236 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
237 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
238 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700239 private static final int CMD_RESET_MODEM_CONFIG = 19;
240 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800241 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
242 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
243 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
244 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800245 private static final int CMD_SEND_ENVELOPE = 25;
246 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000247 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
248 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700249 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
250 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
251 private static final int CMD_EXCHANGE_SIM_IO = 31;
252 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800253 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
254 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700255 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
256 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700257 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
258 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700259 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
260 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
261 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
262 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700263 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
264 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
265 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
266 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700267 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800268 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
269 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000270 private static final int CMD_SWITCH_SLOTS = 50;
271 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700272 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
273 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
274 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
275 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
276 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
277 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
278 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
279 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700280 private static final int CMD_GET_ALL_CELL_INFO = 60;
281 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
282 private static final int CMD_GET_CELL_LOCATION = 62;
283 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700284 private static final int CMD_MODEM_REBOOT = 64;
285 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700286 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
287 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800288 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
289 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700290 private static final int CMD_GET_MODEM_STATUS = 70;
291 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700292 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
293 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700294 private static final int CMD_ERASE_MODEM_CONFIG = 74;
295 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800296 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
297 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
298 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
299 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800300 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
301 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800302 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800303 private static final int CMD_GET_CALL_FORWARDING = 83;
304 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
305 private static final int CMD_SET_CALL_FORWARDING = 85;
306 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
307 private static final int CMD_GET_CALL_WAITING = 87;
308 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
309 private static final int CMD_SET_CALL_WAITING = 89;
310 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700311 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
312 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
313 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
314 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700315 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
316 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800317 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
318 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800319 private static final int CMD_SET_DATA_THROTTLING = 99;
320 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800321 private static final int CMD_SET_SIM_POWER = 101;
322 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800324 // Parameters of select command.
325 private static final int SELECT_COMMAND = 0xA4;
326 private static final int SELECT_P1 = 0x04;
327 private static final int SELECT_P2 = 0;
328 private static final int SELECT_P3 = 0x10;
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 /** The singleton instance. */
331 private static PhoneInterfaceManager sInstance;
332
Wink Saville3ab207e2014-11-20 13:07:20 -0800333 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800335 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700336 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private AppOpsManager mAppOps;
338 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800339 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700341 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Peter Wangdafb9ac2020-01-15 14:13:38 -0800343 /** User Activity */
344 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
346
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700347 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
348
Derek Tan97ebb422014-09-05 16:55:38 -0700349 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
350 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800351 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800352 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700353
Michelecea4cf22018-12-21 15:00:11 -0800354 // String to store multi SIM allowed
355 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
356
Derek Tan740e1672017-06-27 14:56:27 -0700357 // The AID of ISD-R.
358 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
359
yinxub1bed742017-04-17 11:45:04 -0700360 private NetworkScanRequestTracker mNetworkScanRequestTracker;
361
David Kelly5e06a7f2018-03-12 14:10:59 +0000362 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
363 private static final int MANUFACTURER_CODE_LENGTH = 8;
364
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800365 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
366
Derek Tan89e89d42014-07-08 17:00:10 -0700367 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700368 * Experiment flag to enable erase modem config on reset network, default value is false
369 */
370 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
371 "reset_network_erase_modem_config_enabled";
372
373 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700374 * A request object to use for transmitting data to an ICC.
375 */
376 private static final class IccAPDUArgument {
377 public int channel, cla, command, p1, p2, p3;
378 public String data;
379
380 public IccAPDUArgument(int channel, int cla, int command,
381 int p1, int p2, int p3, String data) {
382 this.channel = channel;
383 this.cla = cla;
384 this.command = command;
385 this.p1 = p1;
386 this.p2 = p2;
387 this.p3 = p3;
388 this.data = data;
389 }
390 }
391
392 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700393 * A request object to use for transmitting data to an ICC.
394 */
395 private static final class ManualNetworkSelectionArgument {
396 public OperatorInfo operatorInfo;
397 public boolean persistSelection;
398
399 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
400 this.operatorInfo = operatorInfo;
401 this.persistSelection = persistSelection;
402 }
403 }
404
405 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
407 * request after sending. The main thread will notify the request when it is complete.
408 */
409 private static final class MainThreadRequest {
410 /** The argument to use for the request */
411 public Object argument;
412 /** The result of the request that is run on the main thread */
413 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800414 // The subscriber id that this request applies to. Defaults to
415 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
416 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Nathan Harold92bed182018-10-12 18:16:49 -0700418 // In cases where subId is unavailable, the caller needs to specify the phone.
419 public Phone phone;
420
vagdeviaf9a5b92018-08-15 16:01:53 -0700421 public WorkSource workSource;
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 public MainThreadRequest(Object argument) {
424 this.argument = argument;
425 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800426
Nathan Harold92bed182018-10-12 18:16:49 -0700427 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
428 this.argument = argument;
429 if (phone != null) {
430 this.phone = phone;
431 }
432 this.workSource = workSource;
433 }
434
vagdeviaf9a5b92018-08-15 16:01:53 -0700435 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800436 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800437 if (subId != null) {
438 this.subId = subId;
439 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700440 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 }
443
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800444 private static final class IncomingThirdPartyCallArgs {
445 public final ComponentName component;
446 public final String callId;
447 public final String callerDisplayName;
448
449 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
450 String callerDisplayName) {
451 this.component = component;
452 this.callId = callId;
453 this.callerDisplayName = callerDisplayName;
454 }
455 }
456
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 /**
458 * A handler that processes messages on the main thread in the phone process. Since many
459 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
460 * inbound binder threads to the main thread in the phone process. The Binder thread
461 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
462 * on, which will be notified when the operation completes and will contain the result of the
463 * request.
464 *
465 * <p>If a MainThreadRequest object is provided in the msg.obj field,
466 * note that request.result must be set to something non-null for the calling thread to
467 * unblock.
468 */
469 private final class MainThreadHandler extends Handler {
470 @Override
471 public void handleMessage(Message msg) {
472 MainThreadRequest request;
473 Message onCompleted;
474 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800477 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478
479 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 case CMD_HANDLE_USSD_REQUEST: {
481 request = (MainThreadRequest) msg.obj;
482 final Phone phone = getPhoneFromRequest(request);
483 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
484 String ussdRequest = ussdObject.first;
485 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700486
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 if (!isUssdApiAllowed(request.subId)) {
488 // Carrier does not support use of this API, return failure.
489 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
490 UssdResponse response = new UssdResponse(ussdRequest, null);
491 Bundle returnData = new Bundle();
492 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
493 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700494
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 request.result = true;
496 notifyRequester(request);
497 return;
498 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700499
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 try {
501 request.result = phone != null
502 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
503 } catch (CallStateException cse) {
504 request.result = false;
505 }
506 // Wake up the requesting thread
507 notifyRequester(request);
508 break;
pkanwar32d516d2016-10-14 19:37:38 -0700509 }
510
Yorke Lee716f67e2015-06-17 15:39:16 -0700511 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700513 final Phone phone = getPhoneFromRequest(request);
514 request.result = phone != null ?
515 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
516 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 if (uiccCard == null) {
527 loge("iccTransmitApduLogicalChannel: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
532 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 iccArgument.channel, iccArgument.cla, iccArgument.command,
535 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 break;
539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800549 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800551 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 } else {
553 loge("iccTransmitApduLogicalChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccTransmitApduBasicChannel: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
569 request);
570 uiccCard.iccTransmitApduBasicChannel(
571 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
572 iccArgument.p3, iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("iccTransmitApduBasicChannel: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("iccTransmitApduBasicChannel: CommandException: " +
587 ar.exception);
588 } else {
589 loge("iccTransmitApduBasicChannel: Unknown exception");
590 }
591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 break;
594
595 case CMD_EXCHANGE_SIM_IO:
596 request = (MainThreadRequest) msg.obj;
597 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800598 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (uiccCard == null) {
600 loge("iccExchangeSimIO: No UICC");
601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
605 request);
606 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
607 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
608 iccArgument.data, onCompleted);
609 }
610 break;
611
612 case EVENT_EXCHANGE_SIM_IO_DONE:
613 ar = (AsyncResult) msg.obj;
614 request = (MainThreadRequest) ar.userObj;
615 if (ar.exception == null && ar.result != null) {
616 request.result = ar.result;
617 } else {
618 request.result = new IccIoResult(0x6f, 0, (byte[])null);
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 break;
622
Derek Tan4d5e5c12014-02-04 11:54:58 -0800623 case CMD_SEND_ENVELOPE:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("sendEnvelopeWithStatus: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
632 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
633 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800634 break;
635
636 case EVENT_SEND_ENVELOPE_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700642 request.result = new IccIoResult(0x6F, 0, (byte[])null);
643 if (ar.result == null) {
644 loge("sendEnvelopeWithStatus: Empty response");
645 } else if (ar.exception instanceof CommandException) {
646 loge("sendEnvelopeWithStatus: CommandException: " +
647 ar.exception);
648 } else {
649 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
650 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800653 break;
654
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 case CMD_OPEN_CHANNEL:
656 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800657 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800658 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 if (uiccCard == null) {
660 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800661 request.result = new IccOpenLogicalChannelResponse(-1,
662 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
665 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800666 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
667 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
671 case EVENT_OPEN_CHANNEL_DONE:
672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 int[] result = (int[]) ar.result;
677 int channelId = result[0];
678 byte[] selectResponse = null;
679 if (result.length > 1) {
680 selectResponse = new byte[result.length - 1];
681 for (int i = 1; i < result.length; ++i) {
682 selectResponse[i - 1] = (byte) result[i];
683 }
684 }
685 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700686 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 if (ar.result == null) {
689 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 if (ar.exception != null) {
692 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
693 }
694
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700696 if (ar.exception instanceof CommandException) {
697 CommandException.Error error =
698 ((CommandException) (ar.exception)).getCommandError();
699 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700701 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 }
704 }
705 openChannelResp = new IccOpenLogicalChannelResponse(
706 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700708 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 break;
711
712 case CMD_CLOSE_CHANNEL:
713 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800714 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 if (uiccCard == null) {
716 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900717 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
721 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
722 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 break;
724
725 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800726 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
727 break;
728
729 case CMD_NV_READ_ITEM:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800732 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
733 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
736 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800739 if (ar.exception == null && ar.result != null) {
740 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800742 request.result = "";
743 if (ar.result == null) {
744 loge("nvReadItem: Empty response");
745 } else if (ar.exception instanceof CommandException) {
746 loge("nvReadItem: CommandException: " +
747 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800749 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 }
751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 break;
754
Jake Hambye994d462014-02-03 13:10:13 -0800755 case CMD_NV_WRITE_ITEM:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
758 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_WRITE_ITEM_DONE:
764 handleNullReturnEvent(msg, "nvWriteItem");
765 break;
766
767 case CMD_NV_WRITE_CDMA_PRL:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800770 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800771 break;
772
773 case EVENT_NV_WRITE_CDMA_PRL_DONE:
774 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
775 break;
776
chen xu6dac5ab2018-10-26 17:39:23 -0700777 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800778 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700779 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800780 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800781 break;
782
chen xu6dac5ab2018-10-26 17:39:23 -0700783 case EVENT_RESET_MODEM_CONFIG_DONE:
784 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
Sooraj Sasindran37444802020-08-11 10:40:43 -0700787 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
790 request);
791 Phone phone = getPhoneFromRequest(request);
792 if (phone != null) {
793 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
794 } else {
795 loge("isNRDualConnectivityEnabled: No phone object");
796 request.result = false;
797 notifyRequester(request);
798 }
799 break;
800 }
801
802 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null && ar.result != null) {
806 request.result = ar.result;
807 } else {
808 // request.result must be set to something non-null
809 // for the calling thread to unblock
810 if (request.result != null) {
811 request.result = ar.result;
812 } else {
813 request.result = false;
814 }
815 if (ar.result == null) {
816 loge("isNRDualConnectivityEnabled: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("isNRDualConnectivityEnabled: CommandException: "
819 + ar.exception);
820 } else {
821 loge("isNRDualConnectivityEnabled: Unknown exception");
822 }
823 }
824 notifyRequester(request);
825 break;
826
827 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
830 Phone phone = getPhoneFromRequest(request);
831 if (phone != null) {
832 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
833 request.workSource);
834 } else {
835 loge("enableNrDualConnectivity: No phone object");
836 request.result =
837 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
838 notifyRequester(request);
839 }
840 break;
841 }
842
843 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result =
848 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
849 } else {
850 request.result =
851 TelephonyManager
852 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
853 if (ar.exception instanceof CommandException) {
854 CommandException.Error error =
855 ((CommandException) (ar.exception)).getCommandError();
856 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
857 request.result =
858 TelephonyManager
859 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
860 }
861 loge("enableNrDualConnectivity" + ": CommandException: "
862 + ar.exception);
863 } else {
864 loge("enableNrDualConnectivity" + ": Unknown exception");
865 }
866 }
867 notifyRequester(request);
868 break;
869 }
870
Jake Hamby7c27be32014-03-03 13:25:59 -0800871 case CMD_GET_PREFERRED_NETWORK_TYPE:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700874 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 break;
876
877 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result; // Integer
882 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530883 // request.result must be set to something non-null
884 // for the calling thread to unblock
885 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 if (ar.result == null) {
887 loge("getPreferredNetworkType: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getPreferredNetworkType: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getPreferredNetworkType: Unknown exception");
893 }
894 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700895 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 break;
897
898 case CMD_SET_PREFERRED_NETWORK_TYPE:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
901 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700902 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 break;
904
905 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
906 handleNullReturnEvent(msg, "setPreferredNetworkType");
907 break;
908
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000909 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
910 request = (MainThreadRequest)msg.obj;
911 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 break;
914
915 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
916 ar = (AsyncResult)msg.obj;
917 request = (MainThreadRequest)ar.userObj;
918 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000920 break;
921
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800922 case CMD_SET_VOICEMAIL_NUMBER:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
925 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800926 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
927 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800928 break;
929
930 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
931 handleNullReturnEvent(msg, "setVoicemailNumber");
932 break;
933
Stuart Scott54788802015-03-30 13:18:01 -0700934 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
937 request);
938 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
939 break;
940
941 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
942 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
943 break;
944
Shishir Agrawal302c8692015-06-19 13:49:39 -0700945 case CMD_PERFORM_NETWORK_SCAN:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
948 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
949 break;
950
Hall Liu27d24262020-09-18 19:04:59 -0700951 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700954 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
955 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
956 request.argument;
957 int callForwardingReason = args.first;
958 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800959 break;
Hall Liu27d24262020-09-18 19:04:59 -0700960 }
961 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700964 TelephonyManager.CallForwardingInfoCallback callback =
965 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
966 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800967 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700968 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800969 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
970 for (CallForwardInfo callForwardInfo : callForwardInfos) {
971 // Service Class is a bit mask per 3gpp 27.007. Search for
972 // any service for voice call.
973 if ((callForwardInfo.serviceClass
974 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700975 callForwardingInfo = new CallForwardingInfo(true,
976 callForwardInfo.reason,
977 callForwardInfo.number,
978 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800979 break;
980 }
981 }
982 // Didn't find a call forward info for voice call.
983 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700984 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
985 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800986 }
Hall Liu27d24262020-09-18 19:04:59 -0700987 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800988 } else {
989 if (ar.result == null) {
990 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
991 }
992 if (ar.exception != null) {
993 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
994 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700995 int errorCode = TelephonyManager
996 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800997 if (ar.exception instanceof CommandException) {
998 CommandException.Error error =
999 ((CommandException) (ar.exception)).getCommandError();
1000 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001001 errorCode = TelephonyManager
1002 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001004 errorCode = TelephonyManager
1005 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001006 }
1007 }
Hall Liu27d24262020-09-18 19:04:59 -07001008 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001009 }
Shuo Qian4a594052020-01-23 11:59:30 -08001010 break;
Hall Liu27d24262020-09-18 19:04:59 -07001011 }
Shuo Qian4a594052020-01-23 11:59:30 -08001012
Hall Liu27d24262020-09-18 19:04:59 -07001013 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001016 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001017 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001018 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1019 request.argument).first;
1020 request.phone.setCallForwardingOption(
1021 callForwardingInfoToSet.isEnabled()
1022 ? CommandsInterface.CF_ACTION_ENABLE
1023 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001024 callForwardingInfoToSet.getReason(),
1025 callForwardingInfoToSet.getNumber(),
1026 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1027 break;
Hall Liu27d24262020-09-18 19:04:59 -07001028 }
Shuo Qian4a594052020-01-23 11:59:30 -08001029
Hall Liu27d24262020-09-18 19:04:59 -07001030 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001033 Consumer<Integer> callback =
1034 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1035 request.argument).second;
1036 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001037 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 int errorCode = TelephonyManager.CallForwardingInfoCallback
1039 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001040 if (ar.exception instanceof CommandException) {
1041 CommandException.Error error =
1042 ((CommandException) (ar.exception)).getCommandError();
1043 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001044 errorCode = TelephonyManager.CallForwardingInfoCallback
1045 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001046 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001047 errorCode = TelephonyManager.CallForwardingInfoCallback
1048 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001049 }
1050 }
1051 callback.accept(errorCode);
1052 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001053 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001054 }
Shuo Qian4a594052020-01-23 11:59:30 -08001055 break;
Hall Liu27d24262020-09-18 19:04:59 -07001056 }
Shuo Qian4a594052020-01-23 11:59:30 -08001057
Hall Liu27d24262020-09-18 19:04:59 -07001058 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1061 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1062 break;
Hall Liu27d24262020-09-18 19:04:59 -07001063 }
Shuo Qian4a594052020-01-23 11:59:30 -08001064
Hall Liu27d24262020-09-18 19:04:59 -07001065 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001068 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001069 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1070 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001071 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001072 // Service Class is a bit mask per 3gpp 27.007.
1073 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001074 if (callForwardResults.length > 1
1075 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001076 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001077 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001078 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1079 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001080 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001081 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001082 }
1083 } else {
1084 if (ar.result == null) {
1085 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1086 }
1087 if (ar.exception != null) {
1088 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1089 }
1090 if (ar.exception instanceof CommandException) {
1091 CommandException.Error error =
1092 ((CommandException) (ar.exception)).getCommandError();
1093 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1094 callForwardingStatus =
1095 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1096 }
1097 }
1098 }
Hall Liu27d24262020-09-18 19:04:59 -07001099 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001100 break;
Hall Liu27d24262020-09-18 19:04:59 -07001101 }
Shuo Qian4a594052020-01-23 11:59:30 -08001102
Hall Liu27d24262020-09-18 19:04:59 -07001103 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001106 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1107 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001108 break;
Hall Liu27d24262020-09-18 19:04:59 -07001109 }
Shuo Qian4a594052020-01-23 11:59:30 -08001110
Hall Liu27d24262020-09-18 19:04:59 -07001111 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001114 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1115 Consumer<Integer> callback =
1116 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1117 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001118 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001119 if (ar.exception instanceof CommandException) {
1120 CommandException.Error error =
1121 ((CommandException) (ar.exception)).getCommandError();
1122 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1123 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1124 } else {
1125 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1126 }
1127 } else {
1128 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1129 }
1130 } else {
1131 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1132 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Shishir Agrawal302c8692015-06-19 13:49:39 -07001137 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 CellNetworkScanResult cellScanResult;
1141 if (ar.exception == null && ar.result != null) {
1142 cellScanResult = new CellNetworkScanResult(
1143 CellNetworkScanResult.STATUS_SUCCESS,
1144 (List<OperatorInfo>) ar.result);
1145 } else {
1146 if (ar.result == null) {
1147 loge("getCellNetworkScanResults: Empty response");
1148 }
1149 if (ar.exception != null) {
1150 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1151 }
1152 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1153 if (ar.exception instanceof CommandException) {
1154 CommandException.Error error =
1155 ((CommandException) (ar.exception)).getCommandError();
1156 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1157 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1158 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1159 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1160 }
1161 }
1162 cellScanResult = new CellNetworkScanResult(errorCode, null);
1163 }
1164 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 break;
1167
1168 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1169 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001170 ManualNetworkSelectionArgument selArg =
1171 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001172 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1173 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001174 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1175 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 break;
1177
1178 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 if (ar.exception == null) {
1182 request.result = true;
1183 } else {
1184 request.result = false;
1185 loge("setNetworkSelectionModeManual " + ar.exception);
1186 }
1187 notifyRequester(request);
1188 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001191 case CMD_GET_MODEM_ACTIVITY_INFO:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001194 if (defaultPhone != null) {
1195 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001196 } else {
1197 ResultReceiver result = (ResultReceiver) request.argument;
1198 Bundle bundle = new Bundle();
1199 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001200 new ModemActivityInfo(0, 0, 0,
1201 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001202 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001203 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001204 break;
1205
Hall Liud0f208c2020-10-14 16:54:44 -07001206 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001209 ResultReceiver result = (ResultReceiver) request.argument;
1210
Hall Liud0f208c2020-10-14 16:54:44 -07001211 ModemActivityInfo ret = null;
1212 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001214 // Update the last modem activity info and the result of the request.
1215 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1216 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001217 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001218 int[] txTimeMs = info.getTransmitTimeMillis();
1219 int[] lastModemTxTimeMs = mLastModemActivityInfo
1220 .getTransmitTimeMillis();
1221 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1222 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1223 }
Hall Liu49656c02020-10-09 19:00:11 -07001224 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001225 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1226 + mLastModemActivityInfo.getSleepTimeMillis());
1227 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1228 + mLastModemActivityInfo.getIdleTimeMillis());
1229 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1230 mLastModemActivityInfo.setReceiveTimeMillis(
1231 info.getReceiveTimeMillis()
1232 + mLastModemActivityInfo.getReceiveTimeMillis());
1233 }
Hall Liu49656c02020-10-09 19:00:11 -07001234 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 mLastModemActivityInfo.getSleepTimeMillis(),
1236 mLastModemActivityInfo.getIdleTimeMillis(),
1237 mLastModemActivityInfo.getTransmitTimeMillis(),
1238 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 } else {
1240 if (ar.result == null) {
1241 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001242 error = TelephonyManager.ModemActivityInfoException
1243 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001244 } else if (ar.exception instanceof CommandException) {
1245 loge("queryModemActivityInfo: CommandException: " +
1246 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001247 error = TelephonyManager.ModemActivityInfoException
1248 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001249 } else {
1250 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001251 error = TelephonyManager.ModemActivityInfoException
1252 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 }
1254 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001255 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001256 if (ret != null) {
1257 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1258 } else {
1259 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1260 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001261 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001262 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001263 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001264 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001265
Meng Wang1a7c35a2016-05-05 20:56:15 -07001266 case CMD_SET_ALLOWED_CARRIERS:
1267 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001268 CarrierRestrictionRules argument =
1269 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001270 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001271 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 break;
1273
1274 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 if (ar.exception == null && ar.result != null) {
1278 request.result = ar.result;
1279 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001280 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1281 if (ar.exception instanceof CommandException) {
1282 loge("setAllowedCarriers: CommandException: " + ar.exception);
1283 CommandException.Error error =
1284 ((CommandException) (ar.exception)).getCommandError();
1285 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1286 request.result =
1287 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1288 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 } else {
1290 loge("setAllowedCarriers: Unknown exception");
1291 }
1292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001293 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001294 break;
1295
1296 case CMD_GET_ALLOWED_CARRIERS:
1297 request = (MainThreadRequest) msg.obj;
1298 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001299 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 break;
1301
1302 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null && ar.result != null) {
1306 request.result = ar.result;
1307 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001308 request.result = new IllegalStateException(
1309 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 if (ar.result == null) {
1311 loge("getAllowedCarriers: Empty response");
1312 } else if (ar.exception instanceof CommandException) {
1313 loge("getAllowedCarriers: CommandException: " +
1314 ar.exception);
1315 } else {
1316 loge("getAllowedCarriers: Unknown exception");
1317 }
1318 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001319 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001320 break;
1321
Nathan Haroldb3014052017-01-25 15:57:32 -08001322 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null && ar.result != null) {
1326 request.result = ar.result;
1327 } else {
1328 request.result = new IllegalArgumentException(
1329 "Failed to retrieve Forbidden Plmns");
1330 if (ar.result == null) {
1331 loge("getForbiddenPlmns: Empty response");
1332 } else {
1333 loge("getForbiddenPlmns: Unknown exception");
1334 }
1335 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001336 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001337 break;
1338
1339 case CMD_GET_FORBIDDEN_PLMNS:
1340 request = (MainThreadRequest) msg.obj;
1341 uiccCard = getUiccCardFromRequest(request);
1342 if (uiccCard == null) {
1343 loge("getForbiddenPlmns() UiccCard is null");
1344 request.result = new IllegalArgumentException(
1345 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001347 break;
1348 }
1349 Integer appType = (Integer) request.argument;
1350 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1351 if (uiccApp == null) {
1352 loge("getForbiddenPlmns() no app with specified type -- "
1353 + appType);
1354 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001356 break;
1357 } else {
1358 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1359 + " specified type -- " + appType);
1360 }
1361 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1362 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1363 onCompleted);
1364 break;
1365
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001366 case CMD_SWITCH_SLOTS:
1367 request = (MainThreadRequest) msg.obj;
1368 int[] physicalSlots = (int[]) request.argument;
1369 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1370 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1371 break;
1372
1373 case EVENT_SWITCH_SLOTS_DONE:
1374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
1376 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001377 notifyRequester(request);
1378 break;
1379 case CMD_GET_NETWORK_SELECTION_MODE:
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1382 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1383 break;
1384
1385 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 if (ar.exception != null) {
1389 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1390 } else {
1391 int mode = ((int[]) ar.result)[0];
1392 if (mode == 0) {
1393 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1394 } else {
1395 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1396 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001397 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001398 notifyRequester(request);
1399 break;
1400 case CMD_GET_CDMA_ROAMING_MODE:
1401 request = (MainThreadRequest) msg.obj;
1402 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1403 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1404 break;
1405 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 if (ar.exception != null) {
1409 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1410 } else {
1411 request.result = ((int[]) ar.result)[0];
1412 }
1413 notifyRequester(request);
1414 break;
1415 case CMD_SET_CDMA_ROAMING_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1418 int mode = (int) request.argument;
1419 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1420 break;
1421 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 request.result = ar.exception == null;
1425 notifyRequester(request);
1426 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001427 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1430 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1431 break;
1432 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 if (ar.exception != null) {
1436 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1437 } else {
1438 request.result = ((int[]) ar.result)[0];
1439 }
1440 notifyRequester(request);
1441 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1445 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001446 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1447 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001448 break;
1449 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 request.result = ar.exception == null;
1453 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001454 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001455 case CMD_GET_ALL_CELL_INFO:
1456 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001458 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 case EVENT_GET_ALL_CELL_INFO_DONE:
1461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001463 // If a timeout occurs, the response will be null
1464 request.result = (ar.exception == null && ar.result != null)
1465 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 synchronized (request) {
1467 request.notifyAll();
1468 }
1469 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001470 case CMD_REQUEST_CELL_INFO_UPDATE:
1471 request = (MainThreadRequest) msg.obj;
1472 request.phone.requestCellInfoUpdate(request.workSource,
1473 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1474 break;
1475 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
1478 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1479 try {
1480 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001482 cb.onError(
1483 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1484 ar.exception.getClass().getName(),
1485 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001486 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001487 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001488 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001489 } else {
1490 // use the result as returned
1491 cb.onCellInfo((List<CellInfo>) ar.result);
1492 }
1493 } catch (RemoteException re) {
1494 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1495 }
1496 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001497 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 request = (MainThreadRequest) msg.obj;
1499 WorkSource ws = (WorkSource) request.argument;
1500 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001501 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001503 }
1504 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001505 ar = (AsyncResult) msg.obj;
1506 request = (MainThreadRequest) ar.userObj;
1507 if (ar.exception == null) {
1508 request.result = ar.result;
1509 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001510 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001511 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001512 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001513 }
1514
1515 synchronized (request) {
1516 request.notifyAll();
1517 }
1518 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001519 }
chen xu6dac5ab2018-10-26 17:39:23 -07001520 case CMD_MODEM_REBOOT:
1521 request = (MainThreadRequest) msg.obj;
1522 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001523 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001524 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001525 case EVENT_CMD_MODEM_REBOOT_DONE:
1526 handleNullReturnEvent(msg, "rebootModem");
1527 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001528 case CMD_REQUEST_ENABLE_MODEM:
1529 request = (MainThreadRequest) msg.obj;
1530 boolean enable = (boolean) request.argument;
1531 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001532 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001533 PhoneConfigurationManager.getInstance()
1534 .enablePhone(request.phone, enable, onCompleted);
1535 break;
1536 case EVENT_ENABLE_MODEM_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001540 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001541 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001542 if ((boolean) request.result) {
1543 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1544 updateModemStateMetrics();
1545 } else {
1546 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1547 + ar.exception);
1548 }
1549 notifyRequester(request);
1550 break;
1551 case CMD_GET_MODEM_STATUS:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1554 PhoneConfigurationManager.getInstance()
1555 .getPhoneStatusFromModem(request.phone, onCompleted);
1556 break;
1557 case EVENT_GET_MODEM_STATUS_DONE:
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 int id = request.phone.getPhoneId();
1561 if (ar.exception == null && ar.result != null) {
1562 request.result = ar.result;
1563 //update the cache as modem status has changed
1564 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1565 (boolean) request.result);
1566 } else {
1567 // Return true if modem status cannot be retrieved. For most cases,
1568 // modem status is on. And for older version modems, GET_MODEM_STATUS
1569 // and disable modem are not supported. Modem is always on.
1570 // TODO: this should be fixed in R to support a third
1571 // status UNKNOWN b/131631629
1572 request.result = true;
1573 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1574 + ar.exception);
1575 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001576 notifyRequester(request);
1577 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001578 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1579 request = (MainThreadRequest) msg.obj;
1580 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1581 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1582 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1583 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1584 break;
1585 }
1586 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
1589 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1590 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1591 args.second.accept(ar.exception == null);
1592 notifyRequester(request);
1593 break;
1594 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001595 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1596 request = (MainThreadRequest) msg.obj;
1597 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1598 Phone phone = getPhoneFromRequest(request);
1599 if (phone != null) {
1600 phone.getSystemSelectionChannels(onCompleted);
1601 } else {
1602 loge("getSystemSelectionChannels: No phone object");
1603 request.result = new ArrayList<RadioAccessSpecifier>();
1604 notifyRequester(request);
1605 }
1606 break;
1607 }
1608 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 if (ar.exception == null && ar.result != null) {
1612 request.result = ar.result;
1613 } else {
1614 request.result = new IllegalArgumentException(
1615 "Failed to retrieve system selection channels");
1616 if (ar.result == null) {
1617 loge("getSystemSelectionChannels: Empty response");
1618 } else {
1619 loge("getSystemSelectionChannels: Unknown exception");
1620 }
1621 }
1622 notifyRequester(request);
1623 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001624 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception == null && ar.result != null) {
1628 request.result = ar.result;
1629 } else {
1630 request.result = -1;
1631 loge("Failed to set Forbidden Plmns");
1632 if (ar.result == null) {
1633 loge("setForbidenPlmns: Empty response");
1634 } else if (ar.exception != null) {
1635 loge("setForbiddenPlmns: Exception: " + ar.exception);
1636 request.result = -1;
1637 } else {
1638 loge("setForbiddenPlmns: Unknown exception");
1639 }
1640 }
1641 notifyRequester(request);
1642 break;
1643 case CMD_SET_FORBIDDEN_PLMNS:
1644 request = (MainThreadRequest) msg.obj;
1645 uiccCard = getUiccCardFromRequest(request);
1646 if (uiccCard == null) {
1647 loge("setForbiddenPlmns: UiccCard is null");
1648 request.result = -1;
1649 notifyRequester(request);
1650 break;
1651 }
1652 Pair<Integer, List<String>> setFplmnsArgs =
1653 (Pair<Integer, List<String>>) request.argument;
1654 appType = setFplmnsArgs.first;
1655 List<String> fplmns = setFplmnsArgs.second;
1656 uiccApp = uiccCard.getApplicationByType(appType);
1657 if (uiccApp == null) {
1658 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1659 request.result = -1;
1660 loge("Failed to get UICC App");
1661 notifyRequester(request);
1662 } else {
1663 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1664 ((SIMRecords) uiccApp.getIccRecords())
1665 .setForbiddenPlmns(onCompleted, fplmns);
1666 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001667 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001668 case CMD_ERASE_MODEM_CONFIG:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1671 defaultPhone.eraseModemConfig(onCompleted);
1672 break;
1673 case EVENT_ERASE_MODEM_CONFIG_DONE:
1674 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001675 break;
zoey chene02881a2019-12-30 16:11:23 +08001676
1677 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1680 Pair<String, String> changed = (Pair<String, String>) request.argument;
1681 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1682 changed.first, changed.second, onCompleted);
1683 break;
1684 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
1687 if (ar.exception == null) {
1688 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1689 } else {
1690 request.result = msg.arg1;
1691 }
1692 notifyRequester(request);
1693 break;
1694
1695 case CMD_SET_ICC_LOCK_ENABLED:
1696 request = (MainThreadRequest) msg.obj;
1697 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1698 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1699 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1700 enabled.first, enabled.second, onCompleted);
1701 break;
1702 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 if (ar.exception == null) {
1706 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1707 } else {
1708 request.result = msg.arg1;
1709 }
1710 notifyRequester(request);
1711 break;
1712
Peter Wangdafb9ac2020-01-15 14:13:38 -08001713 case MSG_NOTIFY_USER_ACTIVITY:
1714 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001715 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001716 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1717 getDefaultPhone().getContext().sendBroadcastAsUser(
1718 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1719 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001720
1721 case CMD_SET_DATA_THROTTLING: {
1722 request = (MainThreadRequest) msg.obj;
1723 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1724 DataThrottlingRequest dataThrottlingRequest =
1725 (DataThrottlingRequest) request.argument;
1726 Phone phone = getPhoneFromRequest(request);
1727 if (phone != null) {
1728 phone.setDataThrottling(onCompleted,
1729 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1730 dataThrottlingRequest.getCompletionDurationMillis());
1731 } else {
1732 loge("setDataThrottling: No phone object");
1733 request.result =
1734 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1735 notifyRequester(request);
1736 }
1737
1738 break;
1739 }
1740 case EVENT_SET_DATA_THROTTLING_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743
1744 if (ar.exception == null) {
1745 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1746 } else if (ar.exception instanceof CommandException) {
1747 loge("setDataThrottling: CommandException: " + ar.exception);
1748 CommandException.Error error =
1749 ((CommandException) (ar.exception)).getCommandError();
1750
1751 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1752 request.result = TelephonyManager
1753 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1754 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1755 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1756 } else {
1757 request.result =
1758 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1759 }
1760 } else {
1761 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1762 }
1763 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1764 notifyRequester(request);
1765 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001766
1767 case CMD_SET_SIM_POWER: {
1768 request = (MainThreadRequest) msg.obj;
1769 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1770 request = (MainThreadRequest) msg.obj;
1771 int stateToSet =
1772 ((Pair<Integer, IIntegerConsumer>)
1773 request.argument).first;
1774 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1775 break;
1776 }
1777 case EVENT_SET_SIM_POWER_DONE: {
1778 ar = (AsyncResult) msg.obj;
1779 request = (MainThreadRequest) ar.userObj;
1780 IIntegerConsumer callback =
1781 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1782 if (ar.exception != null) {
1783 loge("setSimPower exception: " + ar.exception);
1784 int errorCode = TelephonyManager.CallForwardingInfoCallback
1785 .RESULT_ERROR_UNKNOWN;
1786 if (ar.exception instanceof CommandException) {
1787 CommandException.Error error =
1788 ((CommandException) (ar.exception)).getCommandError();
1789 if (error == CommandException.Error.SIM_ERR) {
1790 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1791 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1792 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1793 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1794 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1795 } else {
1796 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1797 }
1798 }
1799 try {
1800 callback.accept(errorCode);
1801 } catch (RemoteException e) {
1802 // Ignore if the remote process is no longer available to call back.
1803 Log.w(LOG_TAG, "setSimPower: callback not available.");
1804 }
1805 } else {
1806 try {
1807 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1808 } catch (RemoteException e) {
1809 // Ignore if the remote process is no longer available to call back.
1810 Log.w(LOG_TAG, "setSimPower: callback not available.");
1811 }
1812 }
1813 break;
1814 }
1815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 default:
1817 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1818 break;
1819 }
1820 }
Jake Hambye994d462014-02-03 13:10:13 -08001821
Pengquan Menga1bb6272018-09-06 09:59:22 -07001822 private void notifyRequester(MainThreadRequest request) {
1823 synchronized (request) {
1824 request.notifyAll();
1825 }
1826 }
1827
Jake Hambye994d462014-02-03 13:10:13 -08001828 private void handleNullReturnEvent(Message msg, String command) {
1829 AsyncResult ar = (AsyncResult) msg.obj;
1830 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1831 if (ar.exception == null) {
1832 request.result = true;
1833 } else {
1834 request.result = false;
1835 if (ar.exception instanceof CommandException) {
1836 loge(command + ": CommandException: " + ar.exception);
1837 } else {
1838 loge(command + ": Unknown exception");
1839 }
1840 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001841 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845 /**
1846 * Posts the specified command to be executed on the main thread,
1847 * waits for the request to complete, and returns the result.
1848 * @see #sendRequestAsync
1849 */
1850 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001851 return sendRequest(
1852 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001853 }
1854
1855 /**
1856 * Posts the specified command to be executed on the main thread,
1857 * waits for the request to complete, and returns the result.
1858 * @see #sendRequestAsync
1859 */
1860 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1861 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001862 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001863 }
1864
1865 /**
1866 * Posts the specified command to be executed on the main thread,
1867 * waits for the request to complete, and returns the result.
1868 * @see #sendRequestAsync
1869 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001870 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001871 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001872 }
1873
1874 /**
1875 * Posts the specified command to be executed on the main thread,
1876 * waits for the request to complete, and returns the result.
1877 * @see #sendRequestAsync
1878 */
Nathan Harold92bed182018-10-12 18:16:49 -07001879 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1880 return sendRequest(command, argument, subId, null, workSource);
1881 }
1882
1883 /**
1884 * Posts the specified command to be executed on the main thread,
1885 * waits for the request to complete, and returns the result.
1886 * @see #sendRequestAsync
1887 */
1888 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1889 return sendRequest(
1890 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1891 }
1892
1893 /**
1894 * Posts the specified command to be executed on the main thread,
1895 * waits for the request to complete, and returns the result.
1896 * @see #sendRequestAsync
1897 */
1898 private Object sendRequest(
1899 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1901 throw new RuntimeException("This method will deadlock if called from the main thread.");
1902 }
1903
Nathan Harold92bed182018-10-12 18:16:49 -07001904 MainThreadRequest request = null;
1905 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1906 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1907 } else if (phone != null) {
1908 request = new MainThreadRequest(argument, phone, workSource);
1909 } else {
1910 request = new MainThreadRequest(argument, subId, workSource);
1911 }
1912
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 Message msg = mMainThreadHandler.obtainMessage(command, request);
1914 msg.sendToTarget();
1915
1916 // Wait for the request to complete
1917 synchronized (request) {
1918 while (request.result == null) {
1919 try {
1920 request.wait();
1921 } catch (InterruptedException e) {
1922 // Do nothing, go back and wait until the request is complete
1923 }
1924 }
1925 }
1926 return request.result;
1927 }
1928
1929 /**
1930 * Asynchronous ("fire and forget") version of sendRequest():
1931 * Posts the specified command to be executed on the main thread, and
1932 * returns immediately.
1933 * @see #sendRequest
1934 */
1935 private void sendRequestAsync(int command) {
1936 mMainThreadHandler.sendEmptyMessage(command);
1937 }
1938
1939 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001940 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001941 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001942 */
1943 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001944 sendRequestAsync(command, argument, null, null);
1945 }
1946
1947 /**
1948 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1949 * @see {@link #sendRequest(int,Object)}
1950 */
1951 private void sendRequestAsync(
1952 int command, Object argument, Phone phone, WorkSource workSource) {
1953 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001954 Message msg = mMainThreadHandler.obtainMessage(command, request);
1955 msg.sendToTarget();
1956 }
1957
1958 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 * Initialize the singleton PhoneInterfaceManager instance.
1960 * This is only done once, at startup, from PhoneApp.onCreate().
1961 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001962 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 synchronized (PhoneInterfaceManager.class) {
1964 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001965 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 } else {
1967 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1968 }
1969 return sInstance;
1970 }
1971 }
1972
1973 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001974 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001977 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001978 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1980 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001981 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001982 mTelephonySharedPreferences =
1983 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001984 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001985 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001986 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 publish();
1989 }
1990
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001991 private Phone getDefaultPhone() {
1992 Phone thePhone = getPhone(getDefaultSubscription());
1993 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1994 }
1995
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 private void publish() {
1997 if (DBG) log("publish: " + this);
1998
Peter Wangc035ce42020-01-08 21:00:22 -08001999 TelephonyFrameworkInitializer
2000 .getTelephonyServiceManager()
2001 .getTelephonyServiceRegisterer()
2002 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 }
2004
Stuart Scott584921c2015-01-15 17:10:34 -08002005 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002006 if (request.phone != null) {
2007 return request.phone;
2008 } else {
2009 return getPhoneFromSubId(request.subId);
2010 }
2011 }
2012
2013 private Phone getPhoneFromSubId(int subId) {
2014 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2015 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002016 }
2017
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002018 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2019 Phone phone = getPhoneFromRequest(request);
2020 return phone == null ? null :
2021 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2022 }
2023
Wink Saville36469e72014-06-11 15:17:00 -07002024 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002025 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002026 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028
Naina Nallurid63128d2019-09-17 14:10:30 -07002029 private void sendEraseModemConfig(Phone phone) {
2030 if (phone != null) {
2031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2032 mApp, phone.getSubId(), "eraseModemConfig");
2033 final long identity = Binder.clearCallingIdentity();
2034 try {
2035 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2036 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2037 } finally {
2038 Binder.restoreCallingIdentity(identity);
2039 }
2040 }
2041 }
2042
Peter Wang44b186e2020-01-13 23:33:09 -08002043 private boolean isImsAvailableOnDevice() {
2044 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2045 if (pm == null) {
2046 // For some reason package manger is not available.. This will fail internally anyway,
2047 // so do not throw error and allow.
2048 return true;
2049 }
2050 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2051 }
2052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002054 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002055 }
2056
Wink Savilleb564aae2014-10-23 10:18:09 -07002057 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 if (DBG) log("dial: " + number);
2059 // No permission check needed here: This is just a wrapper around the
2060 // ACTION_DIAL intent, which is available to any app since it puts up
2061 // the UI before it does anything.
2062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 String url = createTelUrl(number);
2066 if (url == null) {
2067 return;
2068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070 // PENDING: should we just silently fail if phone is offhook or ringing?
2071 PhoneConstants.State state = mCM.getState(subId);
2072 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2073 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2074 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2075 mApp.startActivity(intent);
2076 }
2077 } finally {
2078 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
2080 }
2081
2082 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002083 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002084 }
2085
Wink Savilleb564aae2014-10-23 10:18:09 -07002086 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 if (DBG) log("call: " + number);
2088
2089 // This is just a wrapper around the ACTION_CALL intent, but we still
2090 // need to do a permission check since we're calling startActivity()
2091 // from the context of the phone app.
2092 enforceCallPermission();
2093
Jordan Liu1617b712019-07-10 15:06:26 -07002094 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 != AppOpsManager.MODE_ALLOWED) {
2096 return;
2097 }
2098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 String url = createTelUrl(number);
2102 if (url == null) {
2103 return;
2104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 boolean isValid = false;
2107 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2108 if (slist != null) {
2109 for (SubscriptionInfo subInfoRecord : slist) {
2110 if (subInfoRecord.getSubscriptionId() == subId) {
2111 isValid = true;
2112 break;
2113 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002114 }
Wink Saville08874612014-08-31 19:19:58 -07002115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116 if (!isValid) {
2117 return;
2118 }
Wink Saville08874612014-08-31 19:19:58 -07002119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2121 intent.putExtra(SUBSCRIPTION_KEY, subId);
2122 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2123 mApp.startActivity(intent);
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
2126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Savilleb564aae2014-10-23 10:18:09 -07002129 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002130 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002131 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2132 }
2133
Wink Savilleb564aae2014-10-23 10:18:09 -07002134 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002135 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002136 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2137 }
2138
Wink Savilleb564aae2014-10-23 10:18:09 -07002139 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141
2142 final long identity = Binder.clearCallingIdentity();
2143 try {
2144 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2145 checkSimPin.start();
2146 return checkSimPin.unlockSim(null, pin);
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
2149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 }
2151
Wink Savilleb564aae2014-10-23 10:18:09 -07002152 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002154
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2158 checkSimPuk.start();
2159 return checkSimPuk.unlockSim(puk, pin);
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
2164
2165 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002166 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 * a synchronous one.
2168 */
2169 private static class UnlockSim extends Thread {
2170
2171 private final IccCard mSimCard;
2172
2173 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002174 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2175 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176
2177 // For replies from SimCard interface
2178 private Handler mHandler;
2179
2180 // For async handler to identify request type
2181 private static final int SUPPLY_PIN_COMPLETE = 100;
2182
2183 public UnlockSim(IccCard simCard) {
2184 mSimCard = simCard;
2185 }
2186
2187 @Override
2188 public void run() {
2189 Looper.prepare();
2190 synchronized (UnlockSim.this) {
2191 mHandler = new Handler() {
2192 @Override
2193 public void handleMessage(Message msg) {
2194 AsyncResult ar = (AsyncResult) msg.obj;
2195 switch (msg.what) {
2196 case SUPPLY_PIN_COMPLETE:
2197 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2198 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002199 mRetryCount = msg.arg1;
2200 if (ar.exception != null) {
2201 if (ar.exception instanceof CommandException &&
2202 ((CommandException)(ar.exception)).getCommandError()
2203 == CommandException.Error.PASSWORD_INCORRECT) {
2204 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002205 } //When UiccCardApp dispose,handle message and return exception
2206 else if (ar.exception instanceof CommandException &&
2207 ((CommandException) (ar.exception)).getCommandError()
2208 == CommandException.Error.ABORTED) {
2209 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002210 } else {
2211 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2212 }
2213 } else {
2214 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 mDone = true;
2217 UnlockSim.this.notifyAll();
2218 }
2219 break;
2220 }
2221 }
2222 };
2223 UnlockSim.this.notifyAll();
2224 }
2225 Looper.loop();
2226 }
2227
2228 /*
2229 * Use PIN or PUK to unlock SIM card
2230 *
2231 * If PUK is null, unlock SIM card with PIN
2232 *
2233 * If PUK is not null, unlock SIM card with PUK and set PIN code
2234 */
Wink Saville9de0f752013-10-22 19:04:03 -07002235 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236
2237 while (mHandler == null) {
2238 try {
2239 wait();
2240 } catch (InterruptedException e) {
2241 Thread.currentThread().interrupt();
2242 }
2243 }
2244 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2245
2246 if (puk == null) {
2247 mSimCard.supplyPin(pin, callback);
2248 } else {
2249 mSimCard.supplyPuk(puk, pin, callback);
2250 }
2251
2252 while (!mDone) {
2253 try {
2254 Log.d(LOG_TAG, "wait for done");
2255 wait();
2256 } catch (InterruptedException e) {
2257 // Restore the interrupted status
2258 Thread.currentThread().interrupt();
2259 }
2260 }
2261 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002262 int[] resultArray = new int[2];
2263 resultArray[0] = mResult;
2264 resultArray[1] = mRetryCount;
2265 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267 }
2268
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002269 /**
2270 * This method has been removed due to privacy and stability concerns.
2271 */
2272 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002274 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2275 return;
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
Nathan Harold1f889d82020-06-04 17:05:26 -07002278 @Override
2279 public void updateServiceLocationWithPackageName(String callingPackage) {
2280 mApp.getSystemService(AppOpsManager.class)
2281 .checkPackage(Binder.getCallingUid(), callingPackage);
2282
Nathan Haroldf096d982020-11-18 17:18:06 -08002283 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002284 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2285 // Callers targeting S have no business invoking this method.
2286 return;
2287 }
2288
2289 LocationAccessPolicy.LocationPermissionResult locationResult =
2290 LocationAccessPolicy.checkLocationPermission(mApp,
2291 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2292 .setCallingPackage(callingPackage)
2293 .setCallingFeatureId(null)
2294 .setCallingPid(Binder.getCallingPid())
2295 .setCallingUid(Binder.getCallingUid())
2296 .setMethod("updateServiceLocation")
2297 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2299 .build());
2300 // Apps that lack location permission have no business calling this method;
2301 // however, because no permission was declared in the public API, denials must
2302 // all be "soft".
2303 switch (locationResult) {
2304 case DENIED_HARD: /* fall through */
2305 case DENIED_SOFT:
2306 return;
2307 }
2308
2309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310 final long identity = Binder.clearCallingIdentity();
2311 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002312 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002314 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315 }
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 }
2320
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002321 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 @Override
2323 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002324 return isRadioOnWithFeature(callingPackage, null);
2325 }
2326
2327
2328 @Override
2329 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2330 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2331 callingFeatureId);
2332 }
2333
2334 @Deprecated
2335 @Override
2336 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2337 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002341 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2342 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002344 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 return false;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 return isRadioOnForSubscriber(subId);
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 }
2355
2356 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2362 } else {
2363 return false;
2364 }
2365 } finally {
2366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
2369
2370 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002371 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
Wink Saville36469e72014-06-11 15:17:00 -07002373
Wink Savilleb564aae2014-10-23 10:18:09 -07002374 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 if (phone != null) {
2381 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2382 }
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002385 }
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
2388 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002389 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002390 }
2391
Wink Savilleb564aae2014-10-23 10:18:09 -07002392 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002393 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 final Phone phone = getPhone(subId);
2398 if (phone == null) {
2399 return false;
2400 }
2401 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2402 toggleRadioOnOffForSubscriber(subId);
2403 }
2404 return true;
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
Wink Saville36469e72014-06-11 15:17:00 -07002409
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002410 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002411 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002412 /*
2413 * If any of the Radios are available, it will need to be
2414 * shutdown. So return true if any Radio is available.
2415 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2419 Phone phone = PhoneFactory.getPhone(i);
2420 if (phone != null && phone.isRadioAvailable()) return true;
2421 }
2422 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2423 return false;
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002426 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002427 }
2428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002430 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431 enforceModifyPermission();
2432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2436 logv("Shutting down Phone " + i);
2437 shutdownRadioUsingPhoneId(i);
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002441 }
2442 }
2443
2444 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002445 Phone phone = PhoneFactory.getPhone(phoneId);
2446 if (phone != null && phone.isRadioAvailable()) {
2447 phone.shutdownRadio();
2448 }
2449 }
2450
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2457 if (defaultPhone != null) {
2458 defaultPhone.setRadioPower(turnOn);
2459 return true;
2460 } else {
2461 loge("There's no default phone.");
2462 return false;
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002466 }
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 final Phone phone = getPhone(subId);
2475 if (phone != null) {
2476 phone.setRadioPower(turnOn);
2477 return true;
2478 } else {
2479 return false;
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Wink Saville36469e72014-06-11 15:17:00 -07002486 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 public boolean enableDataConnectivity() {
2489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 int subId = mSubscriptionController.getDefaultDataSubId();
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002496 phone.getDataEnabledSettings().setDataEnabled(
2497 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 return true;
2499 } else {
2500 return false;
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
2506
Wink Saville36469e72014-06-11 15:17:00 -07002507 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 public boolean disableDataConnectivity() {
2510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 int subId = mSubscriptionController.getDefaultDataSubId();
2515 final Phone phone = getPhone(subId);
2516 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002517 phone.getDataEnabledSettings().setDataEnabled(
2518 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 return true;
2520 } else {
2521 return false;
2522 }
2523 } finally {
2524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002529 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002534 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 } else {
2536 return false;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542
2543 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002544 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002545 }
2546
pkanwarae03a6b2016-11-06 20:37:09 -08002547 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 enforceCallPermission();
2549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2553 return;
2554 }
2555 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2556 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
2559 }
pkanwar32d516d2016-10-14 19:37:38 -07002560 };
2561
Wink Savilleb564aae2014-10-23 10:18:09 -07002562 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2568 return false;
2569 }
2570 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002577 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002580 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 Phone phone = PhoneFactory.getPhone(slotIndex);
2584 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2585 PhoneConstantConversions.convertCallState(phone.getState());
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002592 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002593 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2594 }
2595
2596 @Override
2597 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 if (phone != null) {
2602 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2603 } else {
2604 return PhoneConstantConversions.convertDataState(
2605 PhoneConstants.DataState.DISCONNECTED);
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002613 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002614 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2615 }
2616
2617 @Override
2618 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002621 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 if (phone != null) {
2623 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2624 } else {
2625 return TelephonyManager.DATA_ACTIVITY_NONE;
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
2632 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002633 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002634 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002635 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002636
2637 LocationAccessPolicy.LocationPermissionResult locationResult =
2638 LocationAccessPolicy.checkLocationPermission(mApp,
2639 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2640 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002641 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002642 .setCallingPid(Binder.getCallingPid())
2643 .setCallingUid(Binder.getCallingUid())
2644 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002645 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002646 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2647 .build());
2648 switch (locationResult) {
2649 case DENIED_HARD:
2650 throw new SecurityException("Not allowed to access cell location");
2651 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002652 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2653 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002656 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002660 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002661 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Svetoslav64fad262015-04-14 14:35:21 -07002665 }
2666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002668 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002669 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2670 // registered cell info, so return a NULL country instead.
2671 final long identity = Binder.clearCallingIdentity();
2672 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002673 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2674 // Get default phone in this case.
2675 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2676 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002677 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002679 if (phone == null) return "";
2680 ServiceStateTracker sst = phone.getServiceStateTracker();
2681 if (sst == null) return "";
2682 LocaleTracker lt = sst.getLocaleTracker();
2683 if (lt == null) return "";
2684 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2685 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2686 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002690 }
2691
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002692 /**
2693 * This method was removed due to potential issues caused by performing partial
2694 * updates of service state, and lack of a credible use case.
2695 *
2696 * This has the ability to break the telephony implementation by disabling notification of
2697 * changes in device connectivity. DO NOT USE THIS!
2698 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002699 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 public void enableLocationUpdates() {
2701 mApp.enforceCallingOrSelfPermission(
2702 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002705 /**
2706 * This method was removed due to potential issues caused by performing partial
2707 * updates of service state, and lack of a credible use case.
2708 *
2709 * This has the ability to break the telephony implementation by disabling notification of
2710 * changes in device connectivity. DO NOT USE THIS!
2711 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 @Override
2713 public void disableLocationUpdates() {
2714 mApp.enforceCallingOrSelfPermission(
2715 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
2718 @Override
2719 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002720 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2721 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002722 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002723 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2724 throw new SecurityException(
2725 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2726 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002727
Jordan Liu1617b712019-07-10 15:06:26 -07002728 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2730 return null;
2731 }
Svetoslav64fad262015-04-14 14:35:21 -07002732
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002733 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002735 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002736 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737
Nathan Haroldf180aac2018-06-01 18:43:55 -07002738 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2739 for (CellInfo ci : info) {
2740 if (ci instanceof CellInfoGsm) {
2741 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2742 } else if (ci instanceof CellInfoWcdma) {
2743 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002746 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
2748
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002749 private List<CellInfo> getCachedCellInfo() {
2750 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2751 for (Phone phone : PhoneFactory.getPhones()) {
2752 List<CellInfo> info = phone.getAllCellInfo();
2753 if (info != null) cellInfos.addAll(info);
2754 }
2755 return cellInfos;
2756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757
2758 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002759 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002760 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002761 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002762
2763 LocationAccessPolicy.LocationPermissionResult locationResult =
2764 LocationAccessPolicy.checkLocationPermission(mApp,
2765 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2766 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002767 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002768 .setCallingPid(Binder.getCallingPid())
2769 .setCallingUid(Binder.getCallingUid())
2770 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002771 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002772 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2773 .build());
2774 switch (locationResult) {
2775 case DENIED_HARD:
2776 throw new SecurityException("Not allowed to access cell info");
2777 case DENIED_SOFT:
2778 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
Nathan Haroldf096d982020-11-18 17:18:06 -08002781 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002782 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2783 return getCachedCellInfo();
2784 }
2785
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002786 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002787 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2791 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002792 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002793 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 if (info != null) cellInfos.addAll(info);
2795 }
2796 return cellInfos;
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 }
2800 }
2801
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002802 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002803 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2804 String callingFeatureId) {
2805 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2806 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002807 }
2808
2809 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002810 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2811 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002812 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002813 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002814 }
2815
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002816 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2817 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002818 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002819 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002820
2821 LocationAccessPolicy.LocationPermissionResult locationResult =
2822 LocationAccessPolicy.checkLocationPermission(mApp,
2823 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2824 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002825 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002826 .setCallingPid(Binder.getCallingPid())
2827 .setCallingUid(Binder.getCallingUid())
2828 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002829 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2830 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002831 .build());
2832 switch (locationResult) {
2833 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002834 if (TelephonyPermissions
2835 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002836 // Safetynet logging for b/154934934
2837 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2838 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002839 throw new SecurityException("Not allowed to access cell info");
2840 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002841 if (TelephonyPermissions
2842 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002843 // Safetynet logging for b/154934934
2844 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2845 }
Nathan Harold5320c422019-05-09 10:26:08 -07002846 try {
2847 cb.onCellInfo(new ArrayList<CellInfo>());
2848 } catch (RemoteException re) {
2849 // Drop without consequences
2850 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002851 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002852 }
2853
Nathan Harolda939a962019-05-09 10:13:47 -07002854
2855 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002856 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2857
2858 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2859 }
2860
2861 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002863 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
Shishir Agrawala9f32182016-04-12 12:00:16 -07002874 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002876 Phone phone = PhoneFactory.getPhone(slotIndex);
2877 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002878 return null;
2879 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002880 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002881 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002882 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002883 return null;
2884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 return phone.getImei();
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
2891 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002892 }
2893
2894 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002895 public String getTypeAllocationCodeForSlot(int slotIndex) {
2896 Phone phone = PhoneFactory.getPhone(slotIndex);
2897 String tac = null;
2898 if (phone != null) {
2899 String imei = phone.getImei();
2900 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2901 }
2902 return tac;
2903 }
2904
2905 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002906 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002907 Phone phone = PhoneFactory.getPhone(slotIndex);
2908 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002909 return null;
2910 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911
Jeff Davidson913390f2018-02-23 17:11:49 -08002912 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002913 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002914 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002915 return null;
2916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 return phone.getMeid();
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
Jack Yu2af8d712017-03-15 17:14:14 -07002924 }
2925
2926 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002927 public String getManufacturerCodeForSlot(int slotIndex) {
2928 Phone phone = PhoneFactory.getPhone(slotIndex);
2929 String manufacturerCode = null;
2930 if (phone != null) {
2931 String meid = phone.getMeid();
2932 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2933 }
2934 return manufacturerCode;
2935 }
2936
2937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002938 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2939 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002940 Phone phone = PhoneFactory.getPhone(slotIndex);
2941 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002942 return null;
2943 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002944 int subId = phone.getSubId();
2945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002946 mApp, subId, callingPackage, callingFeatureId,
2947 "getDeviceSoftwareVersionForSlot")) {
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.getDeviceSvn();
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002957 }
2958
fionaxu43304da2017-11-27 22:51:16 -08002959 @Override
2960 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = getPhone(subId);
2964 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
fionaxu43304da2017-11-27 22:51:16 -08002968 }
2969
2970 @Override
2971 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone phone = getPhone(subId);
2975 return phone == null ? null : phone.getCarrierName();
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
fionaxu43304da2017-11-27 22:51:16 -08002979 }
2980
calvinpanffe225e2018-11-01 19:43:06 +08002981 @Override
chen xu0026ca62019-03-06 15:28:50 -08002982 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 final Phone phone = getPhone(subId);
2986 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002987 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 @Override
chen xu0026ca62019-03-06 15:28:50 -08002994 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002998 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
chen xu651eec72018-11-11 19:03:44 -08003004 @Override
chen xu864e11c2018-12-06 22:10:03 -08003005 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3006 if (!isSubscriptionMccMnc) {
3007 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3008 }
chen xu651eec72018-11-11 19:03:44 -08003009 final Phone phone = PhoneFactory.getPhone(slotIndex);
3010 if (phone == null) {
3011 return TelephonyManager.UNKNOWN_CARRIER_ID;
3012 }
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 }
3020
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 //
3022 // Internal helper methods.
3023 //
3024
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003025 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3027 *
3028 * @throws SecurityException if the caller does not have the required permission
3029 */
3030 private void enforceModifyPermission() {
3031 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3032 }
3033
Shuo Qiancd19c462020-01-16 20:51:11 -08003034 /**
3035 * Make sure the caller is system.
3036 *
3037 * @throws SecurityException if the caller is not system.
3038 */
3039 private void enforceSystemCaller() {
3040 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3041 throw new SecurityException("Caller must be system");
3042 }
3043 }
3044
Shuo Qian3b6ee772019-11-13 17:43:31 -08003045 private void enforceActiveEmergencySessionPermission() {
3046 mApp.enforceCallingOrSelfPermission(
3047 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3048 }
3049
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 /**
3051 * Make sure the caller has the CALL_PHONE permission.
3052 *
3053 * @throws SecurityException if the caller does not have the required permission
3054 */
3055 private void enforceCallPermission() {
3056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3057 }
3058
paulhu5a773602019-08-23 19:17:33 +08003059 private void enforceSettingsPermission() {
3060 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003061 }
3062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 private String createTelUrl(String number) {
3064 if (TextUtils.isEmpty(number)) {
3065 return null;
3066 }
3067
Jake Hambye994d462014-02-03 13:10:13 -08003068 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 }
3070
Ihab Awadf9e92732013-12-05 18:02:52 -08003071 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3073 }
3074
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003075 private static void logv(String msg) {
3076 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3077 }
3078
Ihab Awadf9e92732013-12-05 18:02:52 -08003079 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3081 }
3082
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003083 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003085 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003086 }
3087
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003089 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 final Phone phone = PhoneFactory.getPhone(slotIndex);
3093 if (phone == null) {
3094 return PhoneConstants.PHONE_TYPE_NONE;
3095 } else {
3096 return phone.getPhoneType();
3097 }
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 }
3102
3103 /**
3104 * Returns the CDMA ERI icon index to display
3105 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003107 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3108 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3109 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003110 }
3111
Sanket Padawe356d7632015-06-22 14:03:32 -07003112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003113 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3114 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003116 mApp, subId, callingPackage, callingFeatureId,
3117 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003118 return -1;
3119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120
3121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 final Phone phone = getPhone(subId);
3124 if (phone != null) {
3125 return phone.getCdmaEriIconIndex();
3126 } else {
3127 return -1;
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 /**
3135 * Returns the CDMA ERI icon mode,
3136 * 0 - ON
3137 * 1 - FLASHING
3138 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003140 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3141 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3142 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003143 }
3144
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003146 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3147 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003149 mApp, subId, callingPackage, callingFeatureId,
3150 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003151 return -1;
3152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 final Phone phone = getPhone(subId);
3157 if (phone != null) {
3158 return phone.getCdmaEriIconMode();
3159 } else {
3160 return -1;
3161 }
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 }
3166
3167 /**
3168 * Returns the CDMA ERI text,
3169 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003171 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3172 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3173 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003174 }
3175
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003177 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3178 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 mApp, subId, callingPackage, callingFeatureId,
3181 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003182 return null;
3183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
3188 if (phone != null) {
3189 return phone.getCdmaEriText();
3190 } else {
3191 return null;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
3198 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003199 * Returns the CDMA MDN.
3200 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003201 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003202 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3204 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205
3206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 return phone.getLine1Number();
3211 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 return null;
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003217 }
3218 }
3219
3220 /**
3221 * Returns the CDMA MIN.
3222 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003224 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3226 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 final Phone phone = getPhone(subId);
3231 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3232 return phone.getCdmaMin();
3233 } else {
3234 return null;
3235 }
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003238 }
3239 }
3240
Hall Liud892bec2018-11-30 14:51:45 -08003241 @Override
3242 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3243 INumberVerificationCallback callback, String callingPackage) {
3244 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3245 != PERMISSION_GRANTED) {
3246 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3247 }
3248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3249
3250 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3251 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3252 throw new SecurityException("Calling package must be configured in the device config");
3253 }
3254
3255 if (range == null) {
3256 throw new NullPointerException("Range must be non-null");
3257 }
3258
3259 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003260 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003261
3262 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3263 }
3264
Junda Liuca05d5d2014-08-14 22:36:34 -07003265 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 * Returns true if CDMA provisioning needs to run.
3267 */
3268 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 }
3276
3277 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003278 * Sets the voice mail number of a given subId.
3279 */
3280 @Override
3281 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3283 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3288 new Pair<String, String>(alphaTag, number), new Integer(subId));
3289 return success;
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003293 }
3294
Ta-wei Yen87c49842016-05-13 21:19:52 -07003295 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003296 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3297 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003298 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3299 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003300 if (!TextUtils.equals(callingPackage, systemDialer)) {
3301 throw new SecurityException("caller must be system dialer");
3302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3307 if (phoneAccountHandle == null) {
3308 return null;
3309 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311 } finally {
3312 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003313 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003314 }
3315
3316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003317 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3318 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003321 mApp, subId, callingPackage, callingFeatureId,
3322 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003323 return null;
3324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003326 final long identity = Binder.clearCallingIdentity();
3327 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003329 } finally {
3330 Binder.restoreCallingIdentity(identity);
3331 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003332 }
3333
3334 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003335 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3336 VisualVoicemailSmsFilterSettings settings) {
3337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003342 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003346 }
3347
3348 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003349 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3350 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003355 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003359 }
3360
3361 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003362 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3363 String callingPackage, int subId) {
3364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365
3366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003369 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370 } finally {
3371 Binder.restoreCallingIdentity(identity);
3372 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003373 }
3374
3375 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003376 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003382 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003386 }
3387
3388 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003389 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3390 String callingAttributionTag, int subId, String number, int port, String text,
3391 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003393 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003394 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003395 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003396 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3397 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003398 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003399
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003400 /**
fionaxu0152e512016-11-14 13:36:14 -08003401 * Sets the voice activation state of a given subId.
3402 */
3403 @Override
3404 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3406 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 if (phone != null) {
3412 phone.setVoiceActivationState(activationState);
3413 } else {
3414 loge("setVoiceActivationState fails with invalid subId: " + subId);
3415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003418 }
3419 }
3420
3421 /**
3422 * Sets the data activation state of a given subId.
3423 */
3424 @Override
3425 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3427 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 final Phone phone = getPhone(subId);
3432 if (phone != null) {
3433 phone.setDataActivationState(activationState);
3434 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003435 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436 }
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003439 }
3440 }
3441
3442 /**
3443 * Returns the voice activation state of a given subId.
3444 */
3445 @Override
3446 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448
fionaxu0152e512016-11-14 13:36:14 -08003449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 if (phone != null) {
3453 return phone.getVoiceActivationState();
3454 } else {
3455 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3456 }
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003459 }
3460 }
3461
3462 /**
3463 * Returns the data activation state of a given subId.
3464 */
3465 @Override
3466 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468
fionaxu0152e512016-11-14 13:36:14 -08003469 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 if (phone != null) {
3473 return phone.getDataActivationState();
3474 } else {
3475 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3476 }
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003479 }
3480 }
3481
3482 /**
Wink Saville36469e72014-06-11 15:17:00 -07003483 * Returns the unread count of voicemails for a subId
3484 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003486 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3487 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 mApp, subId, callingPackage, callingFeatureId,
3490 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003491 return 0;
3492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 final Phone phone = getPhone(subId);
3496 if (phone != null) {
3497 return phone.getVoiceMessageCount();
3498 } else {
3499 return 0;
3500 }
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 }
3505
3506 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003507 * returns true, if the device is in a state where both voice and data
3508 * are supported simultaneously. This can change based on location or network condition.
3509 */
3510 @Override
3511 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 final Phone phone = getPhone(subId);
3515 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003519 }
3520
3521 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003522 * Send the dialer code if called from the current default dialer or the caller has
3523 * carrier privilege.
3524 * @param inputCode The dialer code to send
3525 */
3526 @Override
3527 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003528 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003530 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3531 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003532 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003533 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
fionaxu235cc5e2017-03-06 22:25:57 -08003543 }
3544
Pengquan Menga1bb6272018-09-06 09:59:22 -07003545 @Override
3546 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003547 TelephonyPermissions
3548 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3549 mApp, subId, "getNetworkSelectionMode");
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 if (!isActiveSubscription(subId)) {
3553 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3554 }
3555 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003559 }
3560
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003562 public boolean isInEmergencySmsMode() {
3563 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 for (Phone phone : PhoneFactory.getPhones()) {
3567 if (phone.isInEmergencySmsMode()) {
3568 return true;
3569 }
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 return false;
3575 }
3576
shilu366312e2019-12-17 09:28:10 -08003577 /**
3578 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3579 * @param subId The subscription to use to check the configuration.
3580 * @param c The callback that will be used to send the result.
3581 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003582 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003583 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3584 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003585 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3586 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003587
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003588 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3589 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3590 "IMS not available on device.");
3591 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 final long token = Binder.clearCallingIdentity();
3593 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003597 } catch (ImsException e) {
3598 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 } finally {
3600 Binder.restoreCallingIdentity(token);
3601 }
3602 }
3603
shilu366312e2019-12-17 09:28:10 -08003604 /**
3605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3606 * @param subId The subscription to use to check the configuration.
3607 * @param c The callback that will be used to send the result.
3608 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003610 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003611 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3612 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003613 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3614 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3615 }
Meng Wangafbc5852019-09-19 17:37:13 -07003616 final long token = Binder.clearCallingIdentity();
3617 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003618 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003619 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3620 .removeRegistrationCallbackForSubscription(c, subId);
3621 } catch (ImsException e) {
3622 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3623 + "is inactive, ignoring unregister.");
3624 // If the subscription is no longer active, just return, since the callback
3625 // will already have been removed internally.
3626 } finally {
3627 Binder.restoreCallingIdentity(token);
3628 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 }
3630
Brad Ebingera34a6c22019-10-22 17:36:18 -07003631 /**
3632 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3633 */
3634 @Override
3635 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3636 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3637 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3638 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3639 "IMS not available on device.");
3640 }
3641 final long token = Binder.clearCallingIdentity();
3642 try {
3643 Phone phone = getPhone(subId);
3644 if (phone == null) {
3645 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3646 + subId + "'");
3647 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3648 }
3649 phone.getImsRegistrationState(regState -> {
3650 try {
3651 consumer.accept((regState == null)
3652 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3653 } catch (RemoteException e) {
3654 // Ignore if the remote process is no longer available to call back.
3655 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3656 }
3657 });
3658 } finally {
3659 Binder.restoreCallingIdentity(token);
3660 }
3661 }
3662
3663 /**
3664 * Get the transport type for the IMS service registration state.
3665 */
3666 @Override
3667 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003668 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3669 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003670 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3672 "IMS not available on device.");
3673 }
3674 final long token = Binder.clearCallingIdentity();
3675 try {
3676 Phone phone = getPhone(subId);
3677 if (phone == null) {
3678 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3679 + subId + "'");
3680 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3681 }
3682 phone.getImsRegistrationTech(regTech -> {
3683 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3684 int regTechConverted = (regTech == null)
3685 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3686 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3687 regTechConverted);
3688 try {
3689 consumer.accept(regTechConverted);
3690 } catch (RemoteException e) {
3691 // Ignore if the remote process is no longer available to call back.
3692 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3693 }
3694 });
3695 } finally {
3696 Binder.restoreCallingIdentity(token);
3697 }
3698 }
3699
shilu366312e2019-12-17 09:28:10 -08003700 /**
3701 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3702 * @param subId The subscription to use to check the configuration.
3703 * @param c The callback that will be used to send the result.
3704 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003706 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3707 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003708 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3709 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003710 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3712 "IMS not available on device.");
3713 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3715 final long token = Binder.clearCallingIdentity();
3716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 } catch (ImsException e) {
3720 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 } finally {
3722 Binder.restoreCallingIdentity(token);
3723 }
3724 }
3725
shilu366312e2019-12-17 09:28:10 -08003726 /**
3727 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3728 * @param subId The subscription to use to check the configuration.
3729 * @param c The callback that will be used to send the result.
3730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003732 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003733 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3734 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3736 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3737 }
Meng Wangafbc5852019-09-19 17:37:13 -07003738
3739 final long token = Binder.clearCallingIdentity();
3740 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003741 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003743 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003744 } catch (ImsException e) {
3745 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3746 + "is inactive, ignoring unregister.");
3747 // If the subscription is no longer active, just return, since the callback
3748 // will already have been removed internally.
3749 } finally {
3750 Binder.restoreCallingIdentity(token);
3751 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 }
3753
3754 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003755 public boolean isCapable(int subId, int capability, int regTech) {
3756 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3758 final long token = Binder.clearCallingIdentity();
3759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3764 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003765 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003766 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3767 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 } finally {
3769 Binder.restoreCallingIdentity(token);
3770 }
3771 }
3772
3773 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003774 public boolean isAvailable(int subId, int capability, int regTech) {
3775 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003776 final long token = Binder.clearCallingIdentity();
3777 try {
3778 Phone phone = getPhone(subId);
3779 if (phone == null) return false;
3780 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003781 } catch (com.android.ims.ImsException e) {
3782 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3783 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 } finally {
3785 Binder.restoreCallingIdentity(token);
3786 }
3787 }
3788
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003789 /**
3790 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3791 * subscription.
3792 * @param subId The subscription to use to check the configuration.
3793 * @param callback The callback that will be used to send the result.
3794 * @param capability The MmTelFeature capability that will be used to send the result.
3795 * @param transportType The transport type of the MmTelFeature capability.
3796 */
3797 @Override
3798 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3799 int transportType) {
3800 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3801 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3803 "IMS not available on device.");
3804 }
3805 final long token = Binder.clearCallingIdentity();
3806 try {
3807 int slotId = getSlotIndex(subId);
3808 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3809 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3810 + subId + "'");
3811 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3812 }
3813 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3814 transportType, aBoolean -> {
3815 try {
3816 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3817 } catch (RemoteException e) {
3818 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3819 + "running. Ignore");
3820 }
3821 });
3822 } finally {
3823 Binder.restoreCallingIdentity(token);
3824 }
3825 }
3826
shilu366312e2019-12-17 09:28:10 -08003827 /**
3828 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3829 * @param subId The subscription to use to check the configuration.
3830 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 @Override
3832 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003833 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3834 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003835
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3837 final long token = Binder.clearCallingIdentity();
3838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003841 } catch (ImsException e) {
3842 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 } finally {
3844 Binder.restoreCallingIdentity(token);
3845 }
3846 }
3847
3848 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003849 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003851 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003855 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003857 } catch (ImsException e) {
3858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862 }
3863
shilu366312e2019-12-17 09:28:10 -08003864 /**
3865 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3866 * @param subId The subscription to use to check the configuration.
3867 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003869 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003870 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3871 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003875 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3876 } catch (ImsException e) {
3877 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
3881 }
3882
3883 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003884 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003886 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003891 } catch (ImsException e) {
3892 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
3896 }
3897
shilu366312e2019-12-17 09:28:10 -08003898 /**
3899 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3900 * @param subId The subscription to use to check the configuration.
3901 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 @Override
3903 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003904 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3905 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003911 } catch (ImsException e) {
3912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
3916 }
3917
3918 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003919 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003921 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003925 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (ImsException e) {
3927 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
3931 }
3932
shilu366312e2019-12-17 09:28:10 -08003933 /**
3934 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3935 * @param subId The subscription to use to check the configuration.
3936 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 @Override
3938 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003939 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3940 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003946 } catch (ImsException e) {
3947 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
3951 }
3952
3953 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003954 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003956 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003962 } catch (ImsException e) {
3963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
3967 }
3968
3969 @Override
3970 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3972 "setVoWiFiNonPersistent");
3973 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 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003977 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
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
shilu366312e2019-12-17 09:28:10 -08003985 /**
3986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3987 * @param subId The subscription to use to check the configuration.
3988 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 @Override
3990 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003991 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3992 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003996 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003998 } catch (ImsException e) {
3999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
4003 }
4004
4005 @Override
4006 public void setVoWiFiModeSetting(int subId, int mode) {
4007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4008 "setVoWiFiModeSetting");
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004014 } catch (ImsException e) {
4015 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
4019 }
4020
4021 @Override
4022 public int getVoWiFiRoamingModeSetting(int subId) {
4023 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004027 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 } catch (ImsException e) {
4030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
4034 }
4035
4036 @Override
4037 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4039 "setVoWiFiRoamingModeSetting");
4040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004043 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004045 } catch (ImsException e) {
4046 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 } finally {
4048 Binder.restoreCallingIdentity(identity);
4049 }
4050 }
4051
4052 @Override
4053 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4055 "setRttCapabilityEnabled");
4056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004059 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4060 } catch (ImsException e) {
4061 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 } finally {
4063 Binder.restoreCallingIdentity(identity);
4064 }
4065 }
4066
shilu366312e2019-12-17 09:28:10 -08004067 /**
4068 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4069 * @param subId The subscription to use to check the configuration.
4070 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 @Override
4072 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004073 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4074 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004078 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 } catch (ImsException e) {
4081 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
4085 }
4086
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004087 @Override
4088 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4089 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004092 if (!isImsAvailableOnDevice()) {
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4094 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004095 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004098 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
4106 @Override
4107 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4108 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4109 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4111 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4112 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004115 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004116 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004117 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004118 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4119 + "is inactive, ignoring unregister.");
4120 // If the subscription is no longer active, just return, since the callback will already
4121 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
4125 }
4126
allenwtsu99c623b2020-01-03 18:24:23 +08004127
4128 private void checkModifyPhoneStatePermission(int subId, String message) {
4129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4130 message);
4131 }
4132
4133 private boolean isImsProvisioningRequired(int subId, int capability,
4134 boolean isMmtelCapability) {
4135 Phone phone = getPhone(subId);
4136 if (phone == null) {
4137 loge("phone instance null for subid " + subId);
4138 return false;
4139 }
4140 if (isMmtelCapability) {
4141 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4142 return false;
4143 }
4144 } else {
4145 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4146 return false;
4147 }
4148 }
4149 return true;
4150 }
4151
4152 @Override
4153 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4154 boolean isProvisioned) {
4155 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4156
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4160 if (!isImsProvisioningRequired(subId, capability, false)) {
4161 return;
4162 }
4163
4164 // this capability requires provisioning, route to the correct API.
4165 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4166 switch (capability) {
4167 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4168 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4169 ims.setEabProvisioned(isProvisioned);
4170 break;
4171 default: {
4172 throw new IllegalArgumentException("Tried to set provisioning for "
4173 + "rcs capability '" + capability + "', which does not require "
4174 + "provisioning.");
4175 }
4176 }
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
4179 }
4180
4181 }
4182
4183
4184 @Override
4185 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4186 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4190 if (!isImsProvisioningRequired(subId, capability, false)) {
4191 return true;
4192 }
4193
4194 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4195 switch (capability) {
4196 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4197 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4198 return ims.isEabProvisionedOnDevice();
4199
4200 default: {
4201 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4202 + "capability '" + capability + "', which does not require "
4203 + "provisioning.");
4204 }
4205 }
4206
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004212 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004213 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4214 boolean isProvisioned) {
4215 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4216 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4217 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4218 }
allenwtsu99c623b2020-01-03 18:24:23 +08004219 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004223 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004224 return;
4225 }
4226
4227 // this capability requires provisioning, route to the correct API.
4228 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4229 switch (capability) {
4230 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4231 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4232 ims.setVolteProvisioned(isProvisioned);
4233 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4234 ims.setWfcProvisioned(isProvisioned);
4235 }
4236 break;
4237 }
4238 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4239 // There is currently no difference in VT provisioning type.
4240 ims.setVtProvisioned(isProvisioned);
4241 break;
4242 }
4243 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4244 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4245 // change the capability of the feature instead if needed.
4246 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4247 == isProvisioned) {
4248 // No change in provisioning.
4249 return;
4250 }
4251 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4252 try {
4253 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004254 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004255 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4256 + ", Exception" + e.getMessage());
4257 }
4258 break;
4259 }
4260 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004261 throw new IllegalArgumentException("Tried to set provisioning for "
4262 + "MmTel capability '" + capability + "', which does not require "
4263 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 }
4265 }
4266
4267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
4272 @Override
4273 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4274 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4275 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4276 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4277 }
4278 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004282 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004283 return true;
4284 }
4285
4286 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4287 switch (capability) {
4288 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4289 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4290 return ims.isVolteProvisionedOnDevice();
4291 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4292 return ims.isWfcProvisionedOnDevice();
4293 }
4294 // This should never happen, since we are checking tech above to make sure it
4295 // is either LTE or IWLAN.
4296 throw new IllegalArgumentException("Invalid radio technology for voice "
4297 + "capability.");
4298 }
4299 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4300 // There is currently no difference in VT provisioning type.
4301 return ims.isVtProvisionedOnDevice();
4302 }
4303 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4304 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4305 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4306 }
4307 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004308 throw new IllegalArgumentException(
4309 "Tried to get provisioning for MmTel capability '" + capability
4310 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004311 }
4312 }
4313
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317 }
4318
4319 @Override
4320 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4321 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4322 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4323 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4324 }
4325 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4326 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4327 return (provisionedBits & capability) > 0;
4328 }
4329
4330 @Override
4331 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4332 boolean isProvisioned) {
4333 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4334 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4335 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4336 }
4337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4338 "setProvisioningStatusForCapability");
4339 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4340 // If the current provisioning status for capability already matches isProvisioned,
4341 // do nothing.
4342 if (((provisionedBits & capability) > 0) == isProvisioned) {
4343 return;
4344 }
4345 if (isProvisioned) {
4346 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4347 } else {
4348 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4349 }
4350 }
4351
4352 /**
4353 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4354 * technology. The bitfield should mirror the bitfield defined by
4355 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4356 */
4357 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4358 String key = getMmTelProvisioningKey(subId, tech);
4359 // Default is no capabilities are provisioned.
4360 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4361 }
4362
4363 /**
4364 * Sets the MmTel capability provisioning bitfield (defined by
4365 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4366 * technology specified.
4367 *
4368 * Note: This is a synchronous command and should not be called on UI thread.
4369 */
4370 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4371 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4372 String key = getMmTelProvisioningKey(subId, tech);
4373 editor.putInt(key, newField);
4374 editor.commit();
4375 }
4376
4377 private static String getMmTelProvisioningKey(int subId, int tech) {
4378 // resulting key is provision_ims_mmtel_{subId}_{tech}
4379 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4380 }
4381
4382 /**
4383 * Query CarrierConfig to see if the specified capability requires provisioning for the
4384 * carrier associated with the subscription id.
4385 */
4386 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4387 int capability) {
4388 CarrierConfigManager configManager = new CarrierConfigManager(context);
4389 PersistableBundle c = configManager.getConfigForSubId(subId);
4390 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004391 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004392 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4393 false);
4394 boolean requireVoiceVtProvisioning = c.getBoolean(
4395 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4396
4397 // First check to make sure that the capability requires provisioning.
4398 switch (capability) {
4399 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4400 // intentional fallthrough
4401 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4402 if (requireVoiceVtProvisioning) {
4403 // Voice and Video requires provisioning
4404 return true;
4405 }
4406 break;
4407 }
4408 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4409 if (requireUtProvisioning) {
4410 // UT requires provisioning
4411 return true;
4412 }
4413 break;
4414 }
4415 }
4416 return false;
4417 }
4418
allenwtsu99c623b2020-01-03 18:24:23 +08004419 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4420 int capability) {
4421 CarrierConfigManager configManager = new CarrierConfigManager(context);
4422 PersistableBundle c = configManager.getConfigForSubId(subId);
4423
4424 boolean requireRcsProvisioning = c.getBoolean(
4425 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4426
4427 // First check to make sure that the capability requires provisioning.
4428 switch (capability) {
4429 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4430 // intentional fallthrough
4431 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4432 if (requireRcsProvisioning) {
4433 // OPTION or PRESENCE requires provisioning
4434 return true;
4435 }
4436 break;
4437 }
4438 }
4439 return false;
4440 }
4441
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004442 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004443 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004444 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4445 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4446 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004447 enforceReadPrivilegedPermission("getImsProvisioningInt");
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004451 int slotId = getSlotIndex(subId);
4452 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4453 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4454 + subId + "' for key:" + key);
4455 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4456 }
4457 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004459 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4460 + subId + "' for key:" + key);
4461 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
4465 }
4466
4467 @Override
4468 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004469 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4470 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4471 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004472 enforceReadPrivilegedPermission("getImsProvisioningString");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
4475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004476 int slotId = getSlotIndex(subId);
4477 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4478 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4479 + subId + "' for key:" + key);
4480 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4481 }
4482 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004484 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4485 + subId + "' for key:" + key);
4486 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
4490 }
4491
4492 @Override
4493 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004494 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4495 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4496 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4498 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004502 int slotId = getSlotIndex(subId);
4503 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4504 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4505 + subId + "' for key:" + key);
4506 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4507 }
4508 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004509 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004510 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4511 + "' for key:" + key);
4512 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
4518 @Override
4519 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4521 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4522 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4524 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004525 final long identity = Binder.clearCallingIdentity();
4526 try {
4527 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004528 int slotId = getSlotIndex(subId);
4529 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4530 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4531 + subId + "' for key:" + key);
4532 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4533 }
4534 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004536 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4537 + "' for key:" + key);
4538 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
4542 }
4543
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 int slotId = SubscriptionManager.getSlotIndex(subId);
4546 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004547 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4548 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 }
4550 return slotId;
4551 }
4552
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004553 private int getSlotIndex(int subId) {
4554 int slotId = SubscriptionManager.getSlotIndex(subId);
4555 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4556 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4557 }
4558 return slotId;
4559 }
4560
Wink Saville36469e72014-06-11 15:17:00 -07004561 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004562 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004563 */
4564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004565 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4566 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004567 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004568 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004569 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004570 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004571 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004572 mApp, subId, callingPackage, callingFeatureId,
4573 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004574 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4575 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 final Phone phone = getPhone(subId);
4580 if (phone != null) {
4581 return phone.getServiceState().getDataNetworkType();
4582 } else {
4583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4584 }
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004588 }
4589
4590 /**
4591 * Returns the data network type
4592 */
4593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004594 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4595 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4596 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004597 }
4598
4599 /**
4600 * Returns the data network type for a subId
4601 */
4602 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004603 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4604 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004606 mApp, subId, callingPackage, callingFeatureId,
4607 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004608 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4609 }
4610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 final Phone phone = getPhone(subId);
4614 if (phone != null) {
4615 return phone.getServiceState().getDataNetworkType();
4616 } else {
4617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4618 }
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004622 }
4623
4624 /**
Wink Saville36469e72014-06-11 15:17:00 -07004625 * Returns the Voice network type for a subId
4626 */
4627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004628 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4629 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004631 mApp, subId, callingPackage, callingFeatureId,
4632 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004633 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4634 }
4635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 final Phone phone = getPhone(subId);
4639 if (phone != null) {
4640 return phone.getServiceState().getVoiceNetworkType();
4641 } else {
4642 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4643 }
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004647 }
4648
4649 /**
4650 * @return true if a ICC card is present
4651 */
4652 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004653 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004654 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4655 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004656 }
4657
4658 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004659 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004660 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004661 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004662 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 final Phone phone = PhoneFactory.getPhone(slotIndex);
4666 if (phone != null) {
4667 return phone.getIccCard().hasIccCard();
4668 } else {
4669 return false;
4670 }
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004674 }
4675
4676 /**
4677 * Return if the current radio is LTE on CDMA. This
4678 * is a tri-state return value as for a period of time
4679 * the mode may be unknown.
4680 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004681 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004682 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004683 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004684 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004685 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004686 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4687 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4688 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004689 }
4690
Sanket Padawe356d7632015-06-22 14:03:32 -07004691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004692 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4693 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004694 try {
4695 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4696 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004697 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4698 }
4699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 final Phone phone = getPhone(subId);
4703 if (phone == null) {
4704 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4705 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004706 return TelephonyProperties.lte_on_cdma_device()
4707 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708 }
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004711 }
Wink Saville36469e72014-06-11 15:17:00 -07004712 }
4713
Wink Saville36469e72014-06-11 15:17:00 -07004714 /**
4715 * {@hide}
4716 * Returns Default subId, 0 in the case of single standby.
4717 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004718 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004719 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004720 }
4721
Shishir Agrawala9f32182016-04-12 12:00:16 -07004722 private int getSlotForDefaultSubscription() {
4723 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4724 }
4725
Wink Savilleb564aae2014-10-23 10:18:09 -07004726 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004727 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004728 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004729
Pengquan Menge92a50d2018-09-21 15:54:48 -07004730 private boolean isActiveSubscription(int subId) {
4731 return mSubscriptionController.isActiveSubId(subId);
4732 }
4733
Ihab Awadf2177b72013-11-25 13:33:23 -08004734 /**
4735 * @see android.telephony.TelephonyManager.WifiCallingChoices
4736 */
4737 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004740 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4742 getWhenToMakeWifiCallsDefaultPreference());
4743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004746 }
4747
4748 /**
4749 * @see android.telephony.TelephonyManager.WifiCallingChoices
4750 */
4751 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 final long identity = Binder.clearCallingIdentity();
4753 try {
4754 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004755 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004760 }
4761
Sailesh Nepald1e68152013-12-12 19:08:02 -08004762 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004763 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004764 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004765 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004766
Jordan Liu4c733742019-02-28 12:03:40 -08004767 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4768 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4769 if (phoneId == -1) {
4770 throw new IllegalArgumentException("Given slot index: " + slotIndex
4771 + " does not correspond to an active phone");
4772 }
4773 return PhoneFactory.getPhone(phoneId);
4774 }
4775
Shishir Agrawal566b7612013-10-28 14:41:00 -07004776 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004777 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4778 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4780 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004782 if (DBG) {
4783 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4784 }
4785 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4786 p2);
4787 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004788
Jordan Liu4c733742019-02-28 12:03:40 -08004789
4790 @Override
4791 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4792 int slotIndex, String callingPackage, String aid, int p2) {
4793 enforceModifyPermission();
4794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4795 if (DBG) {
4796 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4797 }
4798 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4799 callingPackage, aid, p2);
4800 }
4801
4802 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4803 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 final long identity = Binder.clearCallingIdentity();
4805 try {
4806 if (TextUtils.equals(ISDR_AID, aid)) {
4807 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004808 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4809 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 if (bestComponent == null
4811 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4812 loge("The calling package is not allowed to access ISD-R.");
4813 throw new SecurityException(
4814 "The calling package is not allowed to access ISD-R.");
4815 }
Derek Tan740e1672017-06-27 14:56:27 -07004816 }
Derek Tan740e1672017-06-27 14:56:27 -07004817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004819 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4820 null /* workSource */);
4821 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 return response;
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
4825 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004826 }
4827
4828 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004829 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4831 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004832 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4833 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004835
Jordan Liu4c733742019-02-28 12:03:40 -08004836 @Override
4837 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4838 enforceModifyPermission();
4839 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4840 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4841 channel);
4842 }
4843
4844 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 final long identity = Binder.clearCallingIdentity();
4846 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 if (channel < 0) {
4848 return false;
4849 }
Jordan Liu4c733742019-02-28 12:03:40 -08004850 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4851 null /* workSource */);
4852 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 return success;
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004856 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004857 }
4858
4859 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004860 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004861 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4863 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004864 if (DBG) {
4865 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4866 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4867 + p3 + " data=" + data);
4868 }
4869 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4870 command, p1, p2, p3, data);
4871 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004872
Jordan Liu4c733742019-02-28 12:03:40 -08004873 @Override
4874 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4875 int command, int p1, int p2, int p3, String data) {
4876 enforceModifyPermission();
4877 if (DBG) {
4878 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4879 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4880 + p3 + " data=" + data);
4881 }
4882 return iccTransmitApduLogicalChannelWithPermission(
4883 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4884 data);
4885 }
4886
4887 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4888 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004891 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 return "";
4893 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004896 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4897 null /* workSource */);
4898 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 // Append the returned status code to the end of the response payload.
4901 String s = Integer.toHexString(
4902 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4903 if (response.payload != null) {
4904 s = IccUtils.bytesToHexString(response.payload) + s;
4905 }
4906 return s;
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004909 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004910 }
Jake Hambye994d462014-02-03 13:10:13 -08004911
Evan Charltonc66da362014-05-16 14:06:40 -07004912 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004913 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4914 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4916 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004918 if (DBG) {
4919 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4920 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4921 }
4922 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4923 cla, command, p1, p2, p3, data);
4924 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004925
Jordan Liu4c733742019-02-28 12:03:40 -08004926 @Override
4927 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4928 int command, int p1, int p2, int p3, String data) {
4929 enforceModifyPermission();
4930 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4931 if (DBG) {
4932 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4933 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4934 + " data=" + data);
4935 }
4936
4937 return iccTransmitApduBasicChannelWithPermission(
4938 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4939 p2, p3, data);
4940 }
4941
4942 // open APDU basic channel assuming the caller has sufficient permissions
4943 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4944 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4948 && TextUtils.equals(ISDR_AID, data)) {
4949 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004950 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4951 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 if (bestComponent == null
4953 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4954 loge("The calling package is not allowed to select ISD-R.");
4955 throw new SecurityException(
4956 "The calling package is not allowed to select ISD-R.");
4957 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004958 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004961 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4962 null /* workSource */);
4963 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 // Append the returned status code to the end of the response payload.
4966 String s = Integer.toHexString(
4967 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4968 if (response.payload != null) {
4969 s = IccUtils.bytesToHexString(response.payload) + s;
4970 }
4971 return s;
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004974 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004975 }
4976
4977 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004978 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004979 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4981 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 if (DBG) {
4986 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4987 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4988 }
4989
4990 IccIoResult response =
4991 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4992 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4993 subId);
4994
4995 if (DBG) {
4996 log("Exchange SIM_IO [R]" + response);
4997 }
4998
4999 byte[] result = null;
5000 int length = 2;
5001 if (response.payload != null) {
5002 length = 2 + response.payload.length;
5003 result = new byte[length];
5004 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5005 } else {
5006 result = new byte[length];
5007 }
5008
5009 result[length - 1] = (byte) response.sw2;
5010 result[length - 2] = (byte) response.sw1;
5011 return result;
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005014 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005015 }
5016
Nathan Haroldb3014052017-01-25 15:57:32 -08005017 /**
5018 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5019 * on a particular subscription
5020 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5022 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005024 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005025 return null;
5026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027
5028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 if (appType != TelephonyManager.APPTYPE_USIM
5031 && appType != TelephonyManager.APPTYPE_SIM) {
5032 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5033 return null;
5034 }
5035 Object response = sendRequest(
5036 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5037 if (response instanceof String[]) {
5038 return (String[]) response;
5039 }
yincheng zhao2737e882019-09-06 17:06:54 -07005040 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005042 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005045 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005046 }
5047
yincheng zhao2737e882019-09-06 17:06:54 -07005048 /**
5049 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5050 * subscription.
5051 *
5052 * @param subId the id of the subscription.
5053 * @param appType the uicc app type, must be USIM or SIM.
5054 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5055 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005056 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005057 * @return number of fplmns that is successfully written to the SIM.
5058 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005059 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5060 String callingFeatureId) {
5061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5062 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005063 if (DBG) logv("no permissions for setForbiddenplmns");
5064 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5065 }
5066 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5067 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5068 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5069 }
5070 if (fplmns == null) {
5071 throw new IllegalArgumentException("Fplmn List provided is null");
5072 }
5073 for (String fplmn : fplmns) {
5074 if (!CellIdentity.isValidPlmn(fplmn)) {
5075 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5076 }
5077 }
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 Object response = sendRequest(
5081 CMD_SET_FORBIDDEN_PLMNS,
5082 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5083 subId);
5084 return (int) response;
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
5088 }
5089
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005090 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005091 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5093 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5098 if (response.payload == null) {
5099 return "";
5100 }
Evan Charltonc66da362014-05-16 14:06:40 -07005101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 // Append the returned status code to the end of the response payload.
5103 String s = Integer.toHexString(
5104 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5105 s = IccUtils.bytesToHexString(response.payload) + s;
5106 return s;
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
Evan Charltonc66da362014-05-16 14:06:40 -07005110 }
5111
Jake Hambye994d462014-02-03 13:10:13 -08005112 /**
5113 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5114 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5115 *
5116 * @param itemID the ID of the item to read
5117 * @return the NV item as a String, or null on error.
5118 */
5119 @Override
5120 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005121 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5123 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124
5125 final long identity = Binder.clearCallingIdentity();
5126 try {
5127 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005128 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5130 return value;
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
5133 }
Jake Hambye994d462014-02-03 13:10:13 -08005134 }
5135
5136 /**
5137 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5138 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5139 *
5140 * @param itemID the ID of the item to read
5141 * @param itemValue the value to write, as a String
5142 * @return true on success; false on any failure
5143 */
5144 @Override
5145 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005146 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5148 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149
5150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5153 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005154 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5156 return success;
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
Jake Hambye994d462014-02-03 13:10:13 -08005160 }
5161
5162 /**
5163 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5164 * Used for device configuration by some CDMA operators.
5165 *
5166 * @param preferredRoamingList byte array containing the new PRL
5167 * @return true on success; false on any failure
5168 */
5169 @Override
5170 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5172 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173
5174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5177 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5178 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5179 return success;
5180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
Jake Hambye994d462014-02-03 13:10:13 -08005183 }
5184
5185 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005186 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005187 * Used for device configuration by some CDMA operators.
5188 *
chen xu6dac5ab2018-10-26 17:39:23 -07005189 * @param slotIndex - device slot.
5190 *
Jake Hambye994d462014-02-03 13:10:13 -08005191 * @return true on success; false on any failure
5192 */
5193 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005194 public boolean resetModemConfig(int slotIndex) {
5195 Phone phone = PhoneFactory.getPhone(slotIndex);
5196 if (phone != null) {
5197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5198 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199
chen xu6dac5ab2018-10-26 17:39:23 -07005200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5203 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5204 return success;
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 }
chen xu6dac5ab2018-10-26 17:39:23 -07005209 return false;
5210 }
5211
5212 /**
5213 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5214 *
5215 * @param slotIndex - device slot.
5216 *
5217 * @return true on success; false on any failure
5218 */
5219 @Override
5220 public boolean rebootModem(int slotIndex) {
5221 Phone phone = PhoneFactory.getPhone(slotIndex);
5222 if (phone != null) {
5223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5224 mApp, phone.getSubId(), "rebootModem");
5225
5226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5229 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5230 return success;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
5234 }
5235 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005236 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005237
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005238 public String[] getPcscfAddress(String apnType, String callingPackage,
5239 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005240 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5242 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005243 return new String[0];
5244 }
5245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 final long identity = Binder.clearCallingIdentity();
5247 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005248 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Wink Saville36469e72014-06-11 15:17:00 -07005252 }
5253
Brad Ebinger51f743a2017-01-23 13:50:20 -08005254 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005255 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5256 * {@link #disableIms(int)}.
5257 * @param slotIndex device slot.
5258 */
5259 public void resetIms(int slotIndex) {
5260 enforceModifyPermission();
5261
5262 final long identity = Binder.clearCallingIdentity();
5263 try {
5264 if (mImsResolver == null) {
5265 // may happen if the does not support IMS.
5266 return;
5267 }
5268 mImsResolver.disableIms(slotIndex);
5269 mImsResolver.enableIms(slotIndex);
5270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
5273 }
5274
5275 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005276 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5277 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005278 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005279 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281
5282 final long identity = Binder.clearCallingIdentity();
5283 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005284 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005285 // may happen if the device does not support IMS.
5286 return;
5287 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005288 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005292 }
5293
5294 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005295 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5296 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005297 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005298 public void disableIms(int slotId) {
5299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005303 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005304 // may happen if the device does not support IMS.
5305 return;
5306 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005307 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005311 }
5312
5313 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005314 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5315 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005316 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005317 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005318 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005319 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320
5321 final long identity = Binder.clearCallingIdentity();
5322 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005323 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005324 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5325 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005326 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005327 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005331 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005332 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005333 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5334 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005335 @Override
5336 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005337 enforceModifyPermission();
5338
5339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005342 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
5346 }
5347
5348 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005349 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005350 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005351 */
5352 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005357 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005358 // may happen if the device does not support IMS.
5359 return null;
5360 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005361 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005365 }
5366
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005367 /**
5368 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005369 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005370 */
5371 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5372 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373
5374 final long identity = Binder.clearCallingIdentity();
5375 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005376 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005377 // may happen if the device does not support IMS.
5378 return null;
5379 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005380 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005384 }
5385
Brad Ebinger884c07b2018-02-15 16:17:40 -08005386 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005387 * Sets the ImsService Package Name that Telephony will bind to.
5388 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005389 * @param slotIndex the slot ID that the ImsService should bind for.
5390 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005391 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005392 * @param featureTypes An integer array of feature types associated with a packageName.
5393 * @param packageName The name of the package that the current configuration will be replaced
5394 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005395 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005396 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005397 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5398 int[] featureTypes, String packageName) {
5399 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5400 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5402 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005403 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005407 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005408 // may happen if the device does not support IMS.
5409 return false;
5410 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005411 Map<Integer, String> featureConfig = new HashMap<>();
5412 for (int featureType : featureTypes) {
5413 featureConfig.put(featureType, packageName);
5414 }
5415 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5416 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005420 }
5421
5422 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005423 * Clears any carrier ImsService overrides for the slot index specified that were previously
5424 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5425 *
5426 * This should only be used for testing.
5427 *
5428 * @param slotIndex the slot ID that the ImsService should bind for.
5429 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5430 */
5431 @Override
5432 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5433 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5435 "clearCarrierImsServiceOverride");
5436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5437 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5438 "clearCarrierImsServiceOverride");
5439
5440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 if (mImsResolver == null) {
5443 // may happen if the device does not support IMS.
5444 return false;
5445 }
5446 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
5450 }
5451
5452 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005453 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005454 *
5455 * @param slotId The slot that the ImsService is associated with.
5456 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5457 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005458 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005459 * @return the package name of the ImsService configuration.
5460 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005461 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5462 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005463 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005464 TelephonyPermissions
5465 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5466 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5467 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005471 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005472 // may happen if the device does not support IMS.
5473 return "";
5474 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005475 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005476 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5477 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005481 }
5482
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005483 /**
5484 * Get the MmTelFeature state associated with the requested subscription id.
5485 * @param subId The subscription that the MmTelFeature is associated with.
5486 * @param callback A callback with an integer containing the
5487 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5488 */
5489 @Override
5490 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5491 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5492 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5493 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5494 "IMS not available on device.");
5495 }
5496 final long token = Binder.clearCallingIdentity();
5497 try {
5498 int slotId = getSlotIndex(subId);
5499 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5500 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5501 + subId + "'");
5502 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5503 }
5504 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5505 try {
5506 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5507 } catch (RemoteException e) {
5508 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5509 + "Ignore");
5510 }
5511 });
5512 } finally {
5513 Binder.restoreCallingIdentity(token);
5514 }
5515 }
5516
Wink Saville36469e72014-06-11 15:17:00 -07005517 public void setImsRegistrationState(boolean registered) {
5518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Wink Saville36469e72014-06-11 15:17:00 -07005526 }
5527
5528 /**
Stuart Scott54788802015-03-30 13:18:01 -07005529 * Set the network selection mode to automatic.
5530 *
5531 */
5532 @Override
5533 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5535 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
shilufc958392020-01-20 11:36:01 -08005539 if (!isActiveSubscription(subId)) {
5540 return;
5541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5543 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Stuart Scott54788802015-03-30 13:18:01 -07005547 }
5548
Jack Yud10cdd42020-09-28 20:28:01 -07005549 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005550 * Ask the radio to connect to the input network and change selection mode to manual.
5551 *
5552 * @param subId the id of the subscription.
5553 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5554 * the operator to attach to.
5555 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5556 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5557 * normal network selection next time.
5558 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005559 */
5560 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005561 public boolean setNetworkSelectionModeManual(
5562 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005565
5566 if (!isActiveSubscription(subId)) {
5567 return false;
5568 }
5569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 final long identity = Binder.clearCallingIdentity();
5571 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005572 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005574 if (DBG) {
5575 log("setNetworkSelectionModeManual: subId: " + subId
5576 + " operator: " + operatorInfo);
5577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005582 }
shilu84f6e8b2019-12-19 13:58:01 -08005583 /**
5584 * Get the manual network selection
5585 *
5586 * @param subId the id of the subscription.
5587 *
5588 * @return the previously saved user selected PLMN
5589 */
5590 @Override
5591 public String getManualNetworkSelectionPlmn(int subId) {
5592 TelephonyPermissions
5593 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5594 mApp, subId, "getManualNetworkSelectionPlmn");
5595
5596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005599 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005600 }
5601
5602 final Phone phone = getPhone(subId);
5603 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005604 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005605 }
5606 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5607 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5608 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
5612 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005613
5614 /**
5615 * Scans for available networks.
5616 */
5617 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005618 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5619 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5621 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005622 LocationAccessPolicy.LocationPermissionResult locationResult =
5623 LocationAccessPolicy.checkLocationPermission(mApp,
5624 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5625 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005626 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005627 .setCallingPid(Binder.getCallingPid())
5628 .setCallingUid(Binder.getCallingUid())
5629 .setMethod("getCellNetworkScanResults")
5630 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005631 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5632 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005633 .build());
5634 switch (locationResult) {
5635 case DENIED_HARD:
5636 throw new SecurityException("Not allowed to access scan results -- location");
5637 case DENIED_SOFT:
5638 return null;
5639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
Pengquan Menga1bb6272018-09-06 09:59:22 -07005641 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 try {
5643 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005644 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005649 }
5650
5651 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005652 * Get the call forwarding info, given the call forwarding reason.
5653 */
5654 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005655 public void getCallForwarding(int subId, int callForwardingReason,
5656 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005657 enforceReadPrivilegedPermission("getCallForwarding");
5658 long identity = Binder.clearCallingIdentity();
5659 try {
5660 if (DBG) {
5661 log("getCallForwarding: subId " + subId
5662 + " callForwardingReason" + callForwardingReason);
5663 }
Hall Liu27d24262020-09-18 19:04:59 -07005664
5665 Phone phone = getPhone(subId);
5666 if (phone == null) {
5667 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005668 callback.onError(
5669 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005670 } catch (RemoteException e) {
5671 // ignore
5672 }
5673 return;
5674 }
5675
5676 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5677 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5678 @Override
5679 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5680 try {
5681 callback.onCallForwardingInfoAvailable(info);
5682 } catch (RemoteException e) {
5683 // ignore
5684 }
5685 }
5686
5687 @Override
5688 public void onError(int error) {
5689 try {
5690 callback.onError(error);
5691 } catch (RemoteException e) {
5692 // ignore
5693 }
5694 }
5695 });
5696 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701
5702 /**
5703 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5704 * reason, the number to forward, and the timeout before the forwarding is attempted.
5705 */
5706 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005707 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5708 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005709 enforceModifyPermission();
5710 long identity = Binder.clearCallingIdentity();
5711 try {
5712 if (DBG) {
5713 log("setCallForwarding: subId " + subId
5714 + " callForwardingInfo" + callForwardingInfo);
5715 }
Hall Liu27d24262020-09-18 19:04:59 -07005716
5717 Phone phone = getPhone(subId);
5718 if (phone == null) {
5719 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005720 callback.accept(
5721 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005722 } catch (RemoteException e) {
5723 // ignore
5724 }
5725 return;
5726 }
5727
5728 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5729 FunctionalUtils.ignoreRemoteException(callback::accept));
5730
5731 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
5735 }
5736
5737 /**
Hall Liu27d24262020-09-18 19:04:59 -07005738 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005739 */
5740 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005741 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005742 enforceReadPrivilegedPermission("getCallForwarding");
5743 long identity = Binder.clearCallingIdentity();
5744 try {
Hall Liu27d24262020-09-18 19:04:59 -07005745
5746 Phone phone = getPhone(subId);
5747 if (phone == null) {
5748 try {
5749 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5750 } catch (RemoteException e) {
5751 // ignore
5752 }
5753 return;
5754 }
5755
5756 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5757
Shuo Qian4a594052020-01-23 11:59:30 -08005758 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005759 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
5763 }
5764
5765 /**
Hall Liu27d24262020-09-18 19:04:59 -07005766 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005767 */
5768 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005769 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005770 enforceModifyPermission();
5771 long identity = Binder.clearCallingIdentity();
5772 try {
Hall Liu27d24262020-09-18 19:04:59 -07005773 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5774
5775 Phone phone = getPhone(subId);
5776 if (phone == null) {
5777 try {
5778 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5779 } catch (RemoteException e) {
5780 // ignore
5781 }
5782 return;
5783 }
5784
5785 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5786 FunctionalUtils.ignoreRemoteException(callback::accept));
5787
5788 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
5792 }
5793
5794 /**
yinxub1bed742017-04-17 11:45:04 -07005795 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005796 *
yinxub1bed742017-04-17 11:45:04 -07005797 * @param subId id of the subscription
5798 * @param request contains the radio access networks with bands/channels to scan
5799 * @param messenger callback messenger for scan results or errors
5800 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005801 * @return the id of the requested scan which can be used to stop the scan.
5802 */
5803 @Override
5804 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005805 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5807 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005808 LocationAccessPolicy.LocationPermissionResult locationResult =
5809 LocationAccessPolicy.checkLocationPermission(mApp,
5810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5811 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005812 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005813 .setCallingPid(Binder.getCallingPid())
5814 .setCallingUid(Binder.getCallingUid())
5815 .setMethod("requestNetworkScan")
5816 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005817 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5818 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005819 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005820 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005821 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5822 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005823 if (e != null) {
5824 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5825 throw e;
5826 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005827 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005828 return TelephonyScanManager.INVALID_SCAN_ID;
5829 }
5830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 }
Hall Liu912dfd32019-04-25 14:02:26 -07005832 int callingUid = Binder.getCallingUid();
5833 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005834 final long identity = Binder.clearCallingIdentity();
5835 try {
5836 return mNetworkScanRequestTracker.startNetworkScan(
5837 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005838 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
yinxu504e1392017-04-12 16:03:22 -07005842 }
5843
Hall Liub2ac8ef2019-02-28 15:56:23 -08005844 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005845 NetworkScanRequest request, int subId, String callingPackage) {
5846 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005847 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5848 boolean hasNetworkScanPermission =
5849 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5850 == PERMISSION_GRANTED;
5851
5852 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5853 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5854 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005855 }
5856
5857 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5858 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005859 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5860 return new SecurityException("Specific channels must not be"
5861 + " scanned without location access.");
5862 }
5863 }
5864 }
5865
Hall Liub2ac8ef2019-02-28 15:56:23 -08005866 return null;
5867 }
5868
yinxu504e1392017-04-12 16:03:22 -07005869 /**
5870 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005871 *
5872 * @param subId id of the subscription
5873 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005874 */
5875 @Override
5876 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5878 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
Hall Liu912dfd32019-04-25 14:02:26 -07005880 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 final long identity = Binder.clearCallingIdentity();
5882 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005883 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
yinxu504e1392017-04-12 16:03:22 -07005887 }
5888
5889 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005890 * Get the calculated preferred network type.
5891 * Used for debugging incorrect network type.
5892 *
5893 * @return the preferred network type, defined in RILConstants.java.
5894 */
5895 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005896 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005897 final Phone defaultPhone = getDefaultPhone();
5898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005899 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005900 return RILConstants.PREFERRED_NETWORK_MODE;
5901 }
5902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005906 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Junda Liu84d15a22014-07-02 11:21:04 -07005910 }
5911
5912 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005913 * Get the preferred network type.
5914 * Used for device configuration by some CDMA operators.
5915 *
5916 * @return the preferred network type, defined in RILConstants.java.
5917 */
5918 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005919 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005920 TelephonyPermissions
5921 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5922 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923
5924 final long identity = Binder.clearCallingIdentity();
5925 try {
5926 if (DBG) log("getPreferredNetworkType");
5927 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5928 int networkType = (result != null ? result[0] : -1);
5929 if (DBG) log("getPreferredNetworkType: " + networkType);
5930 return networkType;
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005934 }
5935
5936 /**
5937 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005938 *
5939 * @param networkType the preferred network type, defined in RILConstants.java.
5940 * @return true on success; false on any failure.
5941 */
5942 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005943 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5945 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
calvinpan8ed33732020-03-12 14:17:55 +08005949 Boolean success = (Boolean) sendRequest(
5950 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005951
5952 if (success) {
5953 Settings.Global.putInt(mApp.getContentResolver(),
5954 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5955 }
calvinpan8ed33732020-03-12 14:17:55 +08005956 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5957 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005960 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005961 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005962
5963 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005964 * Get the allowed network types that store in the telephony provider.
5965 *
5966 * @param subId the id of the subscription.
5967 * @return allowedNetworkTypes the allowed network types.
5968 */
5969 @Override
5970 public long getAllowedNetworkTypes(int subId) {
5971 TelephonyPermissions
5972 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5973 mApp, subId, "getAllowedNetworkTypes");
5974
5975 final long identity = Binder.clearCallingIdentity();
5976 try {
5977 return SubscriptionManager.getLongSubscriptionProperty(
5978 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
5982 }
5983
5984 /**
5985 * Set the allowed network types.
5986 *
5987 * @param subId the id of the subscription.
5988 * @param allowedNetworkTypes the allowed network types.
5989 * @return true on success; false on any failure.
5990 */
5991 @Override
5992 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5994 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005995
calvinpan8ed33732020-03-12 14:17:55 +08005996 SubscriptionManager.setSubscriptionProperty(subId,
5997 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5998 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005999
calvinpan8ed33732020-03-12 14:17:55 +08006000 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6001 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6002 RILConstants.PREFERRED_NETWORK_MODE);
6003 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08006004 }
6005
6006 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006007 * Get the allowed network types for certain reason.
6008 *
6009 * @param subId the id of the subscription.
6010 * @param reason the reason the allowed network type change is taking place
6011 * @return the allowed network types.
6012 */
6013 @Override
6014 public long getAllowedNetworkTypesForReason(int subId,
6015 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6016 TelephonyPermissions
6017 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6018 mApp, subId, "getAllowedNetworkTypesForReason");
6019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
6025 }
6026
6027 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006028 * Enable/Disable E-UTRA-NR Dual Connectivity
6029 * @param subId subscription id of the sim card
6030 * @param nrDualConnectivityState expected NR dual connectivity state
6031 * This can be passed following states
6032 * <ol>
6033 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6034 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6035 * <li>Disable NR dual connectivity and force secondary cell to be released
6036 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6037 * </ol>
6038 * @return operation result.
6039 */
6040 @Override
6041 public int setNrDualConnectivityState(int subId,
6042 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6044 mApp, subId, "enableNRDualConnectivity");
6045 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6049 nrDualConnectivityState, subId,
6050 workSource);
6051 if (DBG) log("enableNRDualConnectivity result: " + result);
6052 return result;
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
6056 }
6057
6058 /**
6059 * Is E-UTRA-NR Dual Connectivity enabled
6060 * @return true if dual connectivity is enabled else false
6061 */
6062 @Override
6063 public boolean isNrDualConnectivityEnabled(int subId) {
6064 TelephonyPermissions
6065 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6066 mApp, subId, "isNRDualConnectivityEnabled");
6067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6071 null, subId, workSource);
6072 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6073 return isEnabled;
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
6077 }
6078
6079 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006080 * get carrier bandwidth per primary and secondary carrier
6081 * @param subId subscription id of the sim card
6082 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6083 */
6084 @Override
6085 public CarrierBandwidth getCarrierBandwidth(int subId) {
6086 TelephonyPermissions
6087 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6088 mApp, subId, "isNRDualConnectivityEnabled");
6089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
6092 CarrierBandwidth carrierBandwidth =
6093 getPhoneFromSubId(subId).getCarrierBandwidth();
6094 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6095 return carrierBandwidth;
6096 } finally {
6097 Binder.restoreCallingIdentity(identity);
6098 }
6099 }
6100
6101 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006102 * Get the effective allowed network types on the device.
6103 * This API will return an intersection of allowed network types for all reasons,
6104 * including the configuration done through setAllowedNetworkTypes
6105 *
6106 * @param subId the id of the subscription.
6107 * @return the allowed network types
6108 */
6109 @Override
6110 public long getEffectiveAllowedNetworkTypes(int subId) {
6111 TelephonyPermissions
6112 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6113 mApp, subId, "getEffectiveAllowedNetworkTypes");
6114 final long identity = Binder.clearCallingIdentity();
6115 try {
6116 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
6120 }
6121
6122 /**
6123 * Set the allowed network types of the device and
6124 * provide the reason triggering the allowed network change.
6125 *
6126 * @param subId the id of the subscription.
6127 * @param reason the reason the allowed network type change is taking place
6128 * @param allowedNetworkTypes the allowed network types.
6129 * @return true on success; false on any failure.
6130 */
6131 @Override
6132 public boolean setAllowedNetworkTypesForReason(int subId,
6133 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6135 mApp, subId, "setAllowedNetworkTypesForReason");
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
6138 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6139 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6140 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6141 RILConstants.PREFERRED_NETWORK_MODE);
6142 return setPreferredNetworkType(subId, preferredNetworkMode);
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
6146 }
6147
6148 /**
Miaoa84611c2019-03-15 09:21:10 +08006149 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006150 *
Miaoa84611c2019-03-15 09:21:10 +08006151 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006152 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006153 * @hide
6154 */
6155 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006156 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006159 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 try {
Miaoa84611c2019-03-15 09:21:10 +08006161 if (phone != null) {
6162 return phone.hasMatchedTetherApnSetting();
6163 } else {
6164 return false;
6165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 } finally {
6167 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006168 }
Junda Liu475951f2014-11-07 16:45:03 -08006169 }
6170
6171 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006172 * Enable or disable always reporting signal strength changes from radio.
6173 *
6174 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6175 */
6176 @Override
6177 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6178 enforceModifyPermission();
6179 enforceSystemCaller();
6180
6181 final long identity = Binder.clearCallingIdentity();
6182 final Phone phone = getPhone(subId);
6183 try {
6184 if (phone != null) {
6185 if (DBG) {
6186 log("setAlwaysReportSignalStrength: subId=" + subId
6187 + " isEnable=" + isEnable);
6188 }
6189 phone.setAlwaysReportSignalStrength(isEnable);
6190 } else {
6191 loge("setAlwaysReportSignalStrength: no phone found for subId="
6192 + subId);
6193 }
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
6197 }
6198
6199 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006200 * Get the user enabled state of Mobile Data.
6201 *
6202 * TODO: remove and use isUserDataEnabled.
6203 * This can't be removed now because some vendor codes
6204 * calls through ITelephony directly while they should
6205 * use TelephonyManager.
6206 *
6207 * @return true on enabled
6208 */
6209 @Override
6210 public boolean getDataEnabled(int subId) {
6211 return isUserDataEnabled(subId);
6212 }
6213
6214 /**
6215 * Get whether mobile data is enabled per user setting.
6216 *
6217 * There are other factors deciding whether mobile data is actually enabled, but they are
6218 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006219 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006220 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006221 *
6222 * @return {@code true} if data is enabled else {@code false}
6223 */
6224 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006225 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006226 try {
6227 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6228 null);
6229 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6231 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233
6234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 int phoneId = mSubscriptionController.getPhoneId(subId);
6237 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6238 Phone phone = PhoneFactory.getPhone(phoneId);
6239 if (phone != null) {
6240 boolean retVal = phone.isUserDataEnabled();
6241 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6242 return retVal;
6243 } else {
6244 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6245 return false;
6246 }
6247 } finally {
6248 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006249 }
6250 }
6251
6252 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006253 * Checks if the device is capable of mobile data by considering whether whether the
6254 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6255 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006256 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006257 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006258 */
6259 @Override
6260 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006261 try {
6262 try {
6263 mApp.enforceCallingOrSelfPermission(
6264 android.Manifest.permission.ACCESS_NETWORK_STATE,
6265 null);
6266 } catch (Exception e) {
6267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6268 "isDataEnabled");
6269 }
6270 } catch (Exception e) {
6271 enforceReadPrivilegedPermission("isDataEnabled");
6272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273
6274 final long identity = Binder.clearCallingIdentity();
6275 try {
6276 int phoneId = mSubscriptionController.getPhoneId(subId);
6277 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6278 Phone phone = PhoneFactory.getPhone(phoneId);
6279 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006280 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6282 return retVal;
6283 } else {
6284 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6285 return false;
6286 }
6287 } finally {
6288 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006289 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006290 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006291
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006292 /**
6293 * Check if data is enabled for a specific reason
6294 * @param subId Subscription index
6295 * @param reason the reason the data enable change is taking place
6296 * @return {@code true} if the overall data is enabled; {@code false} if not.
6297 */
6298 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006299 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006300 @TelephonyManager.DataEnabledReason int reason) {
6301 try {
6302 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6303 null);
6304 } catch (Exception e) {
6305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006306 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006307 }
6308
6309
6310 final long identity = Binder.clearCallingIdentity();
6311 try {
6312 int phoneId = mSubscriptionController.getPhoneId(subId);
6313 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006314 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006315 + " reason=" + reason);
6316 }
6317 Phone phone = PhoneFactory.getPhone(phoneId);
6318 if (phone != null) {
6319 boolean retVal;
6320 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6321 retVal = phone.isUserDataEnabled();
6322 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006323 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006324 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006325 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006326 return retVal;
6327 } else {
6328 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006329 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006330 + subId + " retVal=false");
6331 }
6332 return false;
6333 }
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
6337 }
6338
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006339 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006340 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006341 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6342 // Skip the check if it's one of these special uids
6343 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6344 }
6345
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006346 //load access rules from carrier configs, and check those as well: b/139133814
6347 SubscriptionController subController = SubscriptionController.getInstance();
6348 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6349 || subController == null) return privilegeFromSim;
6350
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006351 PackageManager pkgMgr = phone.getContext().getPackageManager();
6352 String[] packages = pkgMgr.getPackagesForUid(uid);
6353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006356 int subId = phone.getSubId();
6357 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6358 // A test override is in place for the privileges for this subId, so don't try to
6359 // read the subscription privileges.
6360 return privilegeFromSim;
6361 }
6362 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006363 SubscriptionManager subManager = (SubscriptionManager)
6364 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6365 for (String pkg : packages) {
6366 if (subManager.canManageSubscription(subInfo, pkg)) {
6367 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6368 }
6369 }
6370 return privilegeFromSim;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
6376 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6377 String pkgName) {
6378 //load access rules from carrier configs, and check those as well: b/139133814
6379 SubscriptionController subController = SubscriptionController.getInstance();
6380 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6381 || subController == null) return privilegeFromSim;
6382
6383 final long identity = Binder.clearCallingIdentity();
6384 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006385 int subId = phone.getSubId();
6386 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6387 // A test override is in place for the privileges for this subId, so don't try to
6388 // read the subscription privileges.
6389 return privilegeFromSim;
6390 }
6391 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006392 SubscriptionManager subManager = (SubscriptionManager)
6393 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6394 return subManager.canManageSubscription(subInfo, pkgName)
6395 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
6399 }
6400
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006401 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006402 public int getCarrierPrivilegeStatus(int subId) {
6403 final Phone phone = getPhone(subId);
6404 if (phone == null) {
6405 loge("getCarrierPrivilegeStatus: Invalid subId");
6406 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6407 }
6408 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006409 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006410 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006411 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6412 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006413
6414 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6415 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006416 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006417 }
Junda Liu29340342014-07-10 15:23:27 -07006418
6419 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006420 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006421 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006422 final Phone phone = getPhone(subId);
6423 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006424 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006425 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6426 }
6427 UiccProfile profile =
6428 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6429 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006430 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006431 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6432 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006433 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006434 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006435 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006436 }
6437
6438 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006439 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6440 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006441 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006442 }
6443
6444 int phoneId = SubscriptionManager.getPhoneId(subId);
6445 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006446 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006447 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006448 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6449 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006450 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6451 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6452 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006453 }
6454
6455 @Override
6456 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006457 if (TextUtils.isEmpty(pkgName))
6458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006459 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6460 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6461 UiccCard card = UiccController.getInstance().getUiccCard(i);
6462 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006463 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006464 continue;
6465 }
6466
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006467 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6468 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6469 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006470 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6471 break;
6472 }
6473 }
6474
6475 return result;
Junda Liu29340342014-07-10 15:23:27 -07006476 }
Derek Tan89e89d42014-07-08 17:00:10 -07006477
6478 @Override
Junda Liue64de782015-04-16 17:19:16 -07006479 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6480 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6481 loge("phoneId " + phoneId + " is not valid.");
6482 return null;
6483 }
6484 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006485 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006486 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006487 return null ;
6488 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006489 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006490 }
6491
Amith Yamasani6e118872016-02-19 12:53:51 -08006492 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006493 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006494 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006495 List<String> privilegedPackages = new ArrayList<>();
6496 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006497 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6498 // has UICC in that slot.
6499 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006500 if (card.hasCarrierPrivilegeRules()) {
6501 if (packages == null) {
6502 // Only check packages in user 0 for now
6503 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006504 PackageManager.MATCH_DISABLED_COMPONENTS
6505 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006506 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006507 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006508 }
6509 for (int p = packages.size() - 1; p >= 0; p--) {
6510 PackageInfo pkgInfo = packages.get(p);
6511 if (pkgInfo != null && pkgInfo.packageName != null
6512 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006513 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006514 privilegedPackages.add(pkgInfo.packageName);
6515 }
6516 }
6517 }
6518 }
6519 return privilegedPackages;
6520 }
6521
chen xuf7e9fe82019-05-09 19:31:02 -07006522 @Override
6523 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006524 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6525
6526 final long identity = Binder.clearCallingIdentity();
6527
chen xuf7e9fe82019-05-09 19:31:02 -07006528 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006529 try {
6530 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6531 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6532 }
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006535 }
6536 return privilegedPackages;
6537 }
6538
Wink Savilleb564aae2014-10-23 10:18:09 -07006539 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006540 final Phone phone = getPhone(subId);
6541 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006542 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006543 return null;
6544 }
6545 String iccId = card.getIccId();
6546 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006547 return null;
6548 }
6549 return iccId;
6550 }
6551
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006552 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006553 public void setCallComposerStatus(int subId, int status) {
6554 enforceModifyPermission();
6555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 Phone phone = getPhone(subId);
6559 if (phone != null) {
6560 Phone defaultPhone = phone.getImsPhone();
6561 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6562 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6563 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006564 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6565 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006566 }
6567 }
Shuo Qian284ae752020-12-22 19:10:14 -08006568 } catch (ImsException e) {
6569 throw new ServiceSpecificException(e.getCode());
6570 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006571 Binder.restoreCallingIdentity(identity);
6572 }
6573 }
6574
6575 @Override
6576 public int getCallComposerStatus(int subId) {
6577 enforceReadPrivilegedPermission("getCallComposerStatus");
6578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 Phone phone = getPhone(subId);
6582 if (phone != null) {
6583 Phone defaultPhone = phone.getImsPhone();
6584 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6585 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6586 return imsPhone.getCallComposerStatus();
6587 }
6588 }
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
6592 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6593 }
6594
6595 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006596 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6597 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006598 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006599 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 final String iccId = getIccId(subId);
6604 final Phone phone = getPhone(subId);
6605 if (phone == null) {
6606 return false;
6607 }
6608 final String subscriberId = phone.getSubscriberId();
6609
6610 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006611 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 + subscriberId + " to " + number);
6613 }
6614
6615 if (TextUtils.isEmpty(iccId)) {
6616 return false;
6617 }
6618
6619 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6620
6621 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6622 if (alphaTag == null) {
6623 editor.remove(alphaTagPrefKey);
6624 } else {
6625 editor.putString(alphaTagPrefKey, alphaTag);
6626 }
6627
6628 // Record both the line number and IMSI for this ICCID, since we need to
6629 // track all merged IMSIs based on line number
6630 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6631 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6632 if (number == null) {
6633 editor.remove(numberPrefKey);
6634 editor.remove(subscriberPrefKey);
6635 } else {
6636 editor.putString(numberPrefKey, number);
6637 editor.putString(subscriberPrefKey, subscriberId);
6638 }
6639
6640 editor.commit();
6641 return true;
6642 } finally {
6643 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006644 }
Derek Tan7226c842014-07-02 17:42:23 -07006645 }
6646
6647 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006648 public String getLine1NumberForDisplay(int subId, String callingPackage,
6649 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006650 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006652 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006653 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006654 return null;
6655 }
Derek Tan97ebb422014-09-05 16:55:38 -07006656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 String iccId = getIccId(subId);
6660 if (iccId != null) {
6661 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6662 if (DBG_MERGE) {
6663 log("getLine1NumberForDisplay returning "
6664 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6665 }
6666 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6669 return null;
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006672 }
Derek Tan7226c842014-07-02 17:42:23 -07006673 }
6674
6675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006676 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6677 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006679 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006680 return null;
6681 }
Derek Tan97ebb422014-09-05 16:55:38 -07006682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683 final long identity = Binder.clearCallingIdentity();
6684 try {
6685 String iccId = getIccId(subId);
6686 if (iccId != null) {
6687 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6688 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6689 }
6690 return null;
6691 } finally {
6692 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006693 }
Derek Tan7226c842014-07-02 17:42:23 -07006694 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006695
6696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006697 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6698 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006699 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6700 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006702 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006703 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006704 return null;
6705 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006706
Jordan Liub49b04b2019-05-06 14:45:15 -07006707 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6708 // the process, where TelephonyManager was instantiated.
6709 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006710 final long identity = Binder.clearCallingIdentity();
6711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006712 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 final TelephonyManager tele = TelephonyManager.from(context);
6714 final SubscriptionManager sub = SubscriptionManager.from(context);
6715
6716 // Figure out what subscribers are currently active
6717 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718
Jordan Liub49b04b2019-05-06 14:45:15 -07006719 // Only consider subs which match the current subId
6720 // This logic can be simplified. See b/131189269 for progress.
6721 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006722 activeSubscriberIds.add(tele.getSubscriberId(subId));
6723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724
6725 // First pass, find a number override for an active subscriber
6726 String mergeNumber = null;
6727 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6728 for (String key : prefs.keySet()) {
6729 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6730 final String subscriberId = (String) prefs.get(key);
6731 if (activeSubscriberIds.contains(subscriberId)) {
6732 final String iccId = key.substring(
6733 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6734 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6735 mergeNumber = (String) prefs.get(numberKey);
6736 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006737 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 + " for active subscriber " + subscriberId);
6739 }
6740 if (!TextUtils.isEmpty(mergeNumber)) {
6741 break;
6742 }
6743 }
6744 }
6745 }
6746
6747 // Shortcut when no active merged subscribers
6748 if (TextUtils.isEmpty(mergeNumber)) {
6749 return null;
6750 }
6751
6752 // Second pass, find all subscribers under that line override
6753 final ArraySet<String> result = new ArraySet<>();
6754 for (String key : prefs.keySet()) {
6755 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6756 final String number = (String) prefs.get(key);
6757 if (mergeNumber.equals(number)) {
6758 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6759 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6760 final String subscriberId = (String) prefs.get(subscriberKey);
6761 if (!TextUtils.isEmpty(subscriberId)) {
6762 result.add(subscriberId);
6763 }
6764 }
6765 }
6766 }
6767
6768 final String[] resultArray = result.toArray(new String[result.size()]);
6769 Arrays.sort(resultArray);
6770 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006771 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6773 }
6774 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006775 } finally {
6776 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006777 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006778 }
6779
6780 @Override
zoey chen38003472019-12-13 17:16:31 +08006781 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6782 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 final TelephonyManager telephonyManager = mApp.getSystemService(
6787 TelephonyManager.class);
6788 String subscriberId = telephonyManager.getSubscriberId(subId);
6789 if (subscriberId == null) {
6790 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006791 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006792 + subId);
6793 }
6794 return null;
6795 }
6796
6797 final SubscriptionInfo info = SubscriptionController.getInstance()
6798 .getSubscriptionInfo(subId);
6799 final ParcelUuid groupUuid = info.getGroupUuid();
6800 // If it doesn't belong to any group, return just subscriberId of itself.
6801 if (groupUuid == null) {
6802 return new String[]{subscriberId};
6803 }
6804
6805 // Get all subscriberIds from the group.
6806 final List<String> mergedSubscriberIds = new ArrayList<>();
6807 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006808 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006809 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006810 for (SubscriptionInfo subInfo : groupInfos) {
6811 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6812 if (subscriberId != null) {
6813 mergedSubscriberIds.add(subscriberId);
6814 }
6815 }
6816
6817 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820
6821 }
6822 }
6823
6824 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006825 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006826 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828
6829 final long identity = Binder.clearCallingIdentity();
6830 try {
6831 final Phone phone = getPhone(subId);
6832 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
6835 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006836 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006837
6838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006839 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006840 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6841 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006842 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6843 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844
6845 final long identity = Binder.clearCallingIdentity();
6846 try {
6847 final Phone phone = getPhone(subId);
6848 if (phone == null) {
6849 return false;
6850 }
6851 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6852 cdmaNonRoamingList);
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006855 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006856 }
6857
6858 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006859 @Deprecated
6860 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6861 enforceModifyPermission();
6862
6863 int returnValue = 0;
6864 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006865 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006866 if(result.exception == null) {
6867 if (result.result != null) {
6868 byte[] responseData = (byte[])(result.result);
6869 if(responseData.length > oemResp.length) {
6870 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6871 responseData.length + "bytes. Buffer Size is " +
6872 oemResp.length + "bytes.");
6873 }
6874 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6875 returnValue = responseData.length;
6876 }
6877 } else {
6878 CommandException ex = (CommandException) result.exception;
6879 returnValue = ex.getCommandError().ordinal();
6880 if(returnValue > 0) returnValue *= -1;
6881 }
6882 } catch (RuntimeException e) {
6883 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6884 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6885 if(returnValue > 0) returnValue *= -1;
6886 }
6887
6888 return returnValue;
6889 }
6890
6891 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006892 public void setRadioCapability(RadioAccessFamily[] rafs) {
6893 try {
6894 ProxyController.getInstance().setRadioCapability(rafs);
6895 } catch (RuntimeException e) {
6896 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6897 }
6898 }
6899
6900 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006901 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006902 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006903 try {
6904 TelephonyPermissions
6905 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6906 mApp, phone.getSubId(), "getRadioAccessFamily");
6907 } catch (SecurityException e) {
6908 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6909 throw e;
6910 }
chen xub97461a2018-10-26 14:17:57 -07006911 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006912 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006913 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 final long identity = Binder.clearCallingIdentity();
6916 try {
chen xub97461a2018-10-26 14:17:57 -07006917 TelephonyPermissions
6918 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6919 mApp, phone.getSubId(), "getRadioAccessFamily");
6920 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
chen xub97461a2018-10-26 14:17:57 -07006924 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006925 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006926
6927 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006928 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
6929 ParcelFileDescriptor fd, ResultReceiver callback) {
6930 try {
6931 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6932 Binder.getCallingUid())) {
6933 throw new SecurityException("Package uid and package name do not match: "
6934 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6935 }
6936 } catch (PackageManager.NameNotFoundException e) {
6937 throw new SecurityException("Package name invalid:" + callingPackage);
6938 }
6939 RoleManager rm = mApp.getSystemService(RoleManager.class);
6940 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6941 if (!dialerRoleHolders.contains(callingPackage)) {
6942 throw new SecurityException("App must be the dialer role holder to"
6943 + " upload a call composer pic");
6944 }
6945
6946 Executors.newSingleThreadExecutor().execute(() -> {
6947 ByteArrayOutputStream output = new ByteArrayOutputStream(
6948 (int) TelephonyManager.getMaximumCallComposerPictureSize());
6949 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
6950 boolean readUntilEnd = false;
6951 int totalBytesRead = 0;
6952 byte[] buffer = new byte[16 * 1024];
6953 while (true) {
6954 int numRead;
6955 try {
6956 numRead = input.read(buffer);
6957 } catch (IOException e) {
6958 try {
6959 fd.checkError();
6960 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
6961 null);
6962 } catch (IOException e1) {
6963 // This means that the other side closed explicitly with an error. If this
6964 // happens, log and ignore.
6965 loge("Remote end of call composer picture pipe closed: " + e1);
6966 }
6967 break;
6968 }
6969 if (numRead == -1) {
6970 readUntilEnd = true;
6971 break;
6972 }
6973 totalBytesRead += numRead;
6974 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
6975 loge("Too many bytes read for call composer picture: " + totalBytesRead);
6976 try {
6977 input.close();
6978 } catch (IOException e) {
6979 // ignore
6980 }
6981 break;
6982 }
6983 output.write(buffer, 0, numRead);
6984 }
6985 // Generally, the remote end will close the file descriptors. The only case where we
6986 // close is above, where the picture size is too big.
6987
6988 try {
6989 fd.checkError();
6990 } catch (IOException e) {
6991 loge("Remote end for call composer closed with an error: " + e);
6992 return;
6993 }
6994
6995 // TODO: pass along the bytes read to the carrier somehow
6996
6997 ParcelUuid result = new ParcelUuid(UUID.randomUUID());
6998 // TODO: cache this uuid that's been associated with the picture
6999 Bundle outputResult = new Bundle();
7000 outputResult.putParcelable(TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, result);
7001 callback.send(-1, outputResult);
7002 });
7003 }
7004
7005 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007006 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007007 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007008 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009
7010 final long identity = Binder.clearCallingIdentity();
7011 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007012 ImsManager.getInstance(defaultPhone.getContext(),
7013 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007017 }
7018
7019 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007020 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007021 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7023 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007024 return false;
7025 }
Svet Ganovb320e182015-04-16 12:30:10 -07007026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 // Check the user preference and the system-level IMS setting. Even if the user has
7030 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7031 // In the long run, we may instead need to check if there exists a connection service
7032 // which can support video calling.
7033 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007034 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 return imsManager.isVtEnabledByPlatform()
7036 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7037 && imsManager.isVtEnabledByUser();
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
7040 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007041 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007042
Andrew Leea1239f22015-03-02 17:44:07 -08007043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007044 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7045 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007047 mApp, subId, callingPackage, callingFeatureId,
7048 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 return false;
7050 }
7051
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 CarrierConfigManager configManager =
7055 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007056 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
Andrew Leea1239f22015-03-02 17:44:07 -08007061 }
7062
7063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007066 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 return false;
7068 }
7069
7070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 CarrierConfigManager configManager =
7073 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007074 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7076 } finally {
7077 Binder.restoreCallingIdentity(identity);
7078 }
Andrew Leea1239f22015-03-02 17:44:07 -08007079 }
7080
Andrew Lee9431b832015-03-09 18:46:45 -07007081 @Override
7082 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007083 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007084 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007085 }
7086
7087 @Override
7088 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 final long identity = Binder.clearCallingIdentity();
7090 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007091 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 } finally {
7093 Binder.restoreCallingIdentity(identity);
7094 }
Andrew Lee9431b832015-03-09 18:46:45 -07007095 }
7096
Hall Liuf6668912018-10-31 17:05:23 -07007097 /**
7098 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7099 * support for the feature and device firmware support.
7100 *
7101 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7102 */
7103 @Override
7104 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007106 final Phone phone = getPhone(subscriptionId);
7107 if (phone == null) {
7108 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7109 return false;
7110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007112 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7114 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007115 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 return isCarrierSupported && isDeviceSupported;
7117 } finally {
7118 Binder.restoreCallingIdentity(identity);
7119 }
Hall Liu98187582018-01-22 19:15:32 -08007120 }
7121
Hall Liuf6668912018-10-31 17:05:23 -07007122 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007123 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7124 * RTT setting, will return true if the device and carrier both support RTT.
7125 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007126 */
7127 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007130 boolean isRttSupported = isRttSupported(subscriptionId);
7131 boolean isUserRttSettingOn = Settings.Secure.getInt(
7132 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7133 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7134 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7135 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007139 }
7140
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007141 @Deprecated
7142 @Override
7143 public String getDeviceId(String callingPackage) {
7144 return getDeviceIdWithFeature(callingPackage, null);
7145 }
7146
Sanket Padawe7310cc72015-01-14 09:53:20 -08007147 /**
7148 * Returns the unique device ID of phone, for example, the IMEI for
7149 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7150 *
7151 * <p>Requires Permission:
7152 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7153 */
7154 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007155 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007156 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007157 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007158 return null;
7159 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007160 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007161 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007162 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007163 return null;
7164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007165
7166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 return phone.getDeviceId();
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
7171 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007172 }
7173
Ping Sunc67b7c22016-03-02 19:16:45 +08007174 /**
7175 * {@hide}
7176 * Returns the IMS Registration Status on a particular subid
7177 *
7178 * @param subId
7179 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007180 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007181 Phone phone = getPhone(subId);
7182 if (phone != null) {
7183 return phone.isImsRegistered();
7184 } else {
7185 return false;
7186 }
7187 }
7188
Santos Cordon7a1885b2015-02-03 11:15:19 -08007189 @Override
7190 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007197 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007198
Tyler Gunnf70ed162019-04-03 15:28:53 -07007199 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007200 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007201 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007203 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007204 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7205 }
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211 }
7212 }
7213
7214 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007215 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007216 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7217 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 Phone phone = getPhone(subscriptionId);
7221 if (phone == null) {
7222 return null;
7223 }
7224 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
7228 }
7229
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007230 /**
7231 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007232 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007233 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 final long identity = Binder.clearCallingIdentity();
7235 try {
7236 Phone phone = getPhone(subId);
7237 if (phone != null) {
7238 return phone.isWifiCallingEnabled();
7239 } else {
7240 return false;
7241 }
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007244 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007245 }
7246
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007247 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007248 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007249 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007250 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 Phone phone = getPhone(subId);
7254 if (phone != null) {
7255 return phone.isVideoEnabled();
7256 } else {
7257 return false;
7258 }
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007261 }
7262 }
7263
7264 /**
7265 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7266 * defined in {@link ImsRegistrationImplBase}.
7267 */
7268 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 Phone phone = getPhone(subId);
7272 if (phone != null) {
7273 return phone.getImsRegistrationTech();
7274 } else {
7275 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7276 }
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007279 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007280 }
7281
Stuart Scott8eef64f2015-04-08 15:13:54 -07007282 @Override
7283 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007284 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007285 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7286 return;
7287 }
7288
Svet Ganovcc087f82015-05-12 20:35:54 -07007289 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290
Svet Ganovcc087f82015-05-12 20:35:54 -07007291 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007292 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7293 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007294 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007295 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007296 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007297 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007298 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7299 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007300 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007301 // There has been issues when Sms raw table somehow stores orphan
7302 // fragments. They lead to garbled message when new fragments come
7303 // in and combined with those stale ones. In case this happens again,
7304 // user can reset all network settings which will clean up this table.
7305 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007306 // Clean up IMS settings as well here.
7307 int slotId = getSlotIndex(subId);
7308 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7309 ImsManager.getInstance(mApp, slotId).factoryReset();
7310 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007311
7312 // Erase modem config if erase modem on network setting is enabled.
7313 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7314 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7315 if (configValue != null && Boolean.parseBoolean(configValue)) {
7316 sendEraseModemConfig(getDefaultPhone());
7317 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007318 } finally {
7319 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007320 }
7321 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007322
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007323 private void cleanUpSmsRawTable(Context context) {
7324 ContentResolver resolver = context.getContentResolver();
7325 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7326 resolver.delete(uri, null, null);
7327 }
7328
Narayan Kamath1c496c22015-04-16 14:40:19 +01007329 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007330 public String getSimLocaleForSubscriber(int subId) {
7331 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7332 final Phone phone = getPhone(subId);
7333 if (phone == null) {
7334 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007335 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
chen xu5d3637b2019-01-21 23:31:38 -08007339 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007340 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007341 if (info == null) {
7342 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7343 return null;
7344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 // Try and fetch the locale from the carrier properties or from the SIM language
7346 // preferences (EF-PL and EF-LI)...
7347 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007349 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7350 if (localeFromDefaultSim != null) {
7351 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7352 if (DBG) log("Using locale from subId: " + subId + " locale: "
7353 + localeFromDefaultSim);
7354 return localeFromDefaultSim.toLanguageTag();
7355 } else {
7356 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 }
7358 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 // The SIM language preferences only store a language (e.g. fr = French), not an
7361 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7362 // the SIM and carrier preferences does not include a country we add the country
7363 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007364 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007366 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 return mccLocale.toLanguageTag();
7368 }
7369
7370 if (DBG) log("No locale found - returning null");
7371 return null;
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007375 }
7376
7377 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007378 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007379 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007380 }
7381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 /**
7383 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7384 */
7385 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007386 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007387 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007389
Chenjie Yu1ba97252018-01-11 18:16:20 -08007390 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007391 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007392
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007393 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007394 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7395 * representing the state of the modem.
7396 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007397 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7398 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007399 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007400 */
7401 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007402 public void requestModemActivityInfo(ResultReceiver result) {
7403 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007404 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405
7406 final long identity = Binder.clearCallingIdentity();
7407 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007408 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 } finally {
7410 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007411 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007412 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007413
Siddharth Rayb8114062018-06-17 15:02:38 -07007414 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7415 // less than total activity duration.
7416 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7417 if (info == null) {
7418 return false;
7419 }
7420 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007421 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7422 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7423
Siddharth Rayb8114062018-06-17 15:02:38 -07007424 return (info.isValid()
7425 && (info.getSleepTimeMillis() <= activityDurationMs)
7426 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007427 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007428 && (totalTxTimeMs <= activityDurationMs));
7429 }
7430
Jack Yu85bd38a2015-11-09 11:34:32 -08007431 /**
7432 * {@hide}
7433 * Returns the service state information on specified subscription.
7434 */
7435 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007436 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7437 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007440 return null;
7441 }
7442
Hall Liuf19c44f2018-11-27 14:38:17 -08007443 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7444 LocationAccessPolicy.checkLocationPermission(mApp,
7445 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7446 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007447 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007448 .setCallingPid(Binder.getCallingPid())
7449 .setCallingUid(Binder.getCallingUid())
7450 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007451 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007452 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007453 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7454 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007455 .build());
7456
7457 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7458 LocationAccessPolicy.checkLocationPermission(mApp,
7459 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7460 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007461 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007462 .setCallingPid(Binder.getCallingPid())
7463 .setCallingUid(Binder.getCallingUid())
7464 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007465 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007466 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007467 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7468 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007469 .build());
7470 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7471 boolean hasFinePermission =
7472 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7473 boolean hasCoarsePermission =
7474 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7475
Jack Yu479f40e2020-10-27 21:29:25 -07007476 final Phone phone = getPhone(subId);
7477 if (phone == null) {
7478 return null;
7479 }
7480
Jordan Liu0f2bc442020-11-18 16:47:37 -08007481 final long identity = Binder.clearCallingIdentity();
7482
Jack Yu479f40e2020-10-27 21:29:25 -07007483 boolean isCallingPackageDataService = phone.getDataServicePackages()
7484 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007486 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7487 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7488 Rlog.d(LOG_TAG,
7489 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7490 return null;
7491 }
7492
Hall Liuf19c44f2018-11-27 14:38:17 -08007493 ServiceState ss = phone.getServiceState();
7494
7495 // Scrub out the location info in ServiceState depending on what level of access
7496 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007497 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007498 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7499 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007503 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007504
7505 /**
7506 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7507 *
7508 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7509 * voicemail ringtone.
7510 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7511 * PhoneAccount.
7512 */
7513 @Override
7514 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 final long identity = Binder.clearCallingIdentity();
7516 try {
7517 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7518 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007519 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007526 }
7527
7528 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007529 * Sets the per-account voicemail ringtone.
7530 *
7531 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7532 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7533 *
7534 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7535 * voicemail ringtone.
7536 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7537 * PhoneAccount.
7538 */
7539 @Override
7540 public void setVoicemailRingtoneUri(String callingPackage,
7541 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007544 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7545 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7547 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7548 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550
7551 final long identity = Binder.clearCallingIdentity();
7552 try {
7553 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7554 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007555 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 }
7557 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007560 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007561 }
7562
7563 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007564 * Returns whether vibration is set for voicemail notification in Phone settings.
7565 *
7566 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7567 * voicemail vibration setting.
7568 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7569 */
7570 @Override
7571 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 final long identity = Binder.clearCallingIdentity();
7573 try {
7574 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7575 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007576 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007583 }
7584
Youhan Wange64578a2016-05-02 15:32:42 -07007585 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007586 * Sets the per-account voicemail vibration.
7587 *
7588 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7589 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7590 *
7591 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7592 * voicemail vibration setting.
7593 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7594 * specific PhoneAccount.
7595 */
7596 @Override
7597 public void setVoicemailVibrationEnabled(String callingPackage,
7598 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007601 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7602 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7604 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7605 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007606 }
7607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7611 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007612 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 }
7614 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007617 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007618 }
7619
7620 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007621 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7622 *
7623 * @throws SecurityException if the caller does not have the required permission
7624 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007625 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007626 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007627 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007628 }
7629
7630 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007631 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7632 * permission.
7633 *
7634 * @throws SecurityException if the caller does not have the required permission
7635 */
7636 private void enforceSendSmsPermission() {
7637 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7638 }
7639
7640 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007641 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007642 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007643 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007644 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007645 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007649 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 if (componentName == null) {
7651 throw new SecurityException(
7652 "Caller not current active visual voicemail package[null]");
7653 }
7654 String vvmPackage = componentName.getPackageName();
7655 if (!callingPackage.equals(vvmPackage)) {
7656 throw new SecurityException("Caller not current active visual voicemail package["
7657 + vvmPackage + "]");
7658 }
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007661 }
7662 }
7663
7664 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007665 * Return the application ID for the app type.
7666 *
7667 * @param subId the subscription ID that this request applies to.
7668 * @param appType the uicc app type.
7669 * @return Application ID for specificied app type, or null if no uicc.
7670 */
7671 @Override
7672 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007673 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007674 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675
7676 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007677 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 if (phone == null) {
7679 return null;
7680 }
7681 String aid = null;
7682 try {
7683 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7684 .getApplicationByType(appType).getAid();
7685 } catch (Exception e) {
7686 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7687 }
7688 return aid;
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007691 }
Youhan Wange64578a2016-05-02 15:32:42 -07007692 }
7693
Youhan Wang4001d252016-05-11 10:29:41 -07007694 /**
7695 * Return the Electronic Serial Number.
7696 *
7697 * @param subId the subscription ID that this request applies to.
7698 * @return ESN or null if error.
7699 */
7700 @Override
7701 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007702 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007703 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007704
7705 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007706 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 if (phone == null) {
7708 return null;
7709 }
7710 String esn = null;
7711 try {
7712 esn = phone.getEsn();
7713 } catch (Exception e) {
7714 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7715 }
7716 return esn;
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007719 }
Youhan Wang4001d252016-05-11 10:29:41 -07007720 }
7721
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007722 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007723 * Return the Preferred Roaming List Version.
7724 *
7725 * @param subId the subscription ID that this request applies to.
7726 * @return PRLVersion or null if error.
7727 */
7728 @Override
7729 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007730 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007731 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732
7733 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007734 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 if (phone == null) {
7736 return null;
7737 }
7738 String cdmaPrlVersion = null;
7739 try {
7740 cdmaPrlVersion = phone.getCdmaPrlVersion();
7741 } catch (Exception e) {
7742 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7743 }
7744 return cdmaPrlVersion;
7745 } finally {
7746 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007747 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007748 }
7749
7750 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007751 * Get snapshot of Telephony histograms
7752 * @return List of Telephony histograms
7753 * @hide
7754 */
7755 @Override
7756 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7758 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759
7760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 return RIL.getTelephonyRILTimingHistograms();
7763 } finally {
7764 Binder.restoreCallingIdentity(identity);
7765 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007766 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007767
7768 /**
7769 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007770 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7771 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007772 * Require system privileges. In the future we may add this to carrier APIs.
7773 *
Michele Berionne482f8202018-11-27 18:57:59 -08007774 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007775 */
7776 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007777 @TelephonyManager.SetCarrierRestrictionResult
7778 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007779 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007781
Michele Berionne482f8202018-11-27 18:57:59 -08007782 if (carrierRestrictionRules == null) {
7783 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007784 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 final long identity = Binder.clearCallingIdentity();
7787 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007788 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007789 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 } finally {
7791 Binder.restoreCallingIdentity(identity);
7792 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007793 }
7794
7795 /**
7796 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007797 * Get the allowed carrier list and the excluded carrier list, including the priority between
7798 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007799 * Require system privileges. In the future we may add this to carrier APIs.
7800 *
Michele Berionne482f8202018-11-27 18:57:59 -08007801 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007802 */
7803 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007804 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007805 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007806 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807
7808 final long identity = Binder.clearCallingIdentity();
7809 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007810 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7811 if (response instanceof CarrierRestrictionRules) {
7812 return (CarrierRestrictionRules) response;
7813 }
7814 // Response is an Exception of some kind,
7815 // which is signalled to the user as a NULL retval
7816 return null;
7817 } catch (Exception e) {
7818 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7819 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007823 }
7824
fionaxu59545b42016-05-25 15:53:37 -07007825 /**
fionaxu59545b42016-05-25 15:53:37 -07007826 * Action set from carrier signalling broadcast receivers to enable/disable radio
7827 * @param subId the subscription ID that this action applies to.
7828 * @param enabled control enable or disable radio.
7829 * {@hide}
7830 */
7831 @Override
7832 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7833 enforceModifyPermission();
7834 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835
7836 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007837 if (phone == null) {
7838 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7839 return;
7840 }
7841 try {
7842 phone.carrierActionSetRadioEnabled(enabled);
7843 } catch (Exception e) {
7844 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 } finally {
7846 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007847 }
7848 }
7849
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007850 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007851 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7852 * network status based on which carrier apps could apply actions accordingly,
7853 * enable/disable default url handler for example.
7854 *
7855 * @param subId the subscription ID that this action applies to.
7856 * @param report control start/stop reporting the default network status.
7857 * {@hide}
7858 */
7859 @Override
7860 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7861 enforceModifyPermission();
7862 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007863
7864 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007865 if (phone == null) {
7866 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7867 return;
7868 }
7869 try {
7870 phone.carrierActionReportDefaultNetworkStatus(report);
7871 } catch (Exception e) {
7872 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 } finally {
7874 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007875 }
7876 }
7877
7878 /**
fionaxud9622282017-07-17 17:51:30 -07007879 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7880 * @param subId the subscription ID that this action applies to.
7881 * {@hide}
7882 */
7883 @Override
7884 public void carrierActionResetAll(int subId) {
7885 enforceModifyPermission();
7886 final Phone phone = getPhone(subId);
7887 if (phone == null) {
7888 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7889 return;
7890 }
7891 try {
7892 phone.carrierActionResetAll();
7893 } catch (Exception e) {
7894 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7895 }
7896 }
7897
7898 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007899 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7900 * bug report is being generated.
7901 */
7902 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007903 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007904 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7905 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007906 writer.println("Permission Denial: can't dump Phone from pid="
7907 + Binder.getCallingPid()
7908 + ", uid=" + Binder.getCallingUid()
7909 + "without permission "
7910 + android.Manifest.permission.DUMP);
7911 return;
7912 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007913 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007914 }
Jack Yueb89b242016-06-22 13:27:47 -07007915
Brad Ebingerdac2f002018-04-03 15:17:52 -07007916 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007917 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7918 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7919 @NonNull String[] args) {
7920 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7921 this, in.getFileDescriptor(), out.getFileDescriptor(),
7922 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007923 }
7924
Jack Yueb89b242016-06-22 13:27:47 -07007925 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007926 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007927 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007928 * @param reason the reason the data enable change is taking place
7929 * @param enabled True if enabling the data, otherwise disabling.
7930 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007931 */
7932 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007933 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007934 boolean enabled) {
7935 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7936 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7937 try {
7938 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007939 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007940 } catch (SecurityException se) {
7941 enforceModifyPermission();
7942 }
7943 } else {
7944 enforceModifyPermission();
7945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946
7947 final long identity = Binder.clearCallingIdentity();
7948 try {
7949 Phone phone = getPhone(subId);
7950 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007951 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7952 phone.carrierActionSetMeteredApnsEnabled(enabled);
7953 } else {
7954 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 }
7957 } finally {
7958 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007959 }
7960 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007961
7962 /**
7963 * Get Client request stats
7964 * @return List of Client Request Stats
7965 * @hide
7966 */
7967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007968 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7969 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007970 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007971 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007972 return null;
7973 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007974 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 if (phone != null) {
7979 return phone.getClientRequestStats();
7980 }
7981
7982 return null;
7983 } finally {
7984 Binder.restoreCallingIdentity(identity);
7985 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007986 }
7987
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007988 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007989 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007990 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007991 }
Jack Yueb4124c2017-02-16 15:32:43 -08007992
7993 /**
Grace Chen70990072017-03-24 17:21:30 -07007994 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007995 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007996 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007997 * @param state State of SIM (power down, power up, pass through)
7998 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7999 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8000 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008001 *
8002 **/
8003 @Override
Grace Chen70990072017-03-24 17:21:30 -07008004 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008005 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008006 Phone phone = PhoneFactory.getPhone(slotIndex);
8007
vagdeviaf9a5b92018-08-15 16:01:53 -07008008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008013 phone.setSimPowerState(state, null, workSource);
8014 }
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
8018 }
8019
8020 /**
8021 * Set SIM card power state.
8022 *
8023 * @param slotIndex SIM slot id.
8024 * @param state State of SIM (power down, power up, pass through)
8025 * @param callback callback to trigger after success or failure
8026 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8027 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8028 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8029 *
8030 **/
8031 @Override
8032 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8033 IIntegerConsumer callback) {
8034 enforceModifyPermission();
8035 Phone phone = PhoneFactory.getPhone(slotIndex);
8036
8037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8038
8039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 if (phone != null) {
8042 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8043 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044 }
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008047 }
8048 }
Shuo Qiandd210312017-04-12 22:11:33 +00008049
Tyler Gunn65d45c22017-06-05 11:22:26 -07008050 private boolean isUssdApiAllowed(int subId) {
8051 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008052 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008053 if (configManager == null) {
8054 return false;
8055 }
8056 PersistableBundle pb = configManager.getConfigForSubId(subId);
8057 if (pb == null) {
8058 return false;
8059 }
8060 return pb.getBoolean(
8061 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8062 }
8063
Shuo Qiandd210312017-04-12 22:11:33 +00008064 /**
8065 * Check if phone is in emergency callback mode
8066 * @return true if phone is in emergency callback mode
8067 * @param subId sub id
8068 */
goneil9c5f4872017-12-05 14:07:56 -08008069 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008070 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008071 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008072 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073
8074 final long identity = Binder.clearCallingIdentity();
8075 try {
8076 if (phone != null) {
8077 return phone.isInEcm();
8078 } else {
8079 return false;
8080 }
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008083 }
8084 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008085
8086 /**
8087 * Get the current signal strength information for the given subscription.
8088 * Because this information is not updated when the device is in a low power state
8089 * it should not be relied-upon to be current.
8090 * @param subId Subscription index
8091 * @return the most recent cached signal strength info from the modem
8092 */
8093 @Override
8094 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 Phone p = getPhone(subId);
8098 if (p == null) {
8099 return null;
8100 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 return p.getSignalStrength();
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
8105 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008106 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008107
Pengquan Meng77b7f132018-08-22 14:49:57 -07008108 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008109 * Get the current modem radio state for the given slot.
8110 * @param slotIndex slot index.
8111 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008112 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008113 * @return the current radio power state from the modem
8114 */
8115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008116 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008117 Phone phone = PhoneFactory.getPhone(slotIndex);
8118 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8120 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008121 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8122 }
8123
8124 final long identity = Binder.clearCallingIdentity();
8125 try {
8126 return phone.getRadioPowerState();
8127 } finally {
8128 Binder.restoreCallingIdentity(identity);
8129 }
8130 }
8131 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8132 }
8133
8134 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008135 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8136 *
8137 * <p>Requires one of the following permissions:
8138 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8139 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8140 * privileges.
8141 *
8142 * @param subId subscription id
8143 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8144 * {@code false}.
8145 */
8146 @Override
8147 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008148 try {
8149 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8150 null);
8151 } catch (Exception e) {
8152 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8153 mApp, subId, "isDataRoamingEnabled");
8154 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008155
Pengquan Menga1bb6272018-09-06 09:59:22 -07008156 boolean isEnabled = false;
8157 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008158 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008159 Phone phone = getPhone(subId);
8160 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008161 } finally {
8162 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008163 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008164 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008165 }
8166
8167
8168 /**
8169 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8170 *
8171 * <p> Requires permission:
8172 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8173 * privileges.
8174 *
8175 * @param subId subscription id
8176 * @param isEnabled {@code true} means enable, {@code false} means disable.
8177 */
8178 @Override
8179 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8181 mApp, subId, "setDataRoamingEnabled");
8182
Pengquan Menga1bb6272018-09-06 09:59:22 -07008183 final long identity = Binder.clearCallingIdentity();
8184 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008185 Phone phone = getPhone(subId);
8186 if (phone != null) {
8187 phone.setDataRoamingEnabled(isEnabled);
8188 }
8189 } finally {
8190 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008191 }
8192 }
8193
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008194 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008195 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008196 TelephonyPermissions
8197 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008198 mApp, subId, "isManualNetworkSelectionAllowed");
8199
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008200 boolean isAllowed = true;
8201 final long identity = Binder.clearCallingIdentity();
8202 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008203 Phone phone = getPhone(subId);
8204 if (phone != null) {
8205 isAllowed = phone.isCspPlmnEnabled();
8206 }
8207 } finally {
8208 Binder.restoreCallingIdentity(identity);
8209 }
8210 return isAllowed;
8211 }
8212
8213 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008214 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008215 // Verify that tha callingPackage belongs to the calling UID
8216 mApp.getSystemService(AppOpsManager.class)
8217 .checkPackage(Binder.getCallingUid(), callingPackage);
8218
Jordan Liu1e142fc2019-04-22 15:10:43 -07008219 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008220 try {
8221 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008222 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008223 } catch (SecurityException e) {
8224 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8225 // has carrier privileges on an active UICC
8226 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8227 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008228 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008229 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008230 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008231
8232 final long identity = Binder.clearCallingIdentity();
8233 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008234 UiccController uiccController = UiccController.getInstance();
8235 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008236 if (hasReadPermission) {
8237 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008238 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008239
8240 // Remove private info if the caller doesn't have access
8241 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8242 for (UiccCardInfo cardInfo : cardInfos) {
8243 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8244 // is available
8245 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8246 if (card == null || card.getUiccProfile() == null) {
8247 // assume no access if the card or profile is unavailable
8248 filteredInfos.add(cardInfo.getUnprivileged());
8249 continue;
8250 }
8251 UiccProfile profile = card.getUiccProfile();
8252 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8253 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8254 filteredInfos.add(cardInfo);
8255 } else {
8256 filteredInfos.add(cardInfo.getUnprivileged());
8257 }
8258 }
8259 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008260 } finally {
8261 Binder.restoreCallingIdentity(identity);
8262 }
8263 }
8264
8265 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008266 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008267 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 final long identity = Binder.clearCallingIdentity();
8270 try {
8271 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8272 if (slots == null) {
8273 Rlog.i(LOG_TAG, "slots is null.");
8274 return null;
8275 }
8276
8277 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8278 for (int i = 0; i < slots.length; i++) {
8279 UiccSlot slot = slots[i];
8280 if (slot == null) {
8281 continue;
8282 }
8283
Jordan Liu7be7e652019-05-06 18:55:02 +00008284 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 UiccCard card = slot.getUiccCard();
8286 if (card != null) {
8287 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008288 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008289 cardId = slot.getEid();
8290 if (TextUtils.isEmpty(cardId)) {
8291 cardId = slot.getIccId();
8292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 }
8294
Jordan Liu857451f2019-05-09 16:35:35 -07008295 if (cardId != null) {
8296 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8297 // if cardId is an EID, it's all digits so this is fine
8298 cardId = IccUtils.stripTrailingFs(cardId);
8299 }
8300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 int cardState = 0;
8302 switch (slot.getCardState()) {
8303 case CARDSTATE_ABSENT:
8304 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8305 break;
8306 case CARDSTATE_PRESENT:
8307 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8308 break;
8309 case CARDSTATE_ERROR:
8310 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8311 break;
8312 case CARDSTATE_RESTRICTED:
8313 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8314 break;
8315 default:
8316 break;
8317
8318 }
8319
8320 infos[i] = new UiccSlotInfo(
8321 slot.isActive(),
8322 slot.isEuicc(),
8323 cardId,
8324 cardState,
8325 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008326 slot.isExtendedApduSupported(),
8327 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 }
8329 return infos;
8330 } finally {
8331 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008332 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008333 }
8334
8335 @Override
8336 public boolean switchSlots(int[] physicalSlots) {
8337 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338
8339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008345 }
Jack Yu4c988042018-02-27 15:30:01 -08008346
8347 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008348 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 return UiccController.getInstance().getCardIdForDefaultEuicc();
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 }
8356
Pengquan Meng85728fb2018-03-12 16:31:21 -07008357 /**
goneil47ffb6e2018-04-06 15:40:58 -07008358 * A test API to reload the UICC profile.
8359 *
8360 * <p>Requires that the calling app has permission
8361 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8362 * @hide
8363 */
8364 @Override
8365 public void refreshUiccProfile(int subId) {
8366 enforceModifyPermission();
8367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 Phone phone = getPhone(subId);
8371 if (phone == null) {
8372 return;
8373 }
8374 UiccCard uiccCard = phone.getUiccCard();
8375 if (uiccCard == null) {
8376 return;
8377 }
8378 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8379 if (uiccProfile == null) {
8380 return;
8381 }
8382 uiccProfile.refresh();
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
8386 }
8387
8388 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008389 * Returns false if the mobile data is disabled by default, otherwise return true.
8390 */
8391 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008392 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008393 }
8394
8395 /**
8396 * Returns true if the data roaming is enabled by default, i.e the system property
8397 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8398 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8399 */
8400 private boolean getDefaultDataRoamingEnabled(int subId) {
8401 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008402 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008403 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008404 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8405 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8406 return isDataRoamingEnabled;
8407 }
8408
8409 /**
8410 * Returns the default network type for the given {@code subId}, if the default network type is
8411 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8412 */
8413 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008414 List<Integer> list = TelephonyProperties.default_network();
8415 int phoneId = mSubscriptionController.getPhoneId(subId);
8416 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8417 return list.get(phoneId);
8418 }
8419 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008420 }
fionaxua13278b2018-03-21 00:08:13 -07008421
8422 @Override
8423 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008424 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008425 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008426
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 final Phone phone = getPhone(subId);
8430 if (phone == null) {
8431 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8432 return;
8433 }
chen xueaba88a2019-03-15 13:15:10 -07008434 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8435 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008436 if (carrierPrivilegeRules == null) {
8437 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8438 } else {
8439 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441 } finally {
8442 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008443 }
fionaxua13278b2018-03-21 00:08:13 -07008444 }
8445
8446 @Override
8447 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008448 enforceReadPrivilegedPermission("getCarrierIdListVersion");
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("getCarrierIdListVersion fails with invalid subId: " + subId);
8455 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8456 }
8457 return phone.getCarrierIdListVersion();
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008460 }
fionaxua13278b2018-03-21 00:08:13 -07008461 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008462
8463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008464 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8465 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 mApp, subId, callingPackage, callingFeatureId,
8468 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008469 return -1;
8470 }
8471
8472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
8477 }
8478 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008479
8480 @Override
8481 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008482 TelephonyPermissions
8483 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008484 mApp, subId, "getCdmaRoamingMode");
8485
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
8492 }
8493
8494 @Override
8495 public boolean setCdmaRoamingMode(int subId, int mode) {
8496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8497 mApp, subId, "setCdmaRoamingMode");
8498
8499 final long identity = Binder.clearCallingIdentity();
8500 try {
8501 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
8505 }
8506
8507 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008508 public int getCdmaSubscriptionMode(int subId) {
8509 TelephonyPermissions
8510 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8511 mApp, subId, "getCdmaSubscriptionMode");
8512
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
8521 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008522 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8524 mApp, subId, "setCdmaSubscriptionMode");
8525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
8532 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008533
sqianc5eccab2018-10-19 18:46:41 -07008534 @Override
sqian8c685422019-02-22 15:55:18 -08008535 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008536 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008538 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8539 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008540 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8541 }
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
sqian854d44b2018-12-12 16:48:18 -08008544 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8545 for (Phone phone: PhoneFactory.getPhones()) {
8546 if (phone.getEmergencyNumberTracker() != null
8547 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8548 emergencyNumberListInternal.put(
8549 phone.getSubId(),
8550 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8551 }
sqian11b7a0e2018-12-05 18:48:28 -08008552 }
sqian854d44b2018-12-12 16:48:18 -08008553 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
sqianc5eccab2018-10-19 18:46:41 -07008557 }
8558
8559 @Override
sqian8c685422019-02-22 15:55:18 -08008560 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008561 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008562 if (!exactMatch) {
8563 TelephonyPermissions
8564 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008565 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008566 }
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
sqian854d44b2018-12-12 16:48:18 -08008569 for (Phone phone: PhoneFactory.getPhones()) {
8570 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008571 && phone.getEmergencyNumberTracker()
8572 .isEmergencyNumber(number, exactMatch)) {
8573 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008574 }
sqian11b7a0e2018-12-05 18:48:28 -08008575 }
8576 return false;
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
8580 }
8581
sqianf4ca7ed2019-01-15 18:32:07 -08008582 /**
8583 * Update emergency number list for test mode.
8584 */
8585 @Override
8586 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8587 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8588 "updateEmergencyNumberListTestMode");
8589
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 for (Phone phone: PhoneFactory.getPhones()) {
8593 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8594 if (tracker != null) {
8595 tracker.executeEmergencyNumberTestModeCommand(action, num);
8596 }
8597 }
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
8601 }
8602
8603 /**
8604 * Get the full emergency number list for test mode.
8605 */
8606 @Override
8607 public List<String> getEmergencyNumberListTestMode() {
8608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8609 "getEmergencyNumberListTestMode");
8610
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 Set<String> emergencyNumbers = new HashSet<>();
8614 for (Phone phone: PhoneFactory.getPhones()) {
8615 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8616 if (tracker != null) {
8617 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8618 emergencyNumbers.add(num.getNumber());
8619 }
8620 }
8621 }
8622 return new ArrayList<>(emergencyNumbers);
8623 } finally {
8624 Binder.restoreCallingIdentity(identity);
8625 }
8626 }
8627
chen xud6b45bd2018-10-30 22:27:10 -07008628 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008629 public int getEmergencyNumberDbVersion(int subId) {
8630 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 final Phone phone = getPhone(subId);
8635 if (phone == null) {
8636 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8637 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8638 }
8639 return phone.getEmergencyNumberDbVersion();
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
8643 }
8644
8645 @Override
8646 public void notifyOtaEmergencyNumberDbInstalled() {
8647 enforceModifyPermission();
8648
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
8651 for (Phone phone: PhoneFactory.getPhones()) {
8652 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8653 if (tracker != null) {
8654 tracker.updateOtaEmergencyNumberDatabase();
8655 }
8656 }
8657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
8661
8662 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008663 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008664 enforceActiveEmergencySessionPermission();
8665
8666 final long identity = Binder.clearCallingIdentity();
8667 try {
8668 for (Phone phone: PhoneFactory.getPhones()) {
8669 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8670 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008671 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8672 }
8673 }
8674 } finally {
8675 Binder.restoreCallingIdentity(identity);
8676 }
8677 }
8678
8679 @Override
8680 public void resetOtaEmergencyNumberDbFilePath() {
8681 enforceActiveEmergencySessionPermission();
8682
8683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 for (Phone phone: PhoneFactory.getPhones()) {
8686 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8687 if (tracker != null) {
8688 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008689 }
8690 }
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
8694 }
8695
8696 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008697 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8698 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8699 Phone phone = getPhone(subId);
8700 if (phone == null) {
8701 return null;
8702 }
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
8705 UiccProfile profile = UiccController.getInstance()
8706 .getUiccProfileForPhone(phone.getPhoneId());
8707 if (profile != null) {
8708 return profile.getCertsFromCarrierPrivilegeAccessRules();
8709 }
8710 } finally {
8711 Binder.restoreCallingIdentity(identity);
8712 }
8713 return null;
8714 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008715
8716 /**
8717 * Enable or disable a modem stack.
8718 */
8719 @Override
8720 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8721 enforceModifyPermission();
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 Phone phone = PhoneFactory.getPhone(slotIndex);
8726 if (phone == null) {
8727 return false;
8728 } else {
8729 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
Michelecea4cf22018-12-21 15:00:11 -08008735
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008736 /**
8737 * Whether a modem stack is enabled or not.
8738 */
8739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008740 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8741 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008742 Phone phone = PhoneFactory.getPhone(slotIndex);
8743 if (phone == null) return false;
8744
8745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008746 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8747 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008748 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8749 }
8750
8751 final long identity = Binder.clearCallingIdentity();
8752 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008753 try {
8754 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8755 } catch (NoSuchElementException ex) {
8756 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8757 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008758 } finally {
8759 Binder.restoreCallingIdentity(identity);
8760 }
8761 }
8762
Michelecea4cf22018-12-21 15:00:11 -08008763 @Override
Michele0ea7d782019-03-19 14:58:42 -07008764 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008765 enforceModifyPermission();
8766
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008770 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008771 .commit();
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
8776
8777 @Override
Michele0ea7d782019-03-19 14:58:42 -07008778 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008779 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008781 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8782 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008783 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008784 }
Michelecea4cf22018-12-21 15:00:11 -08008785
8786 final long identity = Binder.clearCallingIdentity();
8787 try {
Michele0ea7d782019-03-19 14:58:42 -07008788 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008789 } finally {
8790 Binder.restoreCallingIdentity(identity);
8791 }
8792 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008793
Michele0ea7d782019-03-19 14:58:42 -07008794 @TelephonyManager.IsMultiSimSupportedResult
8795 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008796 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8797 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8798 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008799 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8800 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008801 }
8802 // Check if the hardware supports multisim functionality. If usage of multisim is not
8803 // supported by the modem, indicate that it is restricted.
8804 PhoneCapability staticCapability =
8805 mPhoneConfigurationManager.getStaticPhoneCapability();
8806 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008807 loge("isMultiSimSupportedInternal: no static configuration available");
8808 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008809 }
Sarah Chin7caee492020-02-18 20:49:02 +00008810 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008811 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8812 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008813 }
8814 // Check if support of multiple SIMs is restricted by carrier
8815 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008816 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008817 }
8818
Michele0ea7d782019-03-19 14:58:42 -07008819 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008820 }
8821
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008822 /**
8823 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008824 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8825 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8826 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008827 * @param numOfSims number of active sims we want to switch to
8828 */
8829 @Override
8830 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008831 if (numOfSims == 1) {
8832 enforceModifyPermission();
8833 } else {
8834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8835 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8836 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008837 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008838
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008839 try {
Michele30b57b22019-03-01 12:01:14 -08008840 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008841 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008842 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8843 return;
8844 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008845 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8846 } finally {
8847 Binder.restoreCallingIdentity(identity);
8848 }
8849 }
8850
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008851 @Override
8852 public boolean isApplicationOnUicc(int subId, int appType) {
8853 enforceReadPrivilegedPermission("isApplicationOnUicc");
8854 Phone phone = getPhone(subId);
8855 if (phone == null) {
8856 return false;
8857 }
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 UiccCard uiccCard = phone.getUiccCard();
8861 if (uiccCard == null) {
8862 return false;
8863 }
8864 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8865 if (uiccProfile == null) {
8866 return false;
8867 }
8868 if (TelephonyManager.APPTYPE_SIM <= appType
8869 && appType <= TelephonyManager.APPTYPE_ISIM) {
8870 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8871 }
8872 return false;
8873 } finally {
8874 Binder.restoreCallingIdentity(identity);
8875 }
8876 }
8877
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008878 /**
chen xub4baa772019-04-03 10:23:41 -07008879 * Get whether making changes to modem configurations will trigger reboot.
8880 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008881 */
8882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008883 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8884 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008886 mApp, subId, callingPackage, callingFeatureId,
8887 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008888 return false;
8889 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008890 final long identity = Binder.clearCallingIdentity();
8891 try {
8892 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8893 } finally {
8894 Binder.restoreCallingIdentity(identity);
8895 }
8896 }
8897
Nathan Harold29f5f052019-02-15 13:41:57 -08008898 private void updateModemStateMetrics() {
8899 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8900 // TODO: check the state for each modem if the api is ready.
8901 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8902 }
8903
Pengquan Meng3889a572019-01-23 11:16:29 -08008904 @Override
8905 public int[] getSlotsMapping() {
8906 enforceReadPrivilegedPermission("getSlotsMapping");
8907
8908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8911 // All logical slots should have a mapping to a physical slot.
8912 int[] logicalSlotsMapping = new int[phoneCount];
8913 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8914 for (int i = 0; i < slotInfos.length; i++) {
8915 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8916 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8917 }
8918 }
8919 return logicalSlotsMapping;
8920 } finally {
8921 Binder.restoreCallingIdentity(identity);
8922 }
8923 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008924
8925 /**
8926 * Get the IRadio HAL Version
8927 */
8928 @Override
8929 public int getRadioHalVersion() {
8930 Phone phone = getDefaultPhone();
8931 if (phone == null) return -1;
8932 HalVersion hv = phone.getHalVersion();
8933 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8934 return hv.major * 100 + hv.minor;
8935 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008936
8937 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008938 * Get the current calling package name.
8939 * @return the current calling package name
8940 */
8941 @Override
8942 public String getCurrentPackageName() {
8943 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8944 }
8945
8946 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008947 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8948 * corresponding network requests on a subId.
8949 *
8950 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008951 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008952 * 2) APN is un-metered for this subscription, or
8953 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008954 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008955 *
8956 * @return whether data is allowed for a apn type.
8957 *
8958 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008959 */
8960 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008961 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008962 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8963 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008964
8965 // Now that all security checks passes, perform the operation as ourselves.
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 Phone phone = getPhone(subId);
8969 if (phone == null) return false;
8970
Jack Yu41407ee2019-05-13 16:54:09 -07008971 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008972 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
8976 }
8977
8978 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008979 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008980 enforceReadPrivilegedPermission("isApnMetered");
8981
8982 // Now that all security checks passes, perform the operation as ourselves.
8983 final long identity = Binder.clearCallingIdentity();
8984 try {
8985 Phone phone = getPhone(subId);
8986 if (phone == null) return true; // By default return true.
8987
Jack Yu41407ee2019-05-13 16:54:09 -07008988 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
8992 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008993
8994 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008995 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8996 int subscriptionId, IBooleanConsumer resultCallback) {
8997 enforceModifyPermission();
8998 long token = Binder.clearCallingIdentity();
8999 try {
9000 Phone phone = getPhone(subscriptionId);
9001 if (phone == null) {
9002 try {
9003 if (resultCallback != null) {
9004 resultCallback.accept(false);
9005 }
9006 } catch (RemoteException e) {
9007 // ignore
9008 }
9009 return;
9010 }
9011 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9012 Pair.create(specifiers, (x) -> {
9013 try {
9014 if (resultCallback != null) {
9015 resultCallback.accept(x);
9016 }
9017 } catch (RemoteException e) {
9018 // ignore
9019 }
9020 });
9021 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9022 } finally {
9023 Binder.restoreCallingIdentity(token);
9024 }
9025 }
9026
9027 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009028 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9029 TelephonyPermissions
9030 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9031 mApp, subId, "getSystemSelectionChannels");
9032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 List<RadioAccessSpecifier> specifiers =
9036 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9037 null, subId, workSource);
9038 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9039 return specifiers;
9040 } finally {
9041 Binder.restoreCallingIdentity(identity);
9042 }
9043 }
9044
9045 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009046 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009047 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009048 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9049 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9050 if (iccRecords == null) {
9051 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9052 return false;
9053 }
9054 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9055 }
9056
9057 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009058 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9059 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009060 if (callingPackage == null) {
9061 callingPackage = getCurrentPackageName();
9062 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009063 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9064 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009065 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9066 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009067 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9068 }
9069 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9070 Intent intent = new Intent();
9071 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9072 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9073 // Bring up choose default SMS subscription dialog right now
9074 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9075 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9076 mApp.startActivity(intent);
9077 }
chen xud5ca2d52019-05-28 15:20:57 -07009078
9079 @Override
9080 public String getMmsUAProfUrl(int subId) {
9081 //TODO investigate if this API should require proper permission check in R b/133791609
9082 final long identity = Binder.clearCallingIdentity();
9083 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009084 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9085 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9086 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9087 return carrierUAProfUrl;
9088 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009089 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9090 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
9095
9096 @Override
9097 public String getMmsUserAgent(int subId) {
9098 //TODO investigate if this API should require proper permission check in R b/133791609
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009101 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9102 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9103 if (!TextUtils.isEmpty(carrierUserAgent)) {
9104 return carrierUserAgent;
9105 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009106 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9107 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
Jack Yub07d4972019-05-28 16:12:25 -07009112
9113 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009114 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9115 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009116
Jack Yub07d4972019-05-28 16:12:25 -07009117 final long identity = Binder.clearCallingIdentity();
9118 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009119 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009120 if (phone == null) return false;
9121
Hall Liua62f5da2020-09-25 10:42:19 -07009122 switch (policy) {
9123 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9124 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9125 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9126 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9127 default:
9128 throw new IllegalArgumentException(policy + " is not a valid policy");
9129 }
Jack Yub07d4972019-05-28 16:12:25 -07009130 } finally {
9131 Binder.restoreCallingIdentity(identity);
9132 }
9133 }
9134
9135 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009136 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9137 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009138 enforceModifyPermission();
9139
changbettyd5c246e2019-12-24 15:40:37 +08009140 final long identity = Binder.clearCallingIdentity();
9141 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009142 Phone phone = getPhone(subscriptionId);
9143 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009144
Hall Liua62f5da2020-09-25 10:42:19 -07009145 switch (policy) {
9146 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9147 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9148 break;
9149 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9150 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9151 break;
9152 default:
9153 throw new IllegalArgumentException(policy + " is not a valid policy");
9154 }
changbettyd5c246e2019-12-24 15:40:37 +08009155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
9158 }
9159
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009160 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009161 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009162 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9163 * otherwise.
9164 */
9165 @Override
9166 public void setCepEnabled(boolean isCepEnabled) {
9167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9172 for (Phone phone : PhoneFactory.getPhones()) {
9173 Phone defaultPhone = phone.getImsPhone();
9174 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9175 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9176 ImsPhoneCallTracker imsPhoneCallTracker =
9177 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9178 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9179 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9180 + imsPhone.getMsisdn());
9181 }
9182 }
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
allenwtsu46dcc572020-01-08 18:24:03 +08009187
9188 /**
9189 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9190 *
9191 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9192 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9193 * before being read.
9194 */
9195 @Override
9196 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9197 isCompressed) {
9198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9199 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009200 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9201 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9202 }
9203 if (!isImsAvailableOnDevice()) {
9204 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9205 "IMS not available on device.");
9206 }
9207
9208 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009209 try {
Hui Wang761a6682020-10-31 05:12:53 +00009210 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009213 }
9214 }
zoey chene02881a2019-12-30 16:11:23 +08009215
9216 @Override
9217 public boolean isIccLockEnabled(int subId) {
9218 enforceReadPrivilegedPermission("isIccLockEnabled");
9219
9220 // Now that all security checks passes, perform the operation as ourselves.
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 Phone phone = getPhone(subId);
9224 if (phone != null && phone.getIccCard() != null) {
9225 return phone.getIccCard().getIccLockEnabled();
9226 } else {
9227 return false;
9228 }
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 }
9233
9234 /**
9235 * Set the ICC pin lock enabled or disabled.
9236 *
9237 * @return an integer representing the status of IccLock enabled or disabled in the following
9238 * three cases:
9239 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9240 * successfully.
9241 * - Positive number and zero for remaining password attempts.
9242 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9243 *
9244 */
9245 @Override
9246 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9247 enforceModifyPermission();
9248
9249 Phone phone = getPhone(subId);
9250 if (phone == null) {
9251 return 0;
9252 }
9253 // Now that all security checks passes, perform the operation as ourselves.
9254 final long identity = Binder.clearCallingIdentity();
9255 try {
9256 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9257 new Pair<Boolean, String>(enabled, password), phone, null);
9258 return attemptsRemaining;
9259
9260 } catch (Exception e) {
9261 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 return 0;
9266 }
9267
9268 /**
9269 * Change the ICC password used in ICC pin lock.
9270 *
9271 * @return an integer representing the status of IccLock changed in the following three cases:
9272 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9273 * - Positive number and zero for remaining password attempts.
9274 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9275 *
9276 */
9277 @Override
9278 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9279 enforceModifyPermission();
9280
9281 Phone phone = getPhone(subId);
9282 if (phone == null) {
9283 return 0;
9284 }
9285 // Now that all security checks passes, perform the operation as ourselves.
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9289 new Pair<String, String>(oldPassword, newPassword), phone, null);
9290 return attemptsRemaining;
9291
9292 } catch (Exception e) {
9293 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9294 } finally {
9295 Binder.restoreCallingIdentity(identity);
9296 }
9297 return 0;
9298 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009299
9300 /**
9301 * Request for receiving user activity notification
9302 */
9303 @Override
9304 public void requestUserActivityNotification() {
9305 if (!mNotifyUserActivity.get()
9306 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9307 mNotifyUserActivity.set(true);
9308 }
9309 }
9310
9311 /**
9312 * Called when userActivity is signalled in the power manager.
9313 * This is safe to call from any thread, with any window manager locks held or not.
9314 */
9315 @Override
9316 public void userActivity() {
9317 // ***************************************
9318 // * Inherited from PhoneWindowManager *
9319 // ***************************************
9320 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9321 // WITH ITS LOCKS HELD.
9322 //
9323 // This code must be VERY careful about the locks
9324 // it acquires.
9325 // In fact, the current code acquires way too many,
9326 // and probably has lurking deadlocks.
9327
9328 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9329 throw new SecurityException("Only the OS may call notifyUserActivity()");
9330 }
9331
9332 if (mNotifyUserActivity.getAndSet(false)) {
9333 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9334 USER_ACTIVITY_NOTIFICATION_DELAY);
9335 }
9336 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009337
9338 @Override
9339 public boolean canConnectTo5GInDsdsMode() {
9340 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9341 }
Jack Yud10cdd42020-09-28 20:28:01 -07009342
9343 @Override
9344 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9345 String callingFeatureId) {
9346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9347 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9348 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9349 }
9350
9351 Phone phone = getPhone(subId);
9352 if (phone == null) {
9353 throw new RuntimeException("phone is not available");
9354 }
9355 // Now that all security checks passes, perform the operation as ourselves.
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 return phone.getEquivalentHomePlmns();
9359 } finally {
9360 Binder.restoreCallingIdentity(identity);
9361 }
9362 }
Daniel Bright59e67312020-11-13 11:49:37 -08009363
9364 @Override
9365 public boolean isRadioInterfaceCapabilitySupported(
9366 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9367 RadioInterfaceCapabilities radioInterfaceCapabilities =
9368 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9369 if (radioInterfaceCapabilities == null) {
9370 throw new RuntimeException("radio interface capabilities are not available");
9371 } else {
9372 return radioInterfaceCapabilities.isSupported(capability);
9373 }
9374 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009375
Hui Wang641e81c2020-10-12 12:14:23 -07009376 @Override
9377 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9378 UaSecurityProtocolIdentifier securityProtocol,
9379 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9380 throws RemoteException {
9381 enforceModifyPermission();
9382 if (DBG) {
9383 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9384 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9385 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9386 }
9387
9388 if (!SubscriptionManager.isValidSubscriptionId(subId)
9389 || appType < TelephonyManager.APPTYPE_UNKNOWN
9390 || appType > TelephonyManager.APPTYPE_ISIM
9391 || nafUrl == null || securityProtocol == null || callback == null) {
9392 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9393 if (callback != null) {
9394 try {
9395 callback.onAuthenticationFailure(
9396 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9397 } catch (RemoteException exception) {
9398 log("Fail to notify onAuthenticationFailure due to " + exception);
9399 }
9400 return;
9401 }
9402 }
9403
9404 final long token = Binder.clearCallingIdentity();
9405 try {
9406 getGbaManager(subId).bootstrapAuthenticationRequest(
9407 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9408 forceBootStrapping, callback));
9409 } finally {
9410 Binder.restoreCallingIdentity(token);
9411 }
9412 }
9413
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009414 /**
9415 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9416 * requested radio power state will actually be set. See {@link
9417 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9418 *
9419 * @param subId the subscription ID of the phone requesting to set the radio power state.
9420 * @param enable {@code true} if trying to turn radio on.
9421 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9422 * false}.
9423 */
9424 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9425 Phone phone = getPhone(subId);
9426 if (phone != null) {
9427 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9428 return true;
9429 }
9430 return false;
9431 }
9432
9433 private int handleDataThrottlingRequest(int subId,
9434 DataThrottlingRequest dataThrottlingRequest) {
9435 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9436 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9437 if (!setRadioPowerForThermal(subId, true)) {
9438 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9439 }
9440
9441 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9442
9443 int thermalMitigationResult =
9444 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9445 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9446 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9447 }
9448 return thermalMitigationResult;
9449 }
9450
9451 /**
9452 * Thermal mitigation request to control functionalities at modem.
9453 *
9454 * @param subId the id of the subscription.
9455 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9456 *
9457 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9458 */
9459 @Override
9460 @ThermalMitigationResult
9461 public int sendThermalMitigationRequest(
9462 int subId,
9463 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9464 enforceModifyPermission();
9465
9466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9467 final long identity = Binder.clearCallingIdentity();
9468
9469 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9470 try {
9471 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9472 switch (thermalMitigationAction) {
9473 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9474 thermalMitigationResult =
9475 handleDataThrottlingRequest(subId,
9476 thermalMitigationRequest.getDataThrottlingRequest());
9477 break;
9478 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9479 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9480 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9481 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9482 }
9483
9484 // Ensure that radio is on. If not able to power on due to phone being
9485 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9486 if (!setRadioPowerForThermal(subId, true)) {
9487 thermalMitigationResult =
9488 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9489 break;
9490 }
9491
9492 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9493 false);
9494 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9495 break;
9496 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9497 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9498 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9499 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9500 }
9501
9502 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9503 if (registry != null) {
9504 TelephonyConnectionService service =
9505 registry.getTelephonyConnectionService();
9506 Phone phone = getPhone(subId);
9507 if (phone == null) {
9508 thermalMitigationResult =
9509 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9510 break;
9511 }
9512
9513 if (PhoneConstantConversions.convertCallState(phone.getState())
9514 != TelephonyManager.CALL_STATE_IDLE
9515 || phone.isInEmergencySmsMode() || phone.isInEcm()
9516 || (service != null && service.isEmergencyCallPending())) {
9517 String errorMessage = "Phone state is not valid. call state = "
9518 + PhoneConstantConversions.convertCallState(phone.getState())
9519 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9520 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9521 errorMessage += service == null
9522 ? " TelephonyConnectionService is null"
9523 : " isEmergencyCallPending = "
9524 + service.isEmergencyCallPending();
9525 Log.e(LOG_TAG, errorMessage);
9526 thermalMitigationResult =
9527 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9528 break;
9529 }
9530 } else {
9531 thermalMitigationResult =
9532 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9533 break;
9534 }
9535
9536 // Turn radio off. If not able to power off due to phone being unavailable,
9537 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9538 if (!setRadioPowerForThermal(subId, false)) {
9539 thermalMitigationResult =
9540 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9541 break;
9542 }
9543 thermalMitigationResult =
9544 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9545 break;
9546 default:
9547 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9548 + "not exist. Requested action: " + thermalMitigationAction);
9549 }
9550 } catch (IllegalArgumentException e) {
9551 throw e;
9552 } catch (Exception e) {
9553 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9554 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558
9559 if (DBG) {
9560 log("thermalMitigationRequest returning with thermalMitigationResult: "
9561 + thermalMitigationResult);
9562 }
9563
9564 return thermalMitigationResult;
9565 }
Hui Wang641e81c2020-10-12 12:14:23 -07009566
9567 /**
9568 * Set the GbaService Package Name that Telephony will bind to.
9569 *
9570 * @param subId The sim that the GbaService is associated with.
9571 * @param packageName The name of the package to be replaced with.
9572 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9573 */
9574 @Override
9575 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9576 enforceModifyPermission();
9577
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
9580 return getGbaManager(subId).overrideServicePackage(packageName);
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
9583 }
9584 }
9585
9586 /**
9587 * Return the package name of the currently bound GbaService.
9588 *
9589 * @param subId The sim that the GbaService is associated with.
9590 * @return the package name of the GbaService configuration, null if GBA is not supported.
9591 */
9592 @Override
9593 public String getBoundGbaService(int subId) {
9594 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9595
9596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 return getGbaManager(subId).getServicePackage();
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
9603
9604 /**
9605 * Set the release time for telephony to unbind GbaService.
9606 *
9607 * @param subId The sim that the GbaService is associated with.
9608 * @param interval The release time to unbind GbaService by millisecond.
9609 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9610 */
9611 @Override
9612 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9613 enforceModifyPermission();
9614
9615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 return getGbaManager(subId).overrideReleaseTime(interval);
9618 } finally {
9619 Binder.restoreCallingIdentity(identity);
9620 }
9621 }
9622
9623 /**
9624 * Return the release time for telephony to unbind GbaService.
9625 *
9626 * @param subId The sim that the GbaService is associated with.
9627 * @return The release time to unbind GbaService by millisecond.
9628 */
9629 @Override
9630 public int getGbaReleaseTime(int subId) {
9631 enforceReadPrivilegedPermission("getGbaReleaseTime");
9632
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
9635 return getGbaManager(subId).getReleaseTime();
9636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
9640
9641 private GbaManager getGbaManager(int subId) {
9642 GbaManager instance = GbaManager.getInstance(subId);
9643 if (instance == null) {
9644 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9645 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9646 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9647 }
9648 return instance;
9649 }
Hui Wang761a6682020-10-31 05:12:53 +00009650
9651 /**
9652 * indicate whether the device and the carrier can support
9653 * RCS VoLTE single registration.
9654 */
9655 @Override
9656 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9657 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9658
9659 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9660 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9661 }
9662
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
9665 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9666 if (rpm != null) {
9667 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9668 }
9669 return false;
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
9675 /**
9676 * Register RCS provisioning callback.
9677 */
9678 @Override
9679 public void registerRcsProvisioningChangedCallback(int subId,
9680 IRcsConfigCallback callback) {
9681 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9682
9683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9684 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9685 }
9686 if (!isImsAvailableOnDevice()) {
9687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9688 "IMS not available on device.");
9689 }
9690
9691 final long identity = Binder.clearCallingIdentity();
9692 try {
9693 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9694 .addRcsProvisioningCallbackForSubscription(callback, subId);
9695 } catch (ImsException e) {
9696 throw new ServiceSpecificException(e.getCode());
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
9702 /**
9703 * Unregister RCS provisioning callback.
9704 */
9705 @Override
9706 public void unregisterRcsProvisioningChangedCallback(int subId,
9707 IRcsConfigCallback callback) {
9708 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9709
9710 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9711 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9712 }
9713 if (!isImsAvailableOnDevice()) {
9714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9715 "IMS not available on device.");
9716 }
9717
9718 final long identity = Binder.clearCallingIdentity();
9719 try {
9720 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9721 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9722 } catch (ImsException e) {
9723 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9724 + "is inactive, ignoring unregister.");
9725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
9729
9730 /**
9731 * trigger RCS reconfiguration.
9732 */
9733 public void triggerRcsReconfiguration(int subId) {
9734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9735 mApp, subId, "triggerRcsReconfiguration");
9736
9737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9739 }
9740 if (!isImsAvailableOnDevice()) {
9741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9742 "IMS not available on device.");
9743 }
9744
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 /**
9754 * Provide the client configuration parameters of the RCS application.
9755 */
9756 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9758 mApp, subId, "setRcsClientConfiguration");
9759
9760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9761 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9762 }
9763 if (!isImsAvailableOnDevice()) {
9764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9765 "IMS not available on device.");
9766 }
9767
9768 final long identity = Binder.clearCallingIdentity();
9769
9770 try {
9771 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9772 if (configBinder == null) {
9773 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9774 } else {
9775 configBinder.setRcsClientConfiguration(rcc);
9776 }
9777 } catch (RemoteException e) {
9778 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 /**
9785 * Overrides the config of RCS VoLTE single registration enabled for the device.
9786 */
9787 @Override
9788 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9790 "setDeviceSingleRegistrationEnabledOverride");
9791 enforceModifyPermission();
9792
9793 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9794 : Boolean.parseBoolean(enabledStr);
9795 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9796 }
9797
9798 /**
9799 * Gets the config of RCS VoLTE single registration enabled for the device.
9800 */
9801 @Override
9802 public boolean getDeviceSingleRegistrationEnabled() {
9803 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9804 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9805 }
9806
9807 /**
9808 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9809 */
9810 @Override
9811 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9813 "setCarrierSingleRegistrationEnabledOverride");
9814 enforceModifyPermission();
9815
9816 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9817 : Boolean.parseBoolean(enabledStr);
9818 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9819 subId, enabled);
9820 }
9821
9822 /**
9823 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9824 */
9825 @Override
9826 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9827 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9828 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9829 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009830
9831 /**
9832 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9833 * their mobile plan.
9834 */
9835 @Override
9836 public String getMobileProvisioningUrl() {
9837 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9838 final long identity = Binder.clearCallingIdentity();
9839 try {
9840 return getDefaultPhone().getMobileProvisioningUrl();
9841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009845}