blob: 3de9e22799a82d023b2ca7888a5310a365f44856 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080029import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080067import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080091import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800134import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700136import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700137import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800138import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700143import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800144import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800145import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700146import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800148import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700152import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700155import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800156import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700157import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700158import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700159import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700160import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700161import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700162import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700163import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800165import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800166import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700168import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700170import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800171import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700172import com.android.internal.telephony.imsphone.ImsPhone;
173import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800174import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700175import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800177import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700180import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800185import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700186import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700187import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800191import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700193import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800194import com.android.services.telephony.TelecomAccountRegistry;
195import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800196import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800197
Hall Liu82694d52020-12-11 18:22:04 -0800198import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700199import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800200import java.io.IOException;
201import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700202import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800205import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800206import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800207import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100208import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800209import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700210import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800212import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.util.UUID;
214import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800215import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800216import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
218/**
219 * Implementation of the ITelephony interface.
220 */
Santos Cordon117fee72014-05-16 17:56:12 -0700221public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 private static final String LOG_TAG = "PhoneInterfaceManager";
223 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
224 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800225 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
227 // Message codes used with mMainThreadHandler
228 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700229 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
230 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700231 private static final int CMD_OPEN_CHANNEL = 9;
232 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
233 private static final int CMD_CLOSE_CHANNEL = 11;
234 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800235 private static final int CMD_NV_READ_ITEM = 13;
236 private static final int EVENT_NV_READ_ITEM_DONE = 14;
237 private static final int CMD_NV_WRITE_ITEM = 15;
238 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
239 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
240 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700241 private static final int CMD_RESET_MODEM_CONFIG = 19;
242 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800243 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
244 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
245 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
246 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800247 private static final int CMD_SEND_ENVELOPE = 25;
248 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000249 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
250 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700251 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
252 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
253 private static final int CMD_EXCHANGE_SIM_IO = 31;
254 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800255 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
256 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700257 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700259 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
260 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700261 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
262 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
263 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
264 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700265 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
266 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
267 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
268 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700269 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800270 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
271 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000272 private static final int CMD_SWITCH_SLOTS = 50;
273 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700274 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
275 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
276 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
277 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
278 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
279 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
280 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
281 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700282 private static final int CMD_GET_ALL_CELL_INFO = 60;
283 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
284 private static final int CMD_GET_CELL_LOCATION = 62;
285 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700286 private static final int CMD_MODEM_REBOOT = 64;
287 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700288 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
289 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800290 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
291 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700292 private static final int CMD_GET_MODEM_STATUS = 70;
293 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700294 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
295 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700296 private static final int CMD_ERASE_MODEM_CONFIG = 74;
297 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800298 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
299 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
300 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
301 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800302 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
303 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800304 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800305 private static final int CMD_GET_CALL_FORWARDING = 83;
306 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
307 private static final int CMD_SET_CALL_FORWARDING = 85;
308 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
309 private static final int CMD_GET_CALL_WAITING = 87;
310 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
311 private static final int CMD_SET_CALL_WAITING = 89;
312 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700313 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
314 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
315 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
316 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700317 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
318 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800319 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
320 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800321 private static final int CMD_SET_DATA_THROTTLING = 99;
322 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800323 private static final int CMD_SET_SIM_POWER = 101;
324 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800325 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
326 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
327 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
328 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800330 // Parameters of select command.
331 private static final int SELECT_COMMAND = 0xA4;
332 private static final int SELECT_P1 = 0x04;
333 private static final int SELECT_P2 = 0;
334 private static final int SELECT_P3 = 0x10;
335
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 /** The singleton instance. */
337 private static PhoneInterfaceManager sInstance;
338
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800341 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700342 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private AppOpsManager mAppOps;
344 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800345 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700347 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Peter Wangdafb9ac2020-01-15 14:13:38 -0800349 /** User Activity */
350 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
352
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700353 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
354
Derek Tan97ebb422014-09-05 16:55:38 -0700355 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
356 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800357 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800358 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700359
Michelecea4cf22018-12-21 15:00:11 -0800360 // String to store multi SIM allowed
361 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
362
Derek Tan740e1672017-06-27 14:56:27 -0700363 // The AID of ISD-R.
364 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
365
yinxub1bed742017-04-17 11:45:04 -0700366 private NetworkScanRequestTracker mNetworkScanRequestTracker;
367
David Kelly5e06a7f2018-03-12 14:10:59 +0000368 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
369 private static final int MANUFACTURER_CODE_LENGTH = 8;
370
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800371 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
372
Derek Tan89e89d42014-07-08 17:00:10 -0700373 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700374 * Experiment flag to enable erase modem config on reset network, default value is false
375 */
376 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
377 "reset_network_erase_modem_config_enabled";
378
379 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700380 * A request object to use for transmitting data to an ICC.
381 */
382 private static final class IccAPDUArgument {
383 public int channel, cla, command, p1, p2, p3;
384 public String data;
385
386 public IccAPDUArgument(int channel, int cla, int command,
387 int p1, int p2, int p3, String data) {
388 this.channel = channel;
389 this.cla = cla;
390 this.command = command;
391 this.p1 = p1;
392 this.p2 = p2;
393 this.p3 = p3;
394 this.data = data;
395 }
396 }
397
398 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700399 * A request object to use for transmitting data to an ICC.
400 */
401 private static final class ManualNetworkSelectionArgument {
402 public OperatorInfo operatorInfo;
403 public boolean persistSelection;
404
405 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
406 this.operatorInfo = operatorInfo;
407 this.persistSelection = persistSelection;
408 }
409 }
410
411 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
413 * request after sending. The main thread will notify the request when it is complete.
414 */
415 private static final class MainThreadRequest {
416 /** The argument to use for the request */
417 public Object argument;
418 /** The result of the request that is run on the main thread */
419 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800420 // The subscriber id that this request applies to. Defaults to
421 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
422 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Nathan Harold92bed182018-10-12 18:16:49 -0700424 // In cases where subId is unavailable, the caller needs to specify the phone.
425 public Phone phone;
426
vagdeviaf9a5b92018-08-15 16:01:53 -0700427 public WorkSource workSource;
428
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 public MainThreadRequest(Object argument) {
430 this.argument = argument;
431 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800432
Nathan Harold92bed182018-10-12 18:16:49 -0700433 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
434 this.argument = argument;
435 if (phone != null) {
436 this.phone = phone;
437 }
438 this.workSource = workSource;
439 }
440
vagdeviaf9a5b92018-08-15 16:01:53 -0700441 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800442 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800443 if (subId != null) {
444 this.subId = subId;
445 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700446 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 }
449
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800450 private static final class IncomingThirdPartyCallArgs {
451 public final ComponentName component;
452 public final String callId;
453 public final String callerDisplayName;
454
455 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
456 String callerDisplayName) {
457 this.component = component;
458 this.callId = callId;
459 this.callerDisplayName = callerDisplayName;
460 }
461 }
462
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 /**
464 * A handler that processes messages on the main thread in the phone process. Since many
465 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
466 * inbound binder threads to the main thread in the phone process. The Binder thread
467 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
468 * on, which will be notified when the operation completes and will contain the result of the
469 * request.
470 *
471 * <p>If a MainThreadRequest object is provided in the msg.obj field,
472 * note that request.result must be set to something non-null for the calling thread to
473 * unblock.
474 */
475 private final class MainThreadHandler extends Handler {
476 @Override
477 public void handleMessage(Message msg) {
478 MainThreadRequest request;
479 Message onCompleted;
480 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800483 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484
485 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 case CMD_HANDLE_USSD_REQUEST: {
487 request = (MainThreadRequest) msg.obj;
488 final Phone phone = getPhoneFromRequest(request);
489 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
490 String ussdRequest = ussdObject.first;
491 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700492
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 if (!isUssdApiAllowed(request.subId)) {
494 // Carrier does not support use of this API, return failure.
495 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
496 UssdResponse response = new UssdResponse(ussdRequest, null);
497 Bundle returnData = new Bundle();
498 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
499 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700500
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 request.result = true;
502 notifyRequester(request);
503 return;
504 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700505
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 try {
507 request.result = phone != null
508 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
509 } catch (CallStateException cse) {
510 request.result = false;
511 }
512 // Wake up the requesting thread
513 notifyRequester(request);
514 break;
pkanwar32d516d2016-10-14 19:37:38 -0700515 }
516
Yorke Lee716f67e2015-06-17 15:39:16 -0700517 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700518 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 final Phone phone = getPhoneFromRequest(request);
520 request.result = phone != null ?
521 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
522 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("iccTransmitApduLogicalChannel: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
538 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 iccArgument.channel, iccArgument.cla, iccArgument.command,
541 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 break;
545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 ar = (AsyncResult) msg.obj;
548 request = (MainThreadRequest) ar.userObj;
549 if (ar.exception == null && ar.result != null) {
550 request.result = ar.result;
551 } else {
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 if (ar.result == null) {
554 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800555 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800557 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 } else {
559 loge("iccTransmitApduLogicalChannel: Unknown exception");
560 }
561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
566 request = (MainThreadRequest) msg.obj;
567 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 if (uiccCard == null) {
570 loge("iccTransmitApduBasicChannel: No UICC");
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 } else {
574 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
575 request);
576 uiccCard.iccTransmitApduBasicChannel(
577 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
578 iccArgument.p3, iccArgument.data, onCompleted);
579 }
580 break;
581
582 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
583 ar = (AsyncResult) msg.obj;
584 request = (MainThreadRequest) ar.userObj;
585 if (ar.exception == null && ar.result != null) {
586 request.result = ar.result;
587 } else {
588 request.result = new IccIoResult(0x6F, 0, (byte[])null);
589 if (ar.result == null) {
590 loge("iccTransmitApduBasicChannel: Empty response");
591 } else if (ar.exception instanceof CommandException) {
592 loge("iccTransmitApduBasicChannel: CommandException: " +
593 ar.exception);
594 } else {
595 loge("iccTransmitApduBasicChannel: Unknown exception");
596 }
597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 break;
600
601 case CMD_EXCHANGE_SIM_IO:
602 request = (MainThreadRequest) msg.obj;
603 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800604 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 if (uiccCard == null) {
606 loge("iccExchangeSimIO: No UICC");
607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 } else {
610 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
611 request);
612 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
613 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
614 iccArgument.data, onCompleted);
615 }
616 break;
617
618 case EVENT_EXCHANGE_SIM_IO_DONE:
619 ar = (AsyncResult) msg.obj;
620 request = (MainThreadRequest) ar.userObj;
621 if (ar.exception == null && ar.result != null) {
622 request.result = ar.result;
623 } else {
624 request.result = new IccIoResult(0x6f, 0, (byte[])null);
625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 break;
628
Derek Tan4d5e5c12014-02-04 11:54:58 -0800629 case CMD_SEND_ENVELOPE:
630 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800631 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 if (uiccCard == null) {
633 loge("sendEnvelopeWithStatus: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
638 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
639 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 break;
641
642 case EVENT_SEND_ENVELOPE_DONE:
643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700648 request.result = new IccIoResult(0x6F, 0, (byte[])null);
649 if (ar.result == null) {
650 loge("sendEnvelopeWithStatus: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("sendEnvelopeWithStatus: CommandException: " +
653 ar.exception);
654 } else {
655 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
656 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 break;
660
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 case CMD_OPEN_CHANNEL:
662 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800663 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800664 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700665 if (uiccCard == null) {
666 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800667 request.result = new IccOpenLogicalChannelResponse(-1,
668 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800672 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
673 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case EVENT_OPEN_CHANNEL_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 int[] result = (int[]) ar.result;
683 int channelId = result[0];
684 byte[] selectResponse = null;
685 if (result.length > 1) {
686 selectResponse = new byte[result.length - 1];
687 for (int i = 1; i < result.length; ++i) {
688 selectResponse[i - 1] = (byte) result[i];
689 }
690 }
691 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 if (ar.result == null) {
695 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.exception != null) {
698 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
699 }
700
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700701 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700702 if (ar.exception instanceof CommandException) {
703 CommandException.Error error =
704 ((CommandException) (ar.exception)).getCommandError();
705 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700706 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700707 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 }
710 }
711 openChannelResp = new IccOpenLogicalChannelResponse(
712 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700714 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 break;
717
718 case CMD_CLOSE_CHANNEL:
719 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800720 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 if (uiccCard == null) {
722 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900723 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 } else {
726 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
727 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
728 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 break;
730
731 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800732 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
733 break;
734
735 case CMD_NV_READ_ITEM:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800738 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
739 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
742 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 ar = (AsyncResult) msg.obj;
744 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800745 if (ar.exception == null && ar.result != null) {
746 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800748 request.result = "";
749 if (ar.result == null) {
750 loge("nvReadItem: Empty response");
751 } else if (ar.exception instanceof CommandException) {
752 loge("nvReadItem: CommandException: " +
753 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800755 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 }
757 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 break;
760
Jake Hambye994d462014-02-03 13:10:13 -0800761 case CMD_NV_WRITE_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
764 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_WRITE_ITEM_DONE:
770 handleNullReturnEvent(msg, "nvWriteItem");
771 break;
772
773 case CMD_NV_WRITE_CDMA_PRL:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800776 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800777 break;
778
779 case EVENT_NV_WRITE_CDMA_PRL_DONE:
780 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
781 break;
782
chen xu6dac5ab2018-10-26 17:39:23 -0700783 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800784 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700785 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
chen xu6dac5ab2018-10-26 17:39:23 -0700789 case EVENT_RESET_MODEM_CONFIG_DONE:
790 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800791 break;
792
Sooraj Sasindran37444802020-08-11 10:40:43 -0700793 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
794 request = (MainThreadRequest) msg.obj;
795 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
796 request);
797 Phone phone = getPhoneFromRequest(request);
798 if (phone != null) {
799 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
800 } else {
801 loge("isNRDualConnectivityEnabled: No phone object");
802 request.result = false;
803 notifyRequester(request);
804 }
805 break;
806 }
807
808 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
811 if (ar.exception == null && ar.result != null) {
812 request.result = ar.result;
813 } else {
814 // request.result must be set to something non-null
815 // for the calling thread to unblock
816 if (request.result != null) {
817 request.result = ar.result;
818 } else {
819 request.result = false;
820 }
821 if (ar.result == null) {
822 loge("isNRDualConnectivityEnabled: Empty response");
823 } else if (ar.exception instanceof CommandException) {
824 loge("isNRDualConnectivityEnabled: CommandException: "
825 + ar.exception);
826 } else {
827 loge("isNRDualConnectivityEnabled: Unknown exception");
828 }
829 }
830 notifyRequester(request);
831 break;
832
833 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
836 Phone phone = getPhoneFromRequest(request);
837 if (phone != null) {
838 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
839 request.workSource);
840 } else {
841 loge("enableNrDualConnectivity: No phone object");
842 request.result =
843 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
844 notifyRequester(request);
845 }
846 break;
847 }
848
849 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null) {
853 request.result =
854 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
855 } else {
856 request.result =
857 TelephonyManager
858 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
859 if (ar.exception instanceof CommandException) {
860 CommandException.Error error =
861 ((CommandException) (ar.exception)).getCommandError();
862 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
863 request.result =
864 TelephonyManager
865 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
866 }
867 loge("enableNrDualConnectivity" + ": CommandException: "
868 + ar.exception);
869 } else {
870 loge("enableNrDualConnectivity" + ": Unknown exception");
871 }
872 }
873 notifyRequester(request);
874 break;
875 }
876
Jake Hamby7c27be32014-03-03 13:25:59 -0800877 case CMD_GET_PREFERRED_NETWORK_TYPE:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700880 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800881 break;
882
883 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result; // Integer
888 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530889 // request.result must be set to something non-null
890 // for the calling thread to unblock
891 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800892 if (ar.result == null) {
893 loge("getPreferredNetworkType: Empty response");
894 } else if (ar.exception instanceof CommandException) {
895 loge("getPreferredNetworkType: CommandException: " +
896 ar.exception);
897 } else {
898 loge("getPreferredNetworkType: Unknown exception");
899 }
900 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 break;
903
904 case CMD_SET_PREFERRED_NETWORK_TYPE:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
907 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700908 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 break;
910
911 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
912 handleNullReturnEvent(msg, "setPreferredNetworkType");
913 break;
914
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000915 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
916 request = (MainThreadRequest)msg.obj;
917 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000919 break;
920
921 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
922 ar = (AsyncResult)msg.obj;
923 request = (MainThreadRequest)ar.userObj;
924 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000926 break;
927
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800928 case CMD_SET_VOICEMAIL_NUMBER:
929 request = (MainThreadRequest) msg.obj;
930 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
931 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800932 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
933 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800934 break;
935
936 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
937 handleNullReturnEvent(msg, "setVoicemailNumber");
938 break;
939
Stuart Scott54788802015-03-30 13:18:01 -0700940 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
943 request);
944 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
945 break;
946
947 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
948 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
949 break;
950
Shishir Agrawal302c8692015-06-19 13:49:39 -0700951 case CMD_PERFORM_NETWORK_SCAN:
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
954 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
955 break;
956
Hall Liu27d24262020-09-18 19:04:59 -0700957 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700960 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
961 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
962 request.argument;
963 int callForwardingReason = args.first;
964 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800965 break;
Hall Liu27d24262020-09-18 19:04:59 -0700966 }
967 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700970 TelephonyManager.CallForwardingInfoCallback callback =
971 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
972 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800973 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700974 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800975 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
976 for (CallForwardInfo callForwardInfo : callForwardInfos) {
977 // Service Class is a bit mask per 3gpp 27.007. Search for
978 // any service for voice call.
979 if ((callForwardInfo.serviceClass
980 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700981 callForwardingInfo = new CallForwardingInfo(true,
982 callForwardInfo.reason,
983 callForwardInfo.number,
984 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800985 break;
986 }
987 }
988 // Didn't find a call forward info for voice call.
989 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700990 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
991 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800992 }
Hall Liu27d24262020-09-18 19:04:59 -0700993 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800994 } else {
995 if (ar.result == null) {
996 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
997 }
998 if (ar.exception != null) {
999 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1000 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001001 int errorCode = TelephonyManager
1002 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 if (ar.exception instanceof CommandException) {
1004 CommandException.Error error =
1005 ((CommandException) (ar.exception)).getCommandError();
1006 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001007 errorCode = TelephonyManager
1008 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001009 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001010 errorCode = TelephonyManager
1011 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001012 }
1013 }
Hall Liu27d24262020-09-18 19:04:59 -07001014 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001015 }
Shuo Qian4a594052020-01-23 11:59:30 -08001016 break;
Hall Liu27d24262020-09-18 19:04:59 -07001017 }
Shuo Qian4a594052020-01-23 11:59:30 -08001018
Hall Liu27d24262020-09-18 19:04:59 -07001019 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001022 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001023 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001024 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1025 request.argument).first;
1026 request.phone.setCallForwardingOption(
1027 callForwardingInfoToSet.isEnabled()
1028 ? CommandsInterface.CF_ACTION_ENABLE
1029 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001030 callForwardingInfoToSet.getReason(),
1031 callForwardingInfoToSet.getNumber(),
1032 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1033 break;
Hall Liu27d24262020-09-18 19:04:59 -07001034 }
Shuo Qian4a594052020-01-23 11:59:30 -08001035
Hall Liu27d24262020-09-18 19:04:59 -07001036 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001039 Consumer<Integer> callback =
1040 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1041 request.argument).second;
1042 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001043 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001044 int errorCode = TelephonyManager.CallForwardingInfoCallback
1045 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001046 if (ar.exception instanceof CommandException) {
1047 CommandException.Error error =
1048 ((CommandException) (ar.exception)).getCommandError();
1049 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001050 errorCode = TelephonyManager.CallForwardingInfoCallback
1051 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001052 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001053 errorCode = TelephonyManager.CallForwardingInfoCallback
1054 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001055 }
1056 }
1057 callback.accept(errorCode);
1058 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001059 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001060 }
Shuo Qian4a594052020-01-23 11:59:30 -08001061 break;
Hall Liu27d24262020-09-18 19:04:59 -07001062 }
Shuo Qian4a594052020-01-23 11:59:30 -08001063
Hall Liu27d24262020-09-18 19:04:59 -07001064 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001065 request = (MainThreadRequest) msg.obj;
1066 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1067 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1068 break;
Hall Liu27d24262020-09-18 19:04:59 -07001069 }
Shuo Qian4a594052020-01-23 11:59:30 -08001070
Hall Liu27d24262020-09-18 19:04:59 -07001071 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001074 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001075 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1076 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001077 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001078 // Service Class is a bit mask per 3gpp 27.007.
1079 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001080 if (callForwardResults.length > 1
1081 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001082 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001083 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001084 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1085 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001086 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001087 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001088 }
1089 } else {
1090 if (ar.result == null) {
1091 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1092 }
1093 if (ar.exception != null) {
1094 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1095 }
1096 if (ar.exception instanceof CommandException) {
1097 CommandException.Error error =
1098 ((CommandException) (ar.exception)).getCommandError();
1099 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1100 callForwardingStatus =
1101 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1102 }
1103 }
1104 }
Hall Liu27d24262020-09-18 19:04:59 -07001105 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001106 break;
Hall Liu27d24262020-09-18 19:04:59 -07001107 }
Shuo Qian4a594052020-01-23 11:59:30 -08001108
Hall Liu27d24262020-09-18 19:04:59 -07001109 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001110 request = (MainThreadRequest) msg.obj;
1111 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001112 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1113 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 break;
Hall Liu27d24262020-09-18 19:04:59 -07001115 }
Shuo Qian4a594052020-01-23 11:59:30 -08001116
Hall Liu27d24262020-09-18 19:04:59 -07001117 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001118 ar = (AsyncResult) msg.obj;
1119 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001120 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1121 Consumer<Integer> callback =
1122 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1123 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001124 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1129 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1130 } else {
1131 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1132 }
1133 } else {
1134 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1135 }
1136 } else {
1137 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1138 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001139 }
Shuo Qian4a594052020-01-23 11:59:30 -08001140 break;
Hall Liu27d24262020-09-18 19:04:59 -07001141 }
Shuo Qian4a594052020-01-23 11:59:30 -08001142
Shishir Agrawal302c8692015-06-19 13:49:39 -07001143 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 CellNetworkScanResult cellScanResult;
1147 if (ar.exception == null && ar.result != null) {
1148 cellScanResult = new CellNetworkScanResult(
1149 CellNetworkScanResult.STATUS_SUCCESS,
1150 (List<OperatorInfo>) ar.result);
1151 } else {
1152 if (ar.result == null) {
1153 loge("getCellNetworkScanResults: Empty response");
1154 }
1155 if (ar.exception != null) {
1156 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1157 }
1158 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1159 if (ar.exception instanceof CommandException) {
1160 CommandException.Error error =
1161 ((CommandException) (ar.exception)).getCommandError();
1162 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1163 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1164 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1165 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1166 }
1167 }
1168 cellScanResult = new CellNetworkScanResult(errorCode, null);
1169 }
1170 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001172 break;
1173
1174 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1175 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001176 ManualNetworkSelectionArgument selArg =
1177 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001178 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1179 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001180 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1181 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 break;
1183
1184 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001185 ar = (AsyncResult) msg.obj;
1186 request = (MainThreadRequest) ar.userObj;
1187 if (ar.exception == null) {
1188 request.result = true;
1189 } else {
1190 request.result = false;
1191 loge("setNetworkSelectionModeManual " + ar.exception);
1192 }
1193 notifyRequester(request);
1194 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 break;
1196
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001197 case CMD_GET_MODEM_ACTIVITY_INFO:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001200 if (defaultPhone != null) {
1201 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001202 } else {
1203 ResultReceiver result = (ResultReceiver) request.argument;
1204 Bundle bundle = new Bundle();
1205 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001206 new ModemActivityInfo(0, 0, 0,
1207 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001208 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001209 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001210 break;
1211
Hall Liud0f208c2020-10-14 16:54:44 -07001212 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001215 ResultReceiver result = (ResultReceiver) request.argument;
1216
Hall Liud0f208c2020-10-14 16:54:44 -07001217 ModemActivityInfo ret = null;
1218 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001220 // Update the last modem activity info and the result of the request.
1221 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1222 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001223 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001224 int[] txTimeMs = info.getTransmitTimeMillis();
1225 int[] lastModemTxTimeMs = mLastModemActivityInfo
1226 .getTransmitTimeMillis();
1227 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1228 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1229 }
Hall Liu49656c02020-10-09 19:00:11 -07001230 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001231 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1232 + mLastModemActivityInfo.getSleepTimeMillis());
1233 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1234 + mLastModemActivityInfo.getIdleTimeMillis());
1235 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1236 mLastModemActivityInfo.setReceiveTimeMillis(
1237 info.getReceiveTimeMillis()
1238 + mLastModemActivityInfo.getReceiveTimeMillis());
1239 }
Hall Liu49656c02020-10-09 19:00:11 -07001240 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001241 mLastModemActivityInfo.getSleepTimeMillis(),
1242 mLastModemActivityInfo.getIdleTimeMillis(),
1243 mLastModemActivityInfo.getTransmitTimeMillis(),
1244 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001245 } else {
1246 if (ar.result == null) {
1247 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001248 error = TelephonyManager.ModemActivityInfoException
1249 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001250 } else if (ar.exception instanceof CommandException) {
1251 loge("queryModemActivityInfo: CommandException: " +
1252 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001253 error = TelephonyManager.ModemActivityInfoException
1254 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001255 } else {
1256 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001257 error = TelephonyManager.ModemActivityInfoException
1258 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001259 }
1260 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001261 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001262 if (ret != null) {
1263 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1264 } else {
1265 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1266 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001267 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001268 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001269 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001270 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001271
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 case CMD_SET_ALLOWED_CARRIERS:
1273 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001274 CarrierRestrictionRules argument =
1275 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001277 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001278 break;
1279
1280 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
1283 if (ar.exception == null && ar.result != null) {
1284 request.result = ar.result;
1285 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001286 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1287 if (ar.exception instanceof CommandException) {
1288 loge("setAllowedCarriers: CommandException: " + ar.exception);
1289 CommandException.Error error =
1290 ((CommandException) (ar.exception)).getCommandError();
1291 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1292 request.result =
1293 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1294 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 } else {
1296 loge("setAllowedCarriers: Unknown exception");
1297 }
1298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001299 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 break;
1301
1302 case CMD_GET_ALLOWED_CARRIERS:
1303 request = (MainThreadRequest) msg.obj;
1304 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001305 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 break;
1307
1308 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null && ar.result != null) {
1312 request.result = ar.result;
1313 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001314 request.result = new IllegalStateException(
1315 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001316 if (ar.result == null) {
1317 loge("getAllowedCarriers: Empty response");
1318 } else if (ar.exception instanceof CommandException) {
1319 loge("getAllowedCarriers: CommandException: " +
1320 ar.exception);
1321 } else {
1322 loge("getAllowedCarriers: Unknown exception");
1323 }
1324 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001325 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001326 break;
1327
Nathan Haroldb3014052017-01-25 15:57:32 -08001328 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 if (ar.exception == null && ar.result != null) {
1332 request.result = ar.result;
1333 } else {
1334 request.result = new IllegalArgumentException(
1335 "Failed to retrieve Forbidden Plmns");
1336 if (ar.result == null) {
1337 loge("getForbiddenPlmns: Empty response");
1338 } else {
1339 loge("getForbiddenPlmns: Unknown exception");
1340 }
1341 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001342 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001343 break;
1344
1345 case CMD_GET_FORBIDDEN_PLMNS:
1346 request = (MainThreadRequest) msg.obj;
1347 uiccCard = getUiccCardFromRequest(request);
1348 if (uiccCard == null) {
1349 loge("getForbiddenPlmns() UiccCard is null");
1350 request.result = new IllegalArgumentException(
1351 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001353 break;
1354 }
1355 Integer appType = (Integer) request.argument;
1356 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1357 if (uiccApp == null) {
1358 loge("getForbiddenPlmns() no app with specified type -- "
1359 + appType);
1360 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001361 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001362 break;
1363 } else {
1364 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1365 + " specified type -- " + appType);
1366 }
1367 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1368 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1369 onCompleted);
1370 break;
1371
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001372 case CMD_SWITCH_SLOTS:
1373 request = (MainThreadRequest) msg.obj;
1374 int[] physicalSlots = (int[]) request.argument;
1375 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1376 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1377 break;
1378
1379 case EVENT_SWITCH_SLOTS_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001383 notifyRequester(request);
1384 break;
1385 case CMD_GET_NETWORK_SELECTION_MODE:
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1388 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1389 break;
1390
1391 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 if (ar.exception != null) {
1395 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1396 } else {
1397 int mode = ((int[]) ar.result)[0];
1398 if (mode == 0) {
1399 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1400 } else {
1401 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1402 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001403 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001404 notifyRequester(request);
1405 break;
1406 case CMD_GET_CDMA_ROAMING_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1409 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1410 break;
1411 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 if (ar.exception != null) {
1415 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1416 } else {
1417 request.result = ((int[]) ar.result)[0];
1418 }
1419 notifyRequester(request);
1420 break;
1421 case CMD_SET_CDMA_ROAMING_MODE:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1424 int mode = (int) request.argument;
1425 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1426 break;
1427 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 request.result = ar.exception == null;
1431 notifyRequester(request);
1432 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001433 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1436 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1437 break;
1438 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception != null) {
1442 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1443 } else {
1444 request.result = ((int[]) ar.result)[0];
1445 }
1446 notifyRequester(request);
1447 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001448 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1451 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001452 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1453 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 break;
1455 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 request.result = ar.exception == null;
1459 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001460 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 case CMD_GET_ALL_CELL_INFO:
1462 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001464 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 case EVENT_GET_ALL_CELL_INFO_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001469 // If a timeout occurs, the response will be null
1470 request.result = (ar.exception == null && ar.result != null)
1471 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001472 synchronized (request) {
1473 request.notifyAll();
1474 }
1475 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 case CMD_REQUEST_CELL_INFO_UPDATE:
1477 request = (MainThreadRequest) msg.obj;
1478 request.phone.requestCellInfoUpdate(request.workSource,
1479 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1480 break;
1481 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
1484 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1485 try {
1486 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001487 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001488 cb.onError(
1489 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1490 ar.exception.getClass().getName(),
1491 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001492 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001494 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001495 } else {
1496 // use the result as returned
1497 cb.onCellInfo((List<CellInfo>) ar.result);
1498 }
1499 } catch (RemoteException re) {
1500 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1501 }
1502 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001503 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 request = (MainThreadRequest) msg.obj;
1505 WorkSource ws = (WorkSource) request.argument;
1506 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001507 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001509 }
1510 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception == null) {
1514 request.result = ar.result;
1515 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001516 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001517 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001518 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001519 }
1520
1521 synchronized (request) {
1522 request.notifyAll();
1523 }
1524 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001525 }
chen xu6dac5ab2018-10-26 17:39:23 -07001526 case CMD_MODEM_REBOOT:
1527 request = (MainThreadRequest) msg.obj;
1528 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001529 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001530 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001531 case EVENT_CMD_MODEM_REBOOT_DONE:
1532 handleNullReturnEvent(msg, "rebootModem");
1533 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001534 case CMD_REQUEST_ENABLE_MODEM:
1535 request = (MainThreadRequest) msg.obj;
1536 boolean enable = (boolean) request.argument;
1537 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001538 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001539 PhoneConfigurationManager.getInstance()
1540 .enablePhone(request.phone, enable, onCompleted);
1541 break;
1542 case EVENT_ENABLE_MODEM_DONE:
1543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001546 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001547 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001548 if ((boolean) request.result) {
1549 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1550 updateModemStateMetrics();
1551 } else {
1552 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1553 + ar.exception);
1554 }
1555 notifyRequester(request);
1556 break;
1557 case CMD_GET_MODEM_STATUS:
1558 request = (MainThreadRequest) msg.obj;
1559 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1560 PhoneConfigurationManager.getInstance()
1561 .getPhoneStatusFromModem(request.phone, onCompleted);
1562 break;
1563 case EVENT_GET_MODEM_STATUS_DONE:
1564 ar = (AsyncResult) msg.obj;
1565 request = (MainThreadRequest) ar.userObj;
1566 int id = request.phone.getPhoneId();
1567 if (ar.exception == null && ar.result != null) {
1568 request.result = ar.result;
1569 //update the cache as modem status has changed
1570 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1571 (boolean) request.result);
1572 } else {
1573 // Return true if modem status cannot be retrieved. For most cases,
1574 // modem status is on. And for older version modems, GET_MODEM_STATUS
1575 // and disable modem are not supported. Modem is always on.
1576 // TODO: this should be fixed in R to support a third
1577 // status UNKNOWN b/131631629
1578 request.result = true;
1579 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1580 + ar.exception);
1581 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001582 notifyRequester(request);
1583 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001584 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1585 request = (MainThreadRequest) msg.obj;
1586 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1587 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1588 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1589 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1590 break;
1591 }
1592 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1593 ar = (AsyncResult) msg.obj;
1594 request = (MainThreadRequest) ar.userObj;
1595 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1596 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1597 args.second.accept(ar.exception == null);
1598 notifyRequester(request);
1599 break;
1600 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001601 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1602 request = (MainThreadRequest) msg.obj;
1603 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1604 Phone phone = getPhoneFromRequest(request);
1605 if (phone != null) {
1606 phone.getSystemSelectionChannels(onCompleted);
1607 } else {
1608 loge("getSystemSelectionChannels: No phone object");
1609 request.result = new ArrayList<RadioAccessSpecifier>();
1610 notifyRequester(request);
1611 }
1612 break;
1613 }
1614 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null && ar.result != null) {
1618 request.result = ar.result;
1619 } else {
1620 request.result = new IllegalArgumentException(
1621 "Failed to retrieve system selection channels");
1622 if (ar.result == null) {
1623 loge("getSystemSelectionChannels: Empty response");
1624 } else {
1625 loge("getSystemSelectionChannels: Unknown exception");
1626 }
1627 }
1628 notifyRequester(request);
1629 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001630 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null && ar.result != null) {
1634 request.result = ar.result;
1635 } else {
1636 request.result = -1;
1637 loge("Failed to set Forbidden Plmns");
1638 if (ar.result == null) {
1639 loge("setForbidenPlmns: Empty response");
1640 } else if (ar.exception != null) {
1641 loge("setForbiddenPlmns: Exception: " + ar.exception);
1642 request.result = -1;
1643 } else {
1644 loge("setForbiddenPlmns: Unknown exception");
1645 }
1646 }
1647 notifyRequester(request);
1648 break;
1649 case CMD_SET_FORBIDDEN_PLMNS:
1650 request = (MainThreadRequest) msg.obj;
1651 uiccCard = getUiccCardFromRequest(request);
1652 if (uiccCard == null) {
1653 loge("setForbiddenPlmns: UiccCard is null");
1654 request.result = -1;
1655 notifyRequester(request);
1656 break;
1657 }
1658 Pair<Integer, List<String>> setFplmnsArgs =
1659 (Pair<Integer, List<String>>) request.argument;
1660 appType = setFplmnsArgs.first;
1661 List<String> fplmns = setFplmnsArgs.second;
1662 uiccApp = uiccCard.getApplicationByType(appType);
1663 if (uiccApp == null) {
1664 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1665 request.result = -1;
1666 loge("Failed to get UICC App");
1667 notifyRequester(request);
1668 } else {
1669 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1670 ((SIMRecords) uiccApp.getIccRecords())
1671 .setForbiddenPlmns(onCompleted, fplmns);
1672 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001673 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001674 case CMD_ERASE_MODEM_CONFIG:
1675 request = (MainThreadRequest) msg.obj;
1676 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1677 defaultPhone.eraseModemConfig(onCompleted);
1678 break;
1679 case EVENT_ERASE_MODEM_CONFIG_DONE:
1680 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001681 break;
zoey chene02881a2019-12-30 16:11:23 +08001682
1683 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1686 Pair<String, String> changed = (Pair<String, String>) request.argument;
1687 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1688 changed.first, changed.second, onCompleted);
1689 break;
1690 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1691 ar = (AsyncResult) msg.obj;
1692 request = (MainThreadRequest) ar.userObj;
1693 if (ar.exception == null) {
1694 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1695 } else {
1696 request.result = msg.arg1;
1697 }
1698 notifyRequester(request);
1699 break;
1700
1701 case CMD_SET_ICC_LOCK_ENABLED:
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1704 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1705 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1706 enabled.first, enabled.second, onCompleted);
1707 break;
1708 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1713 } else {
1714 request.result = msg.arg1;
1715 }
1716 notifyRequester(request);
1717 break;
1718
Peter Wangdafb9ac2020-01-15 14:13:38 -08001719 case MSG_NOTIFY_USER_ACTIVITY:
1720 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001721 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001722 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1723 getDefaultPhone().getContext().sendBroadcastAsUser(
1724 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1725 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001726
1727 case CMD_SET_DATA_THROTTLING: {
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1730 DataThrottlingRequest dataThrottlingRequest =
1731 (DataThrottlingRequest) request.argument;
1732 Phone phone = getPhoneFromRequest(request);
1733 if (phone != null) {
1734 phone.setDataThrottling(onCompleted,
1735 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1736 dataThrottlingRequest.getCompletionDurationMillis());
1737 } else {
1738 loge("setDataThrottling: No phone object");
1739 request.result =
1740 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1741 notifyRequester(request);
1742 }
1743
1744 break;
1745 }
1746 case EVENT_SET_DATA_THROTTLING_DONE:
1747 ar = (AsyncResult) msg.obj;
1748 request = (MainThreadRequest) ar.userObj;
1749
1750 if (ar.exception == null) {
1751 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1752 } else if (ar.exception instanceof CommandException) {
1753 loge("setDataThrottling: CommandException: " + ar.exception);
1754 CommandException.Error error =
1755 ((CommandException) (ar.exception)).getCommandError();
1756
1757 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1758 request.result = TelephonyManager
1759 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1760 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1761 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1762 } else {
1763 request.result =
1764 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1765 }
1766 } else {
1767 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1768 }
1769 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1770 notifyRequester(request);
1771 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001772
1773 case CMD_SET_SIM_POWER: {
1774 request = (MainThreadRequest) msg.obj;
1775 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1776 request = (MainThreadRequest) msg.obj;
1777 int stateToSet =
1778 ((Pair<Integer, IIntegerConsumer>)
1779 request.argument).first;
1780 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1781 break;
1782 }
1783 case EVENT_SET_SIM_POWER_DONE: {
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 IIntegerConsumer callback =
1787 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1788 if (ar.exception != null) {
1789 loge("setSimPower exception: " + ar.exception);
1790 int errorCode = TelephonyManager.CallForwardingInfoCallback
1791 .RESULT_ERROR_UNKNOWN;
1792 if (ar.exception instanceof CommandException) {
1793 CommandException.Error error =
1794 ((CommandException) (ar.exception)).getCommandError();
1795 if (error == CommandException.Error.SIM_ERR) {
1796 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1797 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1798 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1799 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1800 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1801 } else {
1802 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1803 }
1804 }
1805 try {
1806 callback.accept(errorCode);
1807 } catch (RemoteException e) {
1808 // Ignore if the remote process is no longer available to call back.
1809 Log.w(LOG_TAG, "setSimPower: callback not available.");
1810 }
1811 } else {
1812 try {
1813 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1814 } catch (RemoteException e) {
1815 // Ignore if the remote process is no longer available to call back.
1816 Log.w(LOG_TAG, "setSimPower: callback not available.");
1817 }
1818 }
1819 break;
1820 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001821 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1822 request = (MainThreadRequest) msg.obj;
1823
1824 final Phone phone = getPhoneFromRequest(request);
1825 if (phone == null || phone.getServiceStateTracker() == null) {
1826 request.result = new IllegalStateException("Phone or SST is null");
1827 notifyRequester(request);
1828 break;
1829 }
1830
1831 Pair<Integer, SignalStrengthUpdateRequest> pair =
1832 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1833 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1834 request);
1835 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1836 request.subId, pair.first /*callingUid*/,
1837 pair.second /*request*/, onCompleted);
1838 break;
1839 }
1840 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 // request.result will be the exception of ar if present, true otherwise.
1844 // Be cautious not to leave result null which will wait() forever
1845 request.result = ar.exception != null ? ar.exception : true;
1846 notifyRequester(request);
1847 break;
1848 }
1849 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1850 request = (MainThreadRequest) msg.obj;
1851
1852 Phone phone = getPhoneFromRequest(request);
1853 if (phone == null || phone.getServiceStateTracker() == null) {
1854 request.result = new IllegalStateException("Phone or SST is null");
1855 notifyRequester(request);
1856 break;
1857 }
1858
1859 Pair<Integer, SignalStrengthUpdateRequest> pair =
1860 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1861 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1862 request);
1863 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1864 request.subId, pair.first /*callingUid*/,
1865 pair.second /*request*/, onCompleted);
1866 break;
1867 }
1868 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1869 ar = (AsyncResult) msg.obj;
1870 request = (MainThreadRequest) ar.userObj;
1871 request.result = ar.exception != null ? ar.exception : true;
1872 notifyRequester(request);
1873 break;
1874 }
Jordan Liu109698e2020-11-24 14:50:34 -08001875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 default:
1877 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1878 break;
1879 }
1880 }
Jake Hambye994d462014-02-03 13:10:13 -08001881
Pengquan Menga1bb6272018-09-06 09:59:22 -07001882 private void notifyRequester(MainThreadRequest request) {
1883 synchronized (request) {
1884 request.notifyAll();
1885 }
1886 }
1887
Jake Hambye994d462014-02-03 13:10:13 -08001888 private void handleNullReturnEvent(Message msg, String command) {
1889 AsyncResult ar = (AsyncResult) msg.obj;
1890 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1891 if (ar.exception == null) {
1892 request.result = true;
1893 } else {
1894 request.result = false;
1895 if (ar.exception instanceof CommandException) {
1896 loge(command + ": CommandException: " + ar.exception);
1897 } else {
1898 loge(command + ": Unknown exception");
1899 }
1900 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001901 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
1906 * Posts the specified command to be executed on the main thread,
1907 * waits for the request to complete, and returns the result.
1908 * @see #sendRequestAsync
1909 */
1910 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001911 return sendRequest(
1912 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001913 }
1914
1915 /**
1916 * Posts the specified command to be executed on the main thread,
1917 * waits for the request to complete, and returns the result.
1918 * @see #sendRequestAsync
1919 */
1920 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1921 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001922 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001923 }
1924
1925 /**
1926 * Posts the specified command to be executed on the main thread,
1927 * waits for the request to complete, and returns the result.
1928 * @see #sendRequestAsync
1929 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001930 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001931 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001932 }
1933
1934 /**
1935 * Posts the specified command to be executed on the main thread,
1936 * waits for the request to complete, and returns the result.
1937 * @see #sendRequestAsync
1938 */
Nathan Harold92bed182018-10-12 18:16:49 -07001939 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1940 return sendRequest(command, argument, subId, null, workSource);
1941 }
1942
1943 /**
1944 * Posts the specified command to be executed on the main thread,
1945 * waits for the request to complete, and returns the result.
1946 * @see #sendRequestAsync
1947 */
1948 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1949 return sendRequest(
1950 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1951 }
1952
1953 /**
1954 * Posts the specified command to be executed on the main thread,
1955 * waits for the request to complete, and returns the result.
1956 * @see #sendRequestAsync
1957 */
1958 private Object sendRequest(
1959 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1961 throw new RuntimeException("This method will deadlock if called from the main thread.");
1962 }
1963
Nathan Harold92bed182018-10-12 18:16:49 -07001964 MainThreadRequest request = null;
1965 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1966 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1967 } else if (phone != null) {
1968 request = new MainThreadRequest(argument, phone, workSource);
1969 } else {
1970 request = new MainThreadRequest(argument, subId, workSource);
1971 }
1972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 Message msg = mMainThreadHandler.obtainMessage(command, request);
1974 msg.sendToTarget();
1975
1976 // Wait for the request to complete
1977 synchronized (request) {
1978 while (request.result == null) {
1979 try {
1980 request.wait();
1981 } catch (InterruptedException e) {
1982 // Do nothing, go back and wait until the request is complete
1983 }
1984 }
1985 }
1986 return request.result;
1987 }
1988
1989 /**
1990 * Asynchronous ("fire and forget") version of sendRequest():
1991 * Posts the specified command to be executed on the main thread, and
1992 * returns immediately.
1993 * @see #sendRequest
1994 */
1995 private void sendRequestAsync(int command) {
1996 mMainThreadHandler.sendEmptyMessage(command);
1997 }
1998
1999 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002000 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002001 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002002 */
2003 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002004 sendRequestAsync(command, argument, null, null);
2005 }
2006
2007 /**
2008 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2009 * @see {@link #sendRequest(int,Object)}
2010 */
2011 private void sendRequestAsync(
2012 int command, Object argument, Phone phone, WorkSource workSource) {
2013 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002014 Message msg = mMainThreadHandler.obtainMessage(command, request);
2015 msg.sendToTarget();
2016 }
2017
2018 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 * Initialize the singleton PhoneInterfaceManager instance.
2020 * This is only done once, at startup, from PhoneApp.onCreate().
2021 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002022 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023 synchronized (PhoneInterfaceManager.class) {
2024 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002025 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 } else {
2027 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2028 }
2029 return sInstance;
2030 }
2031 }
2032
2033 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002034 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002037 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002038 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2040 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002041 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002042 mTelephonySharedPreferences =
2043 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002044 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002045 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002046 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 publish();
2049 }
2050
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002051 private Phone getDefaultPhone() {
2052 Phone thePhone = getPhone(getDefaultSubscription());
2053 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2054 }
2055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 private void publish() {
2057 if (DBG) log("publish: " + this);
2058
Peter Wangc035ce42020-01-08 21:00:22 -08002059 TelephonyFrameworkInitializer
2060 .getTelephonyServiceManager()
2061 .getTelephonyServiceRegisterer()
2062 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 }
2064
Stuart Scott584921c2015-01-15 17:10:34 -08002065 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002066 if (request.phone != null) {
2067 return request.phone;
2068 } else {
2069 return getPhoneFromSubId(request.subId);
2070 }
2071 }
2072
2073 private Phone getPhoneFromSubId(int subId) {
2074 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2075 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002076 }
2077
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002078 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2079 Phone phone = getPhoneFromRequest(request);
2080 return phone == null ? null :
2081 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2082 }
2083
Wink Saville36469e72014-06-11 15:17:00 -07002084 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002085 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002086 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088
Naina Nallurid63128d2019-09-17 14:10:30 -07002089 private void sendEraseModemConfig(Phone phone) {
2090 if (phone != null) {
2091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2092 mApp, phone.getSubId(), "eraseModemConfig");
2093 final long identity = Binder.clearCallingIdentity();
2094 try {
2095 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2096 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2097 } finally {
2098 Binder.restoreCallingIdentity(identity);
2099 }
2100 }
2101 }
2102
Peter Wang44b186e2020-01-13 23:33:09 -08002103 private boolean isImsAvailableOnDevice() {
2104 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2105 if (pm == null) {
2106 // For some reason package manger is not available.. This will fail internally anyway,
2107 // so do not throw error and allow.
2108 return true;
2109 }
2110 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2111 }
2112
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002114 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002115 }
2116
Wink Savilleb564aae2014-10-23 10:18:09 -07002117 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 if (DBG) log("dial: " + number);
2119 // No permission check needed here: This is just a wrapper around the
2120 // ACTION_DIAL intent, which is available to any app since it puts up
2121 // the UI before it does anything.
2122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002123 final long identity = Binder.clearCallingIdentity();
2124 try {
2125 String url = createTelUrl(number);
2126 if (url == null) {
2127 return;
2128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002130 // PENDING: should we just silently fail if phone is offhook or ringing?
2131 PhoneConstants.State state = mCM.getState(subId);
2132 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2133 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2134 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2135 mApp.startActivity(intent);
2136 }
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 }
2140 }
2141
2142 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002143 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002144 }
2145
Wink Savilleb564aae2014-10-23 10:18:09 -07002146 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 if (DBG) log("call: " + number);
2148
2149 // This is just a wrapper around the ACTION_CALL intent, but we still
2150 // need to do a permission check since we're calling startActivity()
2151 // from the context of the phone app.
2152 enforceCallPermission();
2153
Jordan Liu1617b712019-07-10 15:06:26 -07002154 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 != AppOpsManager.MODE_ALLOWED) {
2156 return;
2157 }
2158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 String url = createTelUrl(number);
2162 if (url == null) {
2163 return;
2164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166 boolean isValid = false;
2167 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2168 if (slist != null) {
2169 for (SubscriptionInfo subInfoRecord : slist) {
2170 if (subInfoRecord.getSubscriptionId() == subId) {
2171 isValid = true;
2172 break;
2173 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002174 }
Wink Saville08874612014-08-31 19:19:58 -07002175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 if (!isValid) {
2177 return;
2178 }
Wink Saville08874612014-08-31 19:19:58 -07002179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2181 intent.putExtra(SUBSCRIPTION_KEY, subId);
2182 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2183 mApp.startActivity(intent);
2184 } finally {
2185 Binder.restoreCallingIdentity(identity);
2186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188
Wink Savilleb564aae2014-10-23 10:18:09 -07002189 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002190 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002191 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2192 }
2193
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002195 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002196 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2197 }
2198
Wink Savilleb564aae2014-10-23 10:18:09 -07002199 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201
2202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2205 checkSimPin.start();
2206 return checkSimPin.unlockSim(null, pin);
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Wink Savilleb564aae2014-10-23 10:18:09 -07002212 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214
2215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2218 checkSimPuk.start();
2219 return checkSimPuk.unlockSim(puk, pin);
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224
2225 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002226 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 * a synchronous one.
2228 */
2229 private static class UnlockSim extends Thread {
2230
2231 private final IccCard mSimCard;
2232
2233 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002234 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2235 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236
2237 // For replies from SimCard interface
2238 private Handler mHandler;
2239
2240 // For async handler to identify request type
2241 private static final int SUPPLY_PIN_COMPLETE = 100;
2242
2243 public UnlockSim(IccCard simCard) {
2244 mSimCard = simCard;
2245 }
2246
2247 @Override
2248 public void run() {
2249 Looper.prepare();
2250 synchronized (UnlockSim.this) {
2251 mHandler = new Handler() {
2252 @Override
2253 public void handleMessage(Message msg) {
2254 AsyncResult ar = (AsyncResult) msg.obj;
2255 switch (msg.what) {
2256 case SUPPLY_PIN_COMPLETE:
2257 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2258 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002259 mRetryCount = msg.arg1;
2260 if (ar.exception != null) {
2261 if (ar.exception instanceof CommandException &&
2262 ((CommandException)(ar.exception)).getCommandError()
2263 == CommandException.Error.PASSWORD_INCORRECT) {
2264 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002265 } //When UiccCardApp dispose,handle message and return exception
2266 else if (ar.exception instanceof CommandException &&
2267 ((CommandException) (ar.exception)).getCommandError()
2268 == CommandException.Error.ABORTED) {
2269 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002270 } else {
2271 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2272 }
2273 } else {
2274 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 mDone = true;
2277 UnlockSim.this.notifyAll();
2278 }
2279 break;
2280 }
2281 }
2282 };
2283 UnlockSim.this.notifyAll();
2284 }
2285 Looper.loop();
2286 }
2287
2288 /*
2289 * Use PIN or PUK to unlock SIM card
2290 *
2291 * If PUK is null, unlock SIM card with PIN
2292 *
2293 * If PUK is not null, unlock SIM card with PUK and set PIN code
2294 */
Wink Saville9de0f752013-10-22 19:04:03 -07002295 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296
2297 while (mHandler == null) {
2298 try {
2299 wait();
2300 } catch (InterruptedException e) {
2301 Thread.currentThread().interrupt();
2302 }
2303 }
2304 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2305
2306 if (puk == null) {
2307 mSimCard.supplyPin(pin, callback);
2308 } else {
2309 mSimCard.supplyPuk(puk, pin, callback);
2310 }
2311
2312 while (!mDone) {
2313 try {
2314 Log.d(LOG_TAG, "wait for done");
2315 wait();
2316 } catch (InterruptedException e) {
2317 // Restore the interrupted status
2318 Thread.currentThread().interrupt();
2319 }
2320 }
2321 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002322 int[] resultArray = new int[2];
2323 resultArray[0] = mResult;
2324 resultArray[1] = mRetryCount;
2325 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 }
2327 }
2328
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002329 /**
2330 * This method has been removed due to privacy and stability concerns.
2331 */
2332 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002334 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2335 return;
Wink Saville36469e72014-06-11 15:17:00 -07002336 }
2337
Nathan Harold1f889d82020-06-04 17:05:26 -07002338 @Override
2339 public void updateServiceLocationWithPackageName(String callingPackage) {
2340 mApp.getSystemService(AppOpsManager.class)
2341 .checkPackage(Binder.getCallingUid(), callingPackage);
2342
Nathan Haroldf096d982020-11-18 17:18:06 -08002343 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002344 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2345 // Callers targeting S have no business invoking this method.
2346 return;
2347 }
2348
2349 LocationAccessPolicy.LocationPermissionResult locationResult =
2350 LocationAccessPolicy.checkLocationPermission(mApp,
2351 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2352 .setCallingPackage(callingPackage)
2353 .setCallingFeatureId(null)
2354 .setCallingPid(Binder.getCallingPid())
2355 .setCallingUid(Binder.getCallingUid())
2356 .setMethod("updateServiceLocation")
2357 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2358 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2359 .build());
2360 // Apps that lack location permission have no business calling this method;
2361 // however, because no permission was declared in the public API, denials must
2362 // all be "soft".
2363 switch (locationResult) {
2364 case DENIED_HARD: /* fall through */
2365 case DENIED_SOFT:
2366 return;
2367 }
2368
2369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 final long identity = Binder.clearCallingIdentity();
2371 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002372 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002373 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002374 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002381 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 @Override
2383 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002384 return isRadioOnWithFeature(callingPackage, null);
2385 }
2386
2387
2388 @Override
2389 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2390 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2391 callingFeatureId);
2392 }
2393
2394 @Deprecated
2395 @Override
2396 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2397 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002398 }
2399
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002400 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002401 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2402 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002404 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 return false;
2406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 return isRadioOnForSubscriber(subId);
2411 } finally {
2412 Binder.restoreCallingIdentity(identity);
2413 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002414 }
2415
2416 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 final long identity = Binder.clearCallingIdentity();
2418 try {
2419 final Phone phone = getPhone(subId);
2420 if (phone != null) {
2421 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2422 } else {
2423 return false;
2424 }
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
2430 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002431 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
Wink Saville36469e72014-06-11 15:17:00 -07002433
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 final Phone phone = getPhone(subId);
2440 if (phone != null) {
2441 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 }
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
2448 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002449 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
2451
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
2457 final Phone phone = getPhone(subId);
2458 if (phone == null) {
2459 return false;
2460 }
2461 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2462 toggleRadioOnOffForSubscriber(subId);
2463 }
2464 return true;
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
Wink Saville36469e72014-06-11 15:17:00 -07002469
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002470 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002471 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002472 /*
2473 * If any of the Radios are available, it will need to be
2474 * shutdown. So return true if any Radio is available.
2475 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2479 Phone phone = PhoneFactory.getPhone(i);
2480 if (phone != null && phone.isRadioAvailable()) return true;
2481 }
2482 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2483 return false;
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002486 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002487 }
2488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002490 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 enforceModifyPermission();
2492
2493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2496 logv("Shutting down Phone " + i);
2497 shutdownRadioUsingPhoneId(i);
2498 }
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002501 }
2502 }
2503
2504 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002505 Phone phone = PhoneFactory.getPhone(phoneId);
2506 if (phone != null && phone.isRadioAvailable()) {
2507 phone.shutdownRadio();
2508 }
2509 }
2510
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2517 if (defaultPhone != null) {
2518 defaultPhone.setRadioPower(turnOn);
2519 return true;
2520 } else {
2521 loge("There's no default phone.");
2522 return false;
2523 }
2524 } finally {
2525 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002526 }
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
2528
Wink Savilleb564aae2014-10-23 10:18:09 -07002529 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 final Phone phone = getPhone(subId);
2535 if (phone != null) {
2536 phone.setRadioPower(turnOn);
2537 return true;
2538 } else {
2539 return false;
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 }
2545
Wink Saville36469e72014-06-11 15:17:00 -07002546 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 public boolean enableDataConnectivity() {
2549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 int subId = mSubscriptionController.getDefaultDataSubId();
2554 final Phone phone = getPhone(subId);
2555 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002556 phone.getDataEnabledSettings().setDataEnabled(
2557 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 return true;
2559 } else {
2560 return false;
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 }
2566
Wink Saville36469e72014-06-11 15:17:00 -07002567 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002568 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 public boolean disableDataConnectivity() {
2570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 int subId = mSubscriptionController.getDefaultDataSubId();
2575 final Phone phone = getPhone(subId);
2576 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002577 phone.getDataEnabledSettings().setDataEnabled(
2578 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 return true;
2580 } else {
2581 return false;
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 }
2587
Sanket Padawe356d7632015-06-22 14:03:32 -07002588 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002589 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 final long identity = Binder.clearCallingIdentity();
2591 try {
2592 final Phone phone = getPhone(subId);
2593 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002594 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 } else {
2596 return false;
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 }
2602
2603 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002604 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002605 }
2606
pkanwarae03a6b2016-11-06 20:37:09 -08002607 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 enforceCallPermission();
2609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2613 return;
2614 }
2615 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2616 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
pkanwar32d516d2016-10-14 19:37:38 -07002620 };
2621
Wink Savilleb564aae2014-10-23 10:18:09 -07002622 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624
2625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2628 return false;
2629 }
2630 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002637 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002638 }
2639
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002640 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 Phone phone = PhoneFactory.getPhone(slotIndex);
2644 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2645 PhoneConstantConversions.convertCallState(phone.getState());
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
Sanket Padawe356d7632015-06-22 14:03:32 -07002651 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002652 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002653 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2654 }
2655
2656 @Override
2657 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002660 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 if (phone != null) {
2662 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2663 } else {
2664 return PhoneConstantConversions.convertDataState(
2665 PhoneConstants.DataState.DISCONNECTED);
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002673 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002674 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2675 }
2676
2677 @Override
2678 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002681 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 if (phone != null) {
2683 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2684 } else {
2685 return TelephonyManager.DATA_ACTIVITY_NONE;
2686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
2692 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002693 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002695 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002696
2697 LocationAccessPolicy.LocationPermissionResult locationResult =
2698 LocationAccessPolicy.checkLocationPermission(mApp,
2699 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2700 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002701 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002702 .setCallingPid(Binder.getCallingPid())
2703 .setCallingUid(Binder.getCallingUid())
2704 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002705 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002706 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2707 .build());
2708 switch (locationResult) {
2709 case DENIED_HARD:
2710 throw new SecurityException("Not allowed to access cell location");
2711 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002712 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2713 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002716 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002720 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002721 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
Svetoslav64fad262015-04-14 14:35:21 -07002725 }
2726
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002728 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002729 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2730 // registered cell info, so return a NULL country instead.
2731 final long identity = Binder.clearCallingIdentity();
2732 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002733 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2734 // Get default phone in this case.
2735 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2736 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002737 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002739 if (phone == null) return "";
2740 ServiceStateTracker sst = phone.getServiceStateTracker();
2741 if (sst == null) return "";
2742 LocaleTracker lt = sst.getLocaleTracker();
2743 if (lt == null) return "";
2744 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2745 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2746 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002750 }
2751
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002752 /**
2753 * This method was removed due to potential issues caused by performing partial
2754 * updates of service state, and lack of a credible use case.
2755 *
2756 * This has the ability to break the telephony implementation by disabling notification of
2757 * changes in device connectivity. DO NOT USE THIS!
2758 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002759 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 public void enableLocationUpdates() {
2761 mApp.enforceCallingOrSelfPermission(
2762 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
2764
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002765 /**
2766 * This method was removed due to potential issues caused by performing partial
2767 * updates of service state, and lack of a credible use case.
2768 *
2769 * This has the ability to break the telephony implementation by disabling notification of
2770 * changes in device connectivity. DO NOT USE THIS!
2771 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 @Override
2773 public void disableLocationUpdates() {
2774 mApp.enforceCallingOrSelfPermission(
2775 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777
2778 @Override
2779 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002780 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2781 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002782 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002783 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2784 throw new SecurityException(
2785 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2786 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002787
Jordan Liu1617b712019-07-10 15:06:26 -07002788 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2790 return null;
2791 }
Svetoslav64fad262015-04-14 14:35:21 -07002792
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002793 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002795 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002796 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797
Nathan Haroldf180aac2018-06-01 18:43:55 -07002798 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2799 for (CellInfo ci : info) {
2800 if (ci instanceof CellInfoGsm) {
2801 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2802 } else if (ci instanceof CellInfoWcdma) {
2803 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002806 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807 }
2808
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002809 private List<CellInfo> getCachedCellInfo() {
2810 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2811 for (Phone phone : PhoneFactory.getPhones()) {
2812 List<CellInfo> info = phone.getAllCellInfo();
2813 if (info != null) cellInfos.addAll(info);
2814 }
2815 return cellInfos;
2816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817
2818 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002819 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002820 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002821 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002822
2823 LocationAccessPolicy.LocationPermissionResult locationResult =
2824 LocationAccessPolicy.checkLocationPermission(mApp,
2825 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2826 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002827 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002828 .setCallingPid(Binder.getCallingPid())
2829 .setCallingUid(Binder.getCallingUid())
2830 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002831 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002832 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2833 .build());
2834 switch (locationResult) {
2835 case DENIED_HARD:
2836 throw new SecurityException("Not allowed to access cell info");
2837 case DENIED_SOFT:
2838 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Nathan Haroldf096d982020-11-18 17:18:06 -08002841 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002842 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2843 return getCachedCellInfo();
2844 }
2845
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002846 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2851 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002852 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002853 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 if (info != null) cellInfos.addAll(info);
2855 }
2856 return cellInfos;
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860 }
2861
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002862 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002863 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2864 String callingFeatureId) {
2865 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2866 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002867 }
2868
2869 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002870 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2871 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002872 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002873 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002874 }
2875
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002876 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2877 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002878 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002879 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002880
2881 LocationAccessPolicy.LocationPermissionResult locationResult =
2882 LocationAccessPolicy.checkLocationPermission(mApp,
2883 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2884 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002885 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002886 .setCallingPid(Binder.getCallingPid())
2887 .setCallingUid(Binder.getCallingUid())
2888 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002889 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2890 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002891 .build());
2892 switch (locationResult) {
2893 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002894 if (TelephonyPermissions
2895 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002896 // Safetynet logging for b/154934934
2897 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2898 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002899 throw new SecurityException("Not allowed to access cell info");
2900 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002901 if (TelephonyPermissions
2902 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002903 // Safetynet logging for b/154934934
2904 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2905 }
Nathan Harold5320c422019-05-09 10:26:08 -07002906 try {
2907 cb.onCellInfo(new ArrayList<CellInfo>());
2908 } catch (RemoteException re) {
2909 // Drop without consequences
2910 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002911 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002912 }
2913
Nathan Harolda939a962019-05-09 10:13:47 -07002914
2915 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002916 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2917
2918 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2919 }
2920
2921 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002923 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925
2926 final long identity = Binder.clearCallingIdentity();
2927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002928 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933
Shishir Agrawala9f32182016-04-12 12:00:16 -07002934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002935 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002936 Phone phone = PhoneFactory.getPhone(slotIndex);
2937 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002938 return null;
2939 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002940 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002941 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002942 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002943 return null;
2944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 return phone.getImei();
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
2951 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002952 }
2953
2954 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002955 public String getTypeAllocationCodeForSlot(int slotIndex) {
2956 Phone phone = PhoneFactory.getPhone(slotIndex);
2957 String tac = null;
2958 if (phone != null) {
2959 String imei = phone.getImei();
2960 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2961 }
2962 return tac;
2963 }
2964
2965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002966 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002967 Phone phone = PhoneFactory.getPhone(slotIndex);
2968 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002969 return null;
2970 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002971
Jeff Davidson913390f2018-02-23 17:11:49 -08002972 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002973 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002974 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002975 return null;
2976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 return phone.getMeid();
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
Jack Yu2af8d712017-03-15 17:14:14 -07002984 }
2985
2986 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002987 public String getManufacturerCodeForSlot(int slotIndex) {
2988 Phone phone = PhoneFactory.getPhone(slotIndex);
2989 String manufacturerCode = null;
2990 if (phone != null) {
2991 String meid = phone.getMeid();
2992 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2993 }
2994 return manufacturerCode;
2995 }
2996
2997 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002998 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2999 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003000 Phone phone = PhoneFactory.getPhone(slotIndex);
3001 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003002 return null;
3003 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003004 int subId = phone.getSubId();
3005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003006 mApp, subId, callingPackage, callingFeatureId,
3007 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003008 return null;
3009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 return phone.getDeviceSvn();
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003017 }
3018
fionaxu43304da2017-11-27 22:51:16 -08003019 @Override
3020 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 final Phone phone = getPhone(subId);
3024 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
fionaxu43304da2017-11-27 22:51:16 -08003028 }
3029
3030 @Override
3031 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 final Phone phone = getPhone(subId);
3035 return phone == null ? null : phone.getCarrierName();
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
fionaxu43304da2017-11-27 22:51:16 -08003039 }
3040
calvinpanffe225e2018-11-01 19:43:06 +08003041 @Override
chen xu0026ca62019-03-06 15:28:50 -08003042 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 final Phone phone = getPhone(subId);
3046 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003047 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 @Override
chen xu0026ca62019-03-06 15:28:50 -08003054 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003058 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
chen xu651eec72018-11-11 19:03:44 -08003064 @Override
chen xu864e11c2018-12-06 22:10:03 -08003065 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3066 if (!isSubscriptionMccMnc) {
3067 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3068 }
chen xu651eec72018-11-11 19:03:44 -08003069 final Phone phone = PhoneFactory.getPhone(slotIndex);
3070 if (phone == null) {
3071 return TelephonyManager.UNKNOWN_CARRIER_ID;
3072 }
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 //
3082 // Internal helper methods.
3083 //
3084
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003085 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3087 *
3088 * @throws SecurityException if the caller does not have the required permission
3089 */
3090 private void enforceModifyPermission() {
3091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3092 }
3093
Shuo Qiancd19c462020-01-16 20:51:11 -08003094 /**
3095 * Make sure the caller is system.
3096 *
3097 * @throws SecurityException if the caller is not system.
3098 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003099 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003100 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3101 throw new SecurityException("Caller must be system");
3102 }
3103 }
3104
Shuo Qian3b6ee772019-11-13 17:43:31 -08003105 private void enforceActiveEmergencySessionPermission() {
3106 mApp.enforceCallingOrSelfPermission(
3107 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3108 }
3109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 /**
3111 * Make sure the caller has the CALL_PHONE permission.
3112 *
3113 * @throws SecurityException if the caller does not have the required permission
3114 */
3115 private void enforceCallPermission() {
3116 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3117 }
3118
paulhu5a773602019-08-23 19:17:33 +08003119 private void enforceSettingsPermission() {
3120 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003121 }
3122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 private String createTelUrl(String number) {
3124 if (TextUtils.isEmpty(number)) {
3125 return null;
3126 }
3127
Jake Hambye994d462014-02-03 13:10:13 -08003128 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 }
3130
Ihab Awadf9e92732013-12-05 18:02:52 -08003131 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3133 }
3134
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003135 private static void logv(String msg) {
3136 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3137 }
3138
Ihab Awadf9e92732013-12-05 18:02:52 -08003139 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3141 }
3142
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003143 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003145 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003146 }
3147
Sanket Padawe356d7632015-06-22 14:03:32 -07003148 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003149 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 final Phone phone = PhoneFactory.getPhone(slotIndex);
3153 if (phone == null) {
3154 return PhoneConstants.PHONE_TYPE_NONE;
3155 } else {
3156 return phone.getPhoneType();
3157 }
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 }
3162
3163 /**
3164 * Returns the CDMA ERI icon index to display
3165 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003167 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3168 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3169 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003170 }
3171
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003173 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3174 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003176 mApp, subId, callingPackage, callingFeatureId,
3177 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003178 return -1;
3179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 final Phone phone = getPhone(subId);
3184 if (phone != null) {
3185 return phone.getCdmaEriIconIndex();
3186 } else {
3187 return -1;
3188 }
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
3194 /**
3195 * Returns the CDMA ERI icon mode,
3196 * 0 - ON
3197 * 1 - FLASHING
3198 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003200 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3201 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3202 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003203 }
3204
Sanket Padawe356d7632015-06-22 14:03:32 -07003205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003206 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3207 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003209 mApp, subId, callingPackage, callingFeatureId,
3210 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003211 return -1;
3212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 final Phone phone = getPhone(subId);
3217 if (phone != null) {
3218 return phone.getCdmaEriIconMode();
3219 } else {
3220 return -1;
3221 }
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 }
3226
3227 /**
3228 * Returns the CDMA ERI text,
3229 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003231 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3232 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3233 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003234 }
3235
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3238 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003240 mApp, subId, callingPackage, callingFeatureId,
3241 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003242 return null;
3243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003244
3245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 final Phone phone = getPhone(subId);
3248 if (phone != null) {
3249 return phone.getCdmaEriText();
3250 } else {
3251 return null;
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
3258 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003259 * Returns the CDMA MDN.
3260 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003262 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3264 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003269 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 return phone.getLine1Number();
3271 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 return null;
3274 }
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003277 }
3278 }
3279
3280 /**
3281 * Returns the CDMA MIN.
3282 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003284 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3286 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 final Phone phone = getPhone(subId);
3291 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3292 return phone.getCdmaMin();
3293 } else {
3294 return null;
3295 }
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003298 }
3299 }
3300
Hall Liud892bec2018-11-30 14:51:45 -08003301 @Override
3302 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3303 INumberVerificationCallback callback, String callingPackage) {
3304 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3305 != PERMISSION_GRANTED) {
3306 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3307 }
3308 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3309
3310 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3311 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003312 throw new SecurityException("Calling package must be configured in the device config: "
3313 + "calling package: " + callingPackage
3314 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003315 }
3316
3317 if (range == null) {
3318 throw new NullPointerException("Range must be non-null");
3319 }
3320
3321 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003322 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003323
3324 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3325 }
3326
Junda Liuca05d5d2014-08-14 22:36:34 -07003327 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 * Returns true if CDMA provisioning needs to run.
3329 */
3330 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003337 }
3338
3339 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003340 * Sets the voice mail number of a given subId.
3341 */
3342 @Override
3343 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003344 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3345 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3350 new Pair<String, String>(alphaTag, number), new Integer(subId));
3351 return success;
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003355 }
3356
Ta-wei Yen87c49842016-05-13 21:19:52 -07003357 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003358 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003360 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3361 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003362 if (!TextUtils.equals(callingPackage, systemDialer)) {
3363 throw new SecurityException("caller must be system dialer");
3364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365
3366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3369 if (phoneAccountHandle == null) {
3370 return null;
3371 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373 } finally {
3374 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003375 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003376 }
3377
3378 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003379 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3380 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003383 mApp, subId, callingPackage, callingFeatureId,
3384 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003385 return null;
3386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003388 final long identity = Binder.clearCallingIdentity();
3389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003394 }
3395
3396 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003397 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3398 VisualVoicemailSmsFilterSettings settings) {
3399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003408 }
3409
3410 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003411 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3412 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003417 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418 } finally {
3419 Binder.restoreCallingIdentity(identity);
3420 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003421 }
3422
3423 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003424 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3425 String callingPackage, int subId) {
3426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003431 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003435 }
3436
3437 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003438 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003444 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003448 }
3449
3450 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003451 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3452 String callingAttributionTag, int subId, String number, int port, String text,
3453 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003454 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003455 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003456 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003457 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003458 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3459 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003460 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003461
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003462 /**
fionaxu0152e512016-11-14 13:36:14 -08003463 * Sets the voice activation state of a given subId.
3464 */
3465 @Override
3466 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3468 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 final Phone phone = getPhone(subId);
3473 if (phone != null) {
3474 phone.setVoiceActivationState(activationState);
3475 } else {
3476 loge("setVoiceActivationState fails with invalid subId: " + subId);
3477 }
3478 } finally {
3479 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003480 }
3481 }
3482
3483 /**
3484 * Sets the data activation state of a given subId.
3485 */
3486 @Override
3487 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3489 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 final Phone phone = getPhone(subId);
3494 if (phone != null) {
3495 phone.setDataActivationState(activationState);
3496 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003497 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498 }
3499 } finally {
3500 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003501 }
3502 }
3503
3504 /**
3505 * Returns the voice activation state of a given subId.
3506 */
3507 @Override
3508 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510
fionaxu0152e512016-11-14 13:36:14 -08003511 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 if (phone != null) {
3515 return phone.getVoiceActivationState();
3516 } else {
3517 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3518 }
3519 } finally {
3520 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003521 }
3522 }
3523
3524 /**
3525 * Returns the data activation state of a given subId.
3526 */
3527 @Override
3528 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
fionaxu0152e512016-11-14 13:36:14 -08003531 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 if (phone != null) {
3535 return phone.getDataActivationState();
3536 } else {
3537 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3538 }
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003541 }
3542 }
3543
3544 /**
Wink Saville36469e72014-06-11 15:17:00 -07003545 * Returns the unread count of voicemails for a subId
3546 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3549 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 mApp, subId, callingPackage, callingFeatureId,
3552 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003553 return 0;
3554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 if (phone != null) {
3559 return phone.getVoiceMessageCount();
3560 } else {
3561 return 0;
3562 }
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003566 }
3567
3568 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003569 * returns true, if the device is in a state where both voice and data
3570 * are supported simultaneously. This can change based on location or network condition.
3571 */
3572 @Override
3573 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 final Phone phone = getPhone(subId);
3577 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003581 }
3582
3583 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003584 * Send the dialer code if called from the current default dialer or the caller has
3585 * carrier privilege.
3586 * @param inputCode The dialer code to send
3587 */
3588 @Override
3589 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003592 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3593 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003594 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003595 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602 } finally {
3603 Binder.restoreCallingIdentity(identity);
3604 }
fionaxu235cc5e2017-03-06 22:25:57 -08003605 }
3606
Pengquan Menga1bb6272018-09-06 09:59:22 -07003607 @Override
3608 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003609 TelephonyPermissions
3610 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3611 mApp, subId, "getNetworkSelectionMode");
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 if (!isActiveSubscription(subId)) {
3615 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3616 }
3617 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003621 }
3622
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003624 public boolean isInEmergencySmsMode() {
3625 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 for (Phone phone : PhoneFactory.getPhones()) {
3629 if (phone.isInEmergencySmsMode()) {
3630 return true;
3631 }
3632 }
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
3636 return false;
3637 }
3638
shilu366312e2019-12-17 09:28:10 -08003639 /**
3640 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3641 * @param subId The subscription to use to check the configuration.
3642 * @param c The callback that will be used to send the result.
3643 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003644 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003645 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3646 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003647 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3648 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003649
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003650 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3651 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3652 "IMS not available on device.");
3653 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 final long token = Binder.clearCallingIdentity();
3655 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003659 } catch (ImsException e) {
3660 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 } finally {
3662 Binder.restoreCallingIdentity(token);
3663 }
3664 }
3665
shilu366312e2019-12-17 09:28:10 -08003666 /**
3667 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3668 * @param subId The subscription to use to check the configuration.
3669 * @param c The callback that will be used to send the result.
3670 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003672 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003673 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3674 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3676 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3677 }
Meng Wangafbc5852019-09-19 17:37:13 -07003678 final long token = Binder.clearCallingIdentity();
3679 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003680 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003681 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3682 .removeRegistrationCallbackForSubscription(c, subId);
3683 } catch (ImsException e) {
3684 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3685 + "is inactive, ignoring unregister.");
3686 // If the subscription is no longer active, just return, since the callback
3687 // will already have been removed internally.
3688 } finally {
3689 Binder.restoreCallingIdentity(token);
3690 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 }
3692
Brad Ebingera34a6c22019-10-22 17:36:18 -07003693 /**
3694 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3695 */
3696 @Override
3697 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3698 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3699 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3701 "IMS not available on device.");
3702 }
3703 final long token = Binder.clearCallingIdentity();
3704 try {
3705 Phone phone = getPhone(subId);
3706 if (phone == null) {
3707 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3708 + subId + "'");
3709 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3710 }
3711 phone.getImsRegistrationState(regState -> {
3712 try {
3713 consumer.accept((regState == null)
3714 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3715 } catch (RemoteException e) {
3716 // Ignore if the remote process is no longer available to call back.
3717 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3718 }
3719 });
3720 } finally {
3721 Binder.restoreCallingIdentity(token);
3722 }
3723 }
3724
3725 /**
3726 * Get the transport type for the IMS service registration state.
3727 */
3728 @Override
3729 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003730 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3731 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003732 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3734 "IMS not available on device.");
3735 }
3736 final long token = Binder.clearCallingIdentity();
3737 try {
3738 Phone phone = getPhone(subId);
3739 if (phone == null) {
3740 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3741 + subId + "'");
3742 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3743 }
3744 phone.getImsRegistrationTech(regTech -> {
3745 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3746 int regTechConverted = (regTech == null)
3747 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3748 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3749 regTechConverted);
3750 try {
3751 consumer.accept(regTechConverted);
3752 } catch (RemoteException e) {
3753 // Ignore if the remote process is no longer available to call back.
3754 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3755 }
3756 });
3757 } finally {
3758 Binder.restoreCallingIdentity(token);
3759 }
3760 }
3761
shilu366312e2019-12-17 09:28:10 -08003762 /**
3763 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3764 * @param subId The subscription to use to check the configuration.
3765 * @param c The callback that will be used to send the result.
3766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003768 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3769 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003770 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3771 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003772 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3773 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3774 "IMS not available on device.");
3775 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3777 final long token = Binder.clearCallingIdentity();
3778 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003780 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003781 } catch (ImsException e) {
3782 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 } finally {
3784 Binder.restoreCallingIdentity(token);
3785 }
3786 }
3787
shilu366312e2019-12-17 09:28:10 -08003788 /**
3789 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3790 * @param subId The subscription to use to check the configuration.
3791 * @param c The callback that will be used to send the result.
3792 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003794 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003795 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3796 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003797 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3798 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3799 }
Meng Wangafbc5852019-09-19 17:37:13 -07003800
3801 final long token = Binder.clearCallingIdentity();
3802 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003803 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003804 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003805 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003806 } catch (ImsException e) {
3807 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3808 + "is inactive, ignoring unregister.");
3809 // If the subscription is no longer active, just return, since the callback
3810 // will already have been removed internally.
3811 } finally {
3812 Binder.restoreCallingIdentity(token);
3813 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003814 }
3815
3816 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003817 public boolean isCapable(int subId, int capability, int regTech) {
3818 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3820 final long token = Binder.clearCallingIdentity();
3821 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003822 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003824 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3826 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003827 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003828 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3829 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 } finally {
3831 Binder.restoreCallingIdentity(token);
3832 }
3833 }
3834
3835 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003836 public boolean isAvailable(int subId, int capability, int regTech) {
3837 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 final long token = Binder.clearCallingIdentity();
3839 try {
3840 Phone phone = getPhone(subId);
3841 if (phone == null) return false;
3842 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003843 } catch (com.android.ims.ImsException e) {
3844 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3845 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 } finally {
3847 Binder.restoreCallingIdentity(token);
3848 }
3849 }
3850
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003851 /**
3852 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3853 * subscription.
3854 * @param subId The subscription to use to check the configuration.
3855 * @param callback The callback that will be used to send the result.
3856 * @param capability The MmTelFeature capability that will be used to send the result.
3857 * @param transportType The transport type of the MmTelFeature capability.
3858 */
3859 @Override
3860 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3861 int transportType) {
3862 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3863 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3865 "IMS not available on device.");
3866 }
3867 final long token = Binder.clearCallingIdentity();
3868 try {
3869 int slotId = getSlotIndex(subId);
3870 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3871 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3872 + subId + "'");
3873 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3874 }
3875 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3876 transportType, aBoolean -> {
3877 try {
3878 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3879 } catch (RemoteException e) {
3880 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3881 + "running. Ignore");
3882 }
3883 });
3884 } finally {
3885 Binder.restoreCallingIdentity(token);
3886 }
3887 }
3888
shilu366312e2019-12-17 09:28:10 -08003889 /**
3890 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3891 * @param subId The subscription to use to check the configuration.
3892 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 @Override
3894 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003895 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3896 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003897
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3899 final long token = Binder.clearCallingIdentity();
3900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003903 } catch (ImsException e) {
3904 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 } finally {
3906 Binder.restoreCallingIdentity(token);
3907 }
3908 }
3909
3910 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003911 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003913 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003917 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (ImsException e) {
3920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
3924 }
3925
shilu366312e2019-12-17 09:28:10 -08003926 /**
3927 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3928 * @param subId The subscription to use to check the configuration.
3929 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003931 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003932 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3933 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003937 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3938 } catch (ImsException e) {
3939 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
3943 }
3944
3945 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003946 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003948 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003953 } catch (ImsException e) {
3954 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959
shilu366312e2019-12-17 09:28:10 -08003960 /**
3961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3962 * @param subId The subscription to use to check the configuration.
3963 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 @Override
3965 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003966 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3967 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003973 } catch (ImsException e) {
3974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
3978 }
3979
3980 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003981 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003983 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(identity);
3992 }
3993 }
3994
shilu366312e2019-12-17 09:28:10 -08003995 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08003996 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
3997 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3998 * @param subId The subscription to use to check the configuration.
3999 */
4000 @Override
4001 public boolean isCrossSimCallingEnabledByUser(int subId) {
4002 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4003 mApp, subId, "isCrossSimCallingEnabledByUser");
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4007 return ImsManager.getInstance(mApp,
4008 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4009 } catch (ImsException e) {
4010 throw new ServiceSpecificException(e.getCode());
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
4016 /**
4017 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4018 * Requires MODIFY_PHONE_STATE permission.
4019 * @param subId The subscription to use to check the configuration.
4020 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4021 * false otherwise
4022 */
4023 @Override
4024 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4026 "setCrossSimCallingEnabled");
4027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4030 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4031 .setCrossSimCallingEnabled(isEnabled);
4032 } catch (ImsException e) {
4033 throw new ServiceSpecificException(e.getCode());
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
4037 }
4038
4039 /**
shilu366312e2019-12-17 09:28:10 -08004040 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4041 * @param subId The subscription to use to check the configuration.
4042 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 @Override
4044 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004045 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4046 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004050 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004052 } catch (ImsException e) {
4053 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
4057 }
4058
4059 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004060 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004062 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004066 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004068 } catch (ImsException e) {
4069 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
4073 }
4074
4075 @Override
4076 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4078 "setVoWiFiNonPersistent");
4079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004082 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004083 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004084 } catch (ImsException e) {
4085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
4089 }
4090
shilu366312e2019-12-17 09:28:10 -08004091 /**
4092 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4093 * @param subId The subscription to use to check the configuration.
4094 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 @Override
4096 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004097 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4098 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004102 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004104 } catch (ImsException e) {
4105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
4109 }
4110
4111 @Override
4112 public void setVoWiFiModeSetting(int subId, int mode) {
4113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4114 "setVoWiFiModeSetting");
4115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004120 } catch (ImsException e) {
4121 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
4125 }
4126
4127 @Override
4128 public int getVoWiFiRoamingModeSetting(int subId) {
4129 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (ImsException e) {
4136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4145 "setVoWiFiRoamingModeSetting");
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4161 "setRttCapabilityEnabled");
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
shilu366312e2019-12-17 09:28:10 -08004173 /**
4174 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4175 * @param subId The subscription to use to check the configuration.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
4178 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4180 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004184 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004193 @Override
4194 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4195 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004198 if (!isImsAvailableOnDevice()) {
4199 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4200 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004201 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004203 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004204 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
4212 @Override
4213 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4214 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4215 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4217 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4218 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004219 try {
4220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004221 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004222 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004224 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4225 + "is inactive, ignoring unregister.");
4226 // If the subscription is no longer active, just return, since the callback will already
4227 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
4231 }
4232
allenwtsu99c623b2020-01-03 18:24:23 +08004233
4234 private void checkModifyPhoneStatePermission(int subId, String message) {
4235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4236 message);
4237 }
4238
4239 private boolean isImsProvisioningRequired(int subId, int capability,
4240 boolean isMmtelCapability) {
4241 Phone phone = getPhone(subId);
4242 if (phone == null) {
4243 loge("phone instance null for subid " + subId);
4244 return false;
4245 }
4246 if (isMmtelCapability) {
4247 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4248 return false;
4249 }
4250 } else {
4251 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4252 return false;
4253 }
4254 }
4255 return true;
4256 }
4257
4258 @Override
4259 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4260 boolean isProvisioned) {
4261 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4262
4263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4266 if (!isImsProvisioningRequired(subId, capability, false)) {
4267 return;
4268 }
4269
4270 // this capability requires provisioning, route to the correct API.
4271 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4272 switch (capability) {
4273 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4274 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4275 ims.setEabProvisioned(isProvisioned);
4276 break;
4277 default: {
4278 throw new IllegalArgumentException("Tried to set provisioning for "
4279 + "rcs capability '" + capability + "', which does not require "
4280 + "provisioning.");
4281 }
4282 }
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286
4287 }
4288
4289
4290 @Override
4291 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4292 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4296 if (!isImsProvisioningRequired(subId, capability, false)) {
4297 return true;
4298 }
4299
4300 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4301 switch (capability) {
4302 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4303 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4304 return ims.isEabProvisionedOnDevice();
4305
4306 default: {
4307 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4308 + "capability '" + capability + "', which does not require "
4309 + "provisioning.");
4310 }
4311 }
4312
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004318 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004319 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4320 boolean isProvisioned) {
4321 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4322 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4323 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4324 }
allenwtsu99c623b2020-01-03 18:24:23 +08004325 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004329 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004330 return;
4331 }
4332
4333 // this capability requires provisioning, route to the correct API.
4334 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4335 switch (capability) {
4336 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4337 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4338 ims.setVolteProvisioned(isProvisioned);
4339 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4340 ims.setWfcProvisioned(isProvisioned);
4341 }
4342 break;
4343 }
4344 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4345 // There is currently no difference in VT provisioning type.
4346 ims.setVtProvisioned(isProvisioned);
4347 break;
4348 }
4349 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4350 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4351 // change the capability of the feature instead if needed.
4352 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4353 == isProvisioned) {
4354 // No change in provisioning.
4355 return;
4356 }
4357 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4358 try {
4359 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004360 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004361 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4362 + ", Exception" + e.getMessage());
4363 }
4364 break;
4365 }
4366 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004367 throw new IllegalArgumentException("Tried to set provisioning for "
4368 + "MmTel capability '" + capability + "', which does not require "
4369 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004370 }
4371 }
4372
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
4376 }
4377
4378 @Override
4379 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4380 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4381 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4382 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4383 }
4384 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004388 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004389 return true;
4390 }
4391
4392 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4393 switch (capability) {
4394 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4395 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4396 return ims.isVolteProvisionedOnDevice();
4397 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4398 return ims.isWfcProvisionedOnDevice();
4399 }
4400 // This should never happen, since we are checking tech above to make sure it
4401 // is either LTE or IWLAN.
4402 throw new IllegalArgumentException("Invalid radio technology for voice "
4403 + "capability.");
4404 }
4405 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4406 // There is currently no difference in VT provisioning type.
4407 return ims.isVtProvisionedOnDevice();
4408 }
4409 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4410 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4411 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4412 }
4413 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004414 throw new IllegalArgumentException(
4415 "Tried to get provisioning for MmTel capability '" + capability
4416 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004417 }
4418 }
4419
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
4423 }
4424
4425 @Override
4426 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4427 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4428 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4429 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4430 }
4431 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4432 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4433 return (provisionedBits & capability) > 0;
4434 }
4435
4436 @Override
4437 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4438 boolean isProvisioned) {
4439 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4440 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4441 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4442 }
4443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4444 "setProvisioningStatusForCapability");
4445 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4446 // If the current provisioning status for capability already matches isProvisioned,
4447 // do nothing.
4448 if (((provisionedBits & capability) > 0) == isProvisioned) {
4449 return;
4450 }
4451 if (isProvisioned) {
4452 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4453 } else {
4454 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4455 }
4456 }
4457
4458 /**
4459 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4460 * technology. The bitfield should mirror the bitfield defined by
4461 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4462 */
4463 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4464 String key = getMmTelProvisioningKey(subId, tech);
4465 // Default is no capabilities are provisioned.
4466 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4467 }
4468
4469 /**
4470 * Sets the MmTel capability provisioning bitfield (defined by
4471 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4472 * technology specified.
4473 *
4474 * Note: This is a synchronous command and should not be called on UI thread.
4475 */
4476 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4477 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4478 String key = getMmTelProvisioningKey(subId, tech);
4479 editor.putInt(key, newField);
4480 editor.commit();
4481 }
4482
4483 private static String getMmTelProvisioningKey(int subId, int tech) {
4484 // resulting key is provision_ims_mmtel_{subId}_{tech}
4485 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4486 }
4487
4488 /**
4489 * Query CarrierConfig to see if the specified capability requires provisioning for the
4490 * carrier associated with the subscription id.
4491 */
4492 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4493 int capability) {
4494 CarrierConfigManager configManager = new CarrierConfigManager(context);
4495 PersistableBundle c = configManager.getConfigForSubId(subId);
4496 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004497 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004498 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4499 false);
4500 boolean requireVoiceVtProvisioning = c.getBoolean(
4501 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4502
4503 // First check to make sure that the capability requires provisioning.
4504 switch (capability) {
4505 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4506 // intentional fallthrough
4507 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4508 if (requireVoiceVtProvisioning) {
4509 // Voice and Video requires provisioning
4510 return true;
4511 }
4512 break;
4513 }
4514 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4515 if (requireUtProvisioning) {
4516 // UT requires provisioning
4517 return true;
4518 }
4519 break;
4520 }
4521 }
4522 return false;
4523 }
4524
allenwtsu99c623b2020-01-03 18:24:23 +08004525 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4526 int capability) {
4527 CarrierConfigManager configManager = new CarrierConfigManager(context);
4528 PersistableBundle c = configManager.getConfigForSubId(subId);
4529
4530 boolean requireRcsProvisioning = c.getBoolean(
4531 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4532
4533 // First check to make sure that the capability requires provisioning.
4534 switch (capability) {
4535 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4536 // intentional fallthrough
4537 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4538 if (requireRcsProvisioning) {
4539 // OPTION or PRESENCE requires provisioning
4540 return true;
4541 }
4542 break;
4543 }
4544 }
4545 return false;
4546 }
4547
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004548 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004549 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004550 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4551 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4552 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004553 enforceReadPrivilegedPermission("getImsProvisioningInt");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004557 int slotId = getSlotIndex(subId);
4558 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4559 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4560 + subId + "' for key:" + key);
4561 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4562 }
4563 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004564 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004565 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4566 + subId + "' for key:" + key);
4567 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004568 } finally {
4569 Binder.restoreCallingIdentity(identity);
4570 }
4571 }
4572
4573 @Override
4574 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4576 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4577 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004578 enforceReadPrivilegedPermission("getImsProvisioningString");
4579 final long identity = Binder.clearCallingIdentity();
4580 try {
4581 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004582 int slotId = getSlotIndex(subId);
4583 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4584 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4585 + subId + "' for key:" + key);
4586 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4587 }
4588 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004589 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4591 + subId + "' for key:" + key);
4592 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
4596 }
4597
4598 @Override
4599 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4601 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4602 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4604 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004605 final long identity = Binder.clearCallingIdentity();
4606 try {
4607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004608 int slotId = getSlotIndex(subId);
4609 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4610 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4611 + subId + "' for key:" + key);
4612 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4613 }
4614 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004615 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004616 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4617 + "' for key:" + key);
4618 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
4622 }
4623
4624 @Override
4625 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004626 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4627 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4628 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4630 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 int slotId = getSlotIndex(subId);
4635 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4636 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4637 + subId + "' for key:" + key);
4638 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4639 }
4640 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004641 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4643 + "' for key:" + key);
4644 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004645 } finally {
4646 Binder.restoreCallingIdentity(identity);
4647 }
4648 }
4649
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004650 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 int slotId = SubscriptionManager.getSlotIndex(subId);
4652 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004653 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4654 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 }
4656 return slotId;
4657 }
4658
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004659 private int getSlotIndex(int subId) {
4660 int slotId = SubscriptionManager.getSlotIndex(subId);
4661 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4662 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4663 }
4664 return slotId;
4665 }
4666
Wink Saville36469e72014-06-11 15:17:00 -07004667 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004668 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004669 */
4670 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004671 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4672 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004673 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004674 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004675 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004676 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004677 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004678 mApp, subId, callingPackage, callingFeatureId,
4679 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004680 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4681 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 final long identity = Binder.clearCallingIdentity();
4684 try {
4685 final Phone phone = getPhone(subId);
4686 if (phone != null) {
4687 return phone.getServiceState().getDataNetworkType();
4688 } else {
4689 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4690 }
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004694 }
4695
4696 /**
4697 * Returns the data network type
4698 */
4699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004700 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4701 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4702 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004703 }
4704
4705 /**
4706 * Returns the data network type for a subId
4707 */
4708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004709 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004712 mApp, subId, callingPackage, callingFeatureId,
4713 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004714 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4715 }
4716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 final Phone phone = getPhone(subId);
4720 if (phone != null) {
4721 return phone.getServiceState().getDataNetworkType();
4722 } else {
4723 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4724 }
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004728 }
4729
4730 /**
Wink Saville36469e72014-06-11 15:17:00 -07004731 * Returns the Voice network type for a subId
4732 */
4733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004734 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4735 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004737 mApp, subId, callingPackage, callingFeatureId,
4738 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004739 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4740 }
4741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 final Phone phone = getPhone(subId);
4745 if (phone != null) {
4746 return phone.getServiceState().getVoiceNetworkType();
4747 } else {
4748 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4749 }
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004753 }
4754
4755 /**
4756 * @return true if a ICC card is present
4757 */
4758 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004759 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004760 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4761 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004762 }
4763
4764 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004765 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004766 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004767 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004768 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 final Phone phone = PhoneFactory.getPhone(slotIndex);
4772 if (phone != null) {
4773 return phone.getIccCard().hasIccCard();
4774 } else {
4775 return false;
4776 }
4777 } finally {
4778 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004780 }
4781
4782 /**
4783 * Return if the current radio is LTE on CDMA. This
4784 * is a tri-state return value as for a period of time
4785 * the mode may be unknown.
4786 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004787 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004788 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004789 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004790 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004792 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4793 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4794 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004795 }
4796
Sanket Padawe356d7632015-06-22 14:03:32 -07004797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004798 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4799 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004800 try {
4801 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4802 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004803 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4804 }
4805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 final Phone phone = getPhone(subId);
4809 if (phone == null) {
4810 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4811 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004812 return TelephonyProperties.lte_on_cdma_device()
4813 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 }
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004817 }
Wink Saville36469e72014-06-11 15:17:00 -07004818 }
4819
Wink Saville36469e72014-06-11 15:17:00 -07004820 /**
4821 * {@hide}
4822 * Returns Default subId, 0 in the case of single standby.
4823 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004824 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004825 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004826 }
4827
Shishir Agrawala9f32182016-04-12 12:00:16 -07004828 private int getSlotForDefaultSubscription() {
4829 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4830 }
4831
Wink Savilleb564aae2014-10-23 10:18:09 -07004832 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004833 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004834 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004835
Pengquan Menge92a50d2018-09-21 15:54:48 -07004836 private boolean isActiveSubscription(int subId) {
4837 return mSubscriptionController.isActiveSubId(subId);
4838 }
4839
Ihab Awadf2177b72013-11-25 13:33:23 -08004840 /**
4841 * @see android.telephony.TelephonyManager.WifiCallingChoices
4842 */
4843 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844 final long identity = Binder.clearCallingIdentity();
4845 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004846 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4848 getWhenToMakeWifiCallsDefaultPreference());
4849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004852 }
4853
4854 /**
4855 * @see android.telephony.TelephonyManager.WifiCallingChoices
4856 */
4857 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004861 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004866 }
4867
Sailesh Nepald1e68152013-12-12 19:08:02 -08004868 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004869 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004870 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004871 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004872
Jordan Liu4c733742019-02-28 12:03:40 -08004873 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4874 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4875 if (phoneId == -1) {
4876 throw new IllegalArgumentException("Given slot index: " + slotIndex
4877 + " does not correspond to an active phone");
4878 }
4879 return PhoneFactory.getPhone(phoneId);
4880 }
4881
Shishir Agrawal566b7612013-10-28 14:41:00 -07004882 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004883 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4884 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4886 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004888 if (DBG) {
4889 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4890 }
4891 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4892 p2);
4893 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004894
Jordan Liu4c733742019-02-28 12:03:40 -08004895
4896 @Override
4897 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4898 int slotIndex, String callingPackage, String aid, int p2) {
4899 enforceModifyPermission();
4900 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4901 if (DBG) {
4902 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4903 }
4904 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4905 callingPackage, aid, p2);
4906 }
4907
4908 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4909 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 if (TextUtils.equals(ISDR_AID, aid)) {
4913 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004914 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4915 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 if (bestComponent == null
4917 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4918 loge("The calling package is not allowed to access ISD-R.");
4919 throw new SecurityException(
4920 "The calling package is not allowed to access ISD-R.");
4921 }
Derek Tan740e1672017-06-27 14:56:27 -07004922 }
Derek Tan740e1672017-06-27 14:56:27 -07004923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004925 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4926 null /* workSource */);
4927 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 return response;
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004932 }
4933
4934 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004935 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4937 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004938 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4939 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4940 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004941
Jordan Liu4c733742019-02-28 12:03:40 -08004942 @Override
4943 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4944 enforceModifyPermission();
4945 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4946 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4947 channel);
4948 }
4949
4950 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
4952 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 if (channel < 0) {
4954 return false;
4955 }
Jordan Liu4c733742019-02-28 12:03:40 -08004956 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4957 null /* workSource */);
4958 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 return success;
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004962 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004963 }
4964
4965 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004966 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004967 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4969 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004970 if (DBG) {
4971 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4972 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4973 + p3 + " data=" + data);
4974 }
4975 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4976 command, p1, p2, p3, data);
4977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978
Jordan Liu4c733742019-02-28 12:03:40 -08004979 @Override
4980 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4981 int command, int p1, int p2, int p3, String data) {
4982 enforceModifyPermission();
4983 if (DBG) {
4984 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4985 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4986 + p3 + " data=" + data);
4987 }
4988 return iccTransmitApduLogicalChannelWithPermission(
4989 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4990 data);
4991 }
4992
4993 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4994 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004997 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 return "";
4999 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005002 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5003 null /* workSource */);
5004 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 // Append the returned status code to the end of the response payload.
5007 String s = Integer.toHexString(
5008 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5009 if (response.payload != null) {
5010 s = IccUtils.bytesToHexString(response.payload) + s;
5011 }
5012 return s;
5013 } finally {
5014 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005015 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005016 }
Jake Hambye994d462014-02-03 13:10:13 -08005017
Evan Charltonc66da362014-05-16 14:06:40 -07005018 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005019 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5020 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005024 if (DBG) {
5025 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5026 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5027 }
5028 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5029 cla, command, p1, p2, p3, data);
5030 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005031
Jordan Liu4c733742019-02-28 12:03:40 -08005032 @Override
5033 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5034 int command, int p1, int p2, int p3, String data) {
5035 enforceModifyPermission();
5036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5037 if (DBG) {
5038 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5039 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5040 + " data=" + data);
5041 }
5042
5043 return iccTransmitApduBasicChannelWithPermission(
5044 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5045 p2, p3, data);
5046 }
5047
5048 // open APDU basic channel assuming the caller has sufficient permissions
5049 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5050 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5054 && TextUtils.equals(ISDR_AID, data)) {
5055 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005056 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5057 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 if (bestComponent == null
5059 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5060 loge("The calling package is not allowed to select ISD-R.");
5061 throw new SecurityException(
5062 "The calling package is not allowed to select ISD-R.");
5063 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005064 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005067 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5068 null /* workSource */);
5069 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 // Append the returned status code to the end of the response payload.
5072 String s = Integer.toHexString(
5073 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5074 if (response.payload != null) {
5075 s = IccUtils.bytesToHexString(response.payload) + s;
5076 }
5077 return s;
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005080 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005081 }
5082
5083 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005084 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005085 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5087 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 if (DBG) {
5092 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5093 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5094 }
5095
5096 IccIoResult response =
5097 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5098 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5099 subId);
5100
5101 if (DBG) {
5102 log("Exchange SIM_IO [R]" + response);
5103 }
5104
5105 byte[] result = null;
5106 int length = 2;
5107 if (response.payload != null) {
5108 length = 2 + response.payload.length;
5109 result = new byte[length];
5110 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5111 } else {
5112 result = new byte[length];
5113 }
5114
5115 result[length - 1] = (byte) response.sw2;
5116 result[length - 2] = (byte) response.sw1;
5117 return result;
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005120 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005121 }
5122
Nathan Haroldb3014052017-01-25 15:57:32 -08005123 /**
5124 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5125 * on a particular subscription
5126 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005127 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5128 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005130 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005131 return null;
5132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133
5134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 if (appType != TelephonyManager.APPTYPE_USIM
5137 && appType != TelephonyManager.APPTYPE_SIM) {
5138 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5139 return null;
5140 }
5141 Object response = sendRequest(
5142 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5143 if (response instanceof String[]) {
5144 return (String[]) response;
5145 }
yincheng zhao2737e882019-09-06 17:06:54 -07005146 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005148 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005151 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005152 }
5153
yincheng zhao2737e882019-09-06 17:06:54 -07005154 /**
5155 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5156 * subscription.
5157 *
5158 * @param subId the id of the subscription.
5159 * @param appType the uicc app type, must be USIM or SIM.
5160 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5161 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005162 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005163 * @return number of fplmns that is successfully written to the SIM.
5164 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5166 String callingFeatureId) {
5167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5168 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005169 if (DBG) logv("no permissions for setForbiddenplmns");
5170 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5171 }
5172 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5173 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5174 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5175 }
5176 if (fplmns == null) {
5177 throw new IllegalArgumentException("Fplmn List provided is null");
5178 }
5179 for (String fplmn : fplmns) {
5180 if (!CellIdentity.isValidPlmn(fplmn)) {
5181 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5182 }
5183 }
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 Object response = sendRequest(
5187 CMD_SET_FORBIDDEN_PLMNS,
5188 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5189 subId);
5190 return (int) response;
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
5194 }
5195
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005196 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005197 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5199 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5204 if (response.payload == null) {
5205 return "";
5206 }
Evan Charltonc66da362014-05-16 14:06:40 -07005207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 // Append the returned status code to the end of the response payload.
5209 String s = Integer.toHexString(
5210 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5211 s = IccUtils.bytesToHexString(response.payload) + s;
5212 return s;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Evan Charltonc66da362014-05-16 14:06:40 -07005216 }
5217
Jake Hambye994d462014-02-03 13:10:13 -08005218 /**
5219 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5220 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5221 *
5222 * @param itemID the ID of the item to read
5223 * @return the NV item as a String, or null on error.
5224 */
5225 @Override
5226 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005227 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230
5231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005234 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5236 return value;
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Jake Hambye994d462014-02-03 13:10:13 -08005240 }
5241
5242 /**
5243 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5244 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5245 *
5246 * @param itemID the ID of the item to read
5247 * @param itemValue the value to write, as a String
5248 * @return true on success; false on any failure
5249 */
5250 @Override
5251 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005252 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5254 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255
5256 final long identity = Binder.clearCallingIdentity();
5257 try {
5258 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5259 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005260 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5262 return success;
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Jake Hambye994d462014-02-03 13:10:13 -08005266 }
5267
5268 /**
5269 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5270 * Used for device configuration by some CDMA operators.
5271 *
5272 * @param preferredRoamingList byte array containing the new PRL
5273 * @return true on success; false on any failure
5274 */
5275 @Override
5276 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5278 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5283 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5284 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5285 return success;
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Jake Hambye994d462014-02-03 13:10:13 -08005289 }
5290
5291 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005292 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005293 * Used for device configuration by some CDMA operators.
5294 *
chen xu6dac5ab2018-10-26 17:39:23 -07005295 * @param slotIndex - device slot.
5296 *
Jake Hambye994d462014-02-03 13:10:13 -08005297 * @return true on success; false on any failure
5298 */
5299 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005300 public boolean resetModemConfig(int slotIndex) {
5301 Phone phone = PhoneFactory.getPhone(slotIndex);
5302 if (phone != null) {
5303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5304 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305
chen xu6dac5ab2018-10-26 17:39:23 -07005306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5309 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5310 return success;
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 }
chen xu6dac5ab2018-10-26 17:39:23 -07005315 return false;
5316 }
5317
5318 /**
5319 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5320 *
5321 * @param slotIndex - device slot.
5322 *
5323 * @return true on success; false on any failure
5324 */
5325 @Override
5326 public boolean rebootModem(int slotIndex) {
5327 Phone phone = PhoneFactory.getPhone(slotIndex);
5328 if (phone != null) {
5329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5330 mApp, phone.getSubId(), "rebootModem");
5331
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5335 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5336 return success;
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
5340 }
5341 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005342 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005343
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005344 public String[] getPcscfAddress(String apnType, String callingPackage,
5345 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005346 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5348 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005349 return new String[0];
5350 }
5351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 final long identity = Binder.clearCallingIdentity();
5353 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005354 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
Wink Saville36469e72014-06-11 15:17:00 -07005358 }
5359
Brad Ebinger51f743a2017-01-23 13:50:20 -08005360 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005361 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5362 * {@link #disableIms(int)}.
5363 * @param slotIndex device slot.
5364 */
5365 public void resetIms(int slotIndex) {
5366 enforceModifyPermission();
5367
5368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 if (mImsResolver == null) {
5371 // may happen if the does not support IMS.
5372 return;
5373 }
5374 mImsResolver.disableIms(slotIndex);
5375 mImsResolver.enableIms(slotIndex);
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
5378 }
5379 }
5380
5381 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005382 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5383 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005384 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005385 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005386 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387
5388 final long identity = Binder.clearCallingIdentity();
5389 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005390 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005391 // may happen if the device does not support IMS.
5392 return;
5393 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005394 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005398 }
5399
5400 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005401 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5402 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005403 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005404 public void disableIms(int slotId) {
5405 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406
5407 final long identity = Binder.clearCallingIdentity();
5408 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005409 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005410 // may happen if the device does not support IMS.
5411 return;
5412 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005413 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005417 }
5418
5419 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005420 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5421 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005422 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005423 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005424 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005425 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426
5427 final long identity = Binder.clearCallingIdentity();
5428 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005429 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005430 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5431 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005432 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005433 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005437 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005438 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005439 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5440 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005441 @Override
5442 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005443 enforceModifyPermission();
5444
5445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005448 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453
5454 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005455 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005456 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005457 */
5458 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005463 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005464 // may happen if the device does not support IMS.
5465 return null;
5466 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005467 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005471 }
5472
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005473 /**
5474 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005475 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005476 */
5477 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005482 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005483 // may happen if the device does not support IMS.
5484 return null;
5485 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005486 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005490 }
5491
Brad Ebinger884c07b2018-02-15 16:17:40 -08005492 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005493 * Sets the ImsService Package Name that Telephony will bind to.
5494 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005495 * @param slotIndex the slot ID that the ImsService should bind for.
5496 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005497 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005498 * @param featureTypes An integer array of feature types associated with a packageName.
5499 * @param packageName The name of the package that the current configuration will be replaced
5500 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005501 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005502 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005503 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5504 int[] featureTypes, String packageName) {
5505 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5506 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5508 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005509 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 final long identity = Binder.clearCallingIdentity();
5512 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005513 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005514 // may happen if the device does not support IMS.
5515 return false;
5516 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005517 Map<Integer, String> featureConfig = new HashMap<>();
5518 for (int featureType : featureTypes) {
5519 featureConfig.put(featureType, packageName);
5520 }
5521 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5522 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005526 }
5527
5528 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005529 * Clears any carrier ImsService overrides for the slot index specified that were previously
5530 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5531 *
5532 * This should only be used for testing.
5533 *
5534 * @param slotIndex the slot ID that the ImsService should bind for.
5535 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5536 */
5537 @Override
5538 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5539 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5541 "clearCarrierImsServiceOverride");
5542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5543 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5544 "clearCarrierImsServiceOverride");
5545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 if (mImsResolver == null) {
5549 // may happen if the device does not support IMS.
5550 return false;
5551 }
5552 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
5556 }
5557
5558 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005559 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005560 *
5561 * @param slotId The slot that the ImsService is associated with.
5562 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5563 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005564 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005565 * @return the package name of the ImsService configuration.
5566 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005567 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5568 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005569 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005570 TelephonyPermissions
5571 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5572 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5573 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 final long identity = Binder.clearCallingIdentity();
5576 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005577 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005578 // may happen if the device does not support IMS.
5579 return "";
5580 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005581 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005582 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5583 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005587 }
5588
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005589 /**
5590 * Get the MmTelFeature state associated with the requested subscription id.
5591 * @param subId The subscription that the MmTelFeature is associated with.
5592 * @param callback A callback with an integer containing the
5593 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5594 */
5595 @Override
5596 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5597 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5598 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5600 "IMS not available on device.");
5601 }
5602 final long token = Binder.clearCallingIdentity();
5603 try {
5604 int slotId = getSlotIndex(subId);
5605 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5606 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5607 + subId + "'");
5608 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5609 }
5610 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5611 try {
5612 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5613 } catch (RemoteException e) {
5614 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5615 + "Ignore");
5616 }
5617 });
5618 } finally {
5619 Binder.restoreCallingIdentity(token);
5620 }
5621 }
5622
Daniel Brightbb5840b2021-01-12 15:48:18 -08005623 /**
5624 * Sets the ims registration state on all valid {@link Phone}s.
5625 */
5626 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005631 // NOTE: Before S, this method only set the default phone.
5632 for (final Phone phone : PhoneFactory.getPhones()) {
5633 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5634 phone.setImsRegistrationState(registered);
5635 }
5636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Wink Saville36469e72014-06-11 15:17:00 -07005640 }
5641
5642 /**
Stuart Scott54788802015-03-30 13:18:01 -07005643 * Set the network selection mode to automatic.
5644 *
5645 */
5646 @Override
5647 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650
5651 final long identity = Binder.clearCallingIdentity();
5652 try {
shilufc958392020-01-20 11:36:01 -08005653 if (!isActiveSubscription(subId)) {
5654 return;
5655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5657 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Stuart Scott54788802015-03-30 13:18:01 -07005661 }
5662
Jack Yud10cdd42020-09-28 20:28:01 -07005663 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005664 * Ask the radio to connect to the input network and change selection mode to manual.
5665 *
5666 * @param subId the id of the subscription.
5667 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5668 * the operator to attach to.
5669 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5670 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5671 * normal network selection next time.
5672 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005673 */
5674 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005675 public boolean setNetworkSelectionModeManual(
5676 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5678 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005679
5680 if (!isActiveSubscription(subId)) {
5681 return false;
5682 }
5683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 final long identity = Binder.clearCallingIdentity();
5685 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005686 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005688 if (DBG) {
5689 log("setNetworkSelectionModeManual: subId: " + subId
5690 + " operator: " + operatorInfo);
5691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005696 }
shilu84f6e8b2019-12-19 13:58:01 -08005697 /**
5698 * Get the manual network selection
5699 *
5700 * @param subId the id of the subscription.
5701 *
5702 * @return the previously saved user selected PLMN
5703 */
5704 @Override
5705 public String getManualNetworkSelectionPlmn(int subId) {
5706 TelephonyPermissions
5707 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5708 mApp, subId, "getManualNetworkSelectionPlmn");
5709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005713 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005714 }
5715
5716 final Phone phone = getPhone(subId);
5717 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005718 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005719 }
5720 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5721 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5722 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
5726 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005727
5728 /**
5729 * Scans for available networks.
5730 */
5731 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005732 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5735 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005736 LocationAccessPolicy.LocationPermissionResult locationResult =
5737 LocationAccessPolicy.checkLocationPermission(mApp,
5738 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5739 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005740 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005741 .setCallingPid(Binder.getCallingPid())
5742 .setCallingUid(Binder.getCallingUid())
5743 .setMethod("getCellNetworkScanResults")
5744 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005745 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5746 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005747 .build());
5748 switch (locationResult) {
5749 case DENIED_HARD:
5750 throw new SecurityException("Not allowed to access scan results -- location");
5751 case DENIED_SOFT:
5752 return null;
5753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
Pengquan Menga1bb6272018-09-06 09:59:22 -07005755 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 try {
5757 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005758 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005763 }
5764
5765 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005766 * Get the call forwarding info, given the call forwarding reason.
5767 */
5768 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005769 public void getCallForwarding(int subId, int callForwardingReason,
5770 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005771 enforceReadPrivilegedPermission("getCallForwarding");
5772 long identity = Binder.clearCallingIdentity();
5773 try {
5774 if (DBG) {
5775 log("getCallForwarding: subId " + subId
5776 + " callForwardingReason" + callForwardingReason);
5777 }
Hall Liu27d24262020-09-18 19:04:59 -07005778
5779 Phone phone = getPhone(subId);
5780 if (phone == null) {
5781 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005782 callback.onError(
5783 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005784 } catch (RemoteException e) {
5785 // ignore
5786 }
5787 return;
5788 }
5789
5790 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5791 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5792 @Override
5793 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5794 try {
5795 callback.onCallForwardingInfoAvailable(info);
5796 } catch (RemoteException e) {
5797 // ignore
5798 }
5799 }
5800
5801 @Override
5802 public void onError(int error) {
5803 try {
5804 callback.onError(error);
5805 } catch (RemoteException e) {
5806 // ignore
5807 }
5808 }
5809 });
5810 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
5814 }
5815
5816 /**
5817 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5818 * reason, the number to forward, and the timeout before the forwarding is attempted.
5819 */
5820 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005821 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5822 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005823 enforceModifyPermission();
5824 long identity = Binder.clearCallingIdentity();
5825 try {
5826 if (DBG) {
5827 log("setCallForwarding: subId " + subId
5828 + " callForwardingInfo" + callForwardingInfo);
5829 }
Hall Liu27d24262020-09-18 19:04:59 -07005830
5831 Phone phone = getPhone(subId);
5832 if (phone == null) {
5833 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005834 callback.accept(
5835 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005836 } catch (RemoteException e) {
5837 // ignore
5838 }
5839 return;
5840 }
5841
5842 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5843 FunctionalUtils.ignoreRemoteException(callback::accept));
5844
5845 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
5850
5851 /**
Hall Liu27d24262020-09-18 19:04:59 -07005852 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005853 */
5854 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005855 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005856 enforceReadPrivilegedPermission("getCallForwarding");
5857 long identity = Binder.clearCallingIdentity();
5858 try {
Hall Liu27d24262020-09-18 19:04:59 -07005859
5860 Phone phone = getPhone(subId);
5861 if (phone == null) {
5862 try {
5863 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5864 } catch (RemoteException e) {
5865 // ignore
5866 }
5867 return;
5868 }
5869
5870 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5871
Shuo Qian4a594052020-01-23 11:59:30 -08005872 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005873 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
5877 }
5878
5879 /**
Hall Liu27d24262020-09-18 19:04:59 -07005880 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005881 */
5882 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005883 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005884 enforceModifyPermission();
5885 long identity = Binder.clearCallingIdentity();
5886 try {
Hall Liu27d24262020-09-18 19:04:59 -07005887 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5888
5889 Phone phone = getPhone(subId);
5890 if (phone == null) {
5891 try {
5892 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5893 } catch (RemoteException e) {
5894 // ignore
5895 }
5896 return;
5897 }
5898
5899 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5900 FunctionalUtils.ignoreRemoteException(callback::accept));
5901
5902 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
5907
5908 /**
yinxub1bed742017-04-17 11:45:04 -07005909 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005910 *
yinxub1bed742017-04-17 11:45:04 -07005911 * @param subId id of the subscription
5912 * @param request contains the radio access networks with bands/channels to scan
5913 * @param messenger callback messenger for scan results or errors
5914 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005915 * @return the id of the requested scan which can be used to stop the scan.
5916 */
5917 @Override
5918 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005919 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5921 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005922 LocationAccessPolicy.LocationPermissionResult locationResult =
5923 LocationAccessPolicy.checkLocationPermission(mApp,
5924 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5925 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005926 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005927 .setCallingPid(Binder.getCallingPid())
5928 .setCallingUid(Binder.getCallingUid())
5929 .setMethod("requestNetworkScan")
5930 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005931 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5932 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005933 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005934 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005935 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5936 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005937 if (e != null) {
5938 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5939 throw e;
5940 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005941 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005942 return TelephonyScanManager.INVALID_SCAN_ID;
5943 }
5944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 }
Hall Liu912dfd32019-04-25 14:02:26 -07005946 int callingUid = Binder.getCallingUid();
5947 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005948 final long identity = Binder.clearCallingIdentity();
5949 try {
5950 return mNetworkScanRequestTracker.startNetworkScan(
5951 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005952 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
yinxu504e1392017-04-12 16:03:22 -07005956 }
5957
Hall Liub2ac8ef2019-02-28 15:56:23 -08005958 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005959 NetworkScanRequest request, int subId, String callingPackage) {
5960 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005961 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5962 boolean hasNetworkScanPermission =
5963 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5964 == PERMISSION_GRANTED;
5965
5966 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5967 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5968 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005969 }
5970
5971 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5972 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005973 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5974 return new SecurityException("Specific channels must not be"
5975 + " scanned without location access.");
5976 }
5977 }
5978 }
5979
Hall Liub2ac8ef2019-02-28 15:56:23 -08005980 return null;
5981 }
5982
yinxu504e1392017-04-12 16:03:22 -07005983 /**
5984 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005985 *
5986 * @param subId id of the subscription
5987 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005988 */
5989 @Override
5990 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5992 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993
Hall Liu912dfd32019-04-25 14:02:26 -07005994 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 final long identity = Binder.clearCallingIdentity();
5996 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005997 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
yinxu504e1392017-04-12 16:03:22 -07006001 }
6002
6003 /**
Junda Liu84d15a22014-07-02 11:21:04 -07006004 * Get the calculated preferred network type.
6005 * Used for debugging incorrect network type.
6006 *
6007 * @return the preferred network type, defined in RILConstants.java.
6008 */
6009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006010 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006011 final Phone defaultPhone = getDefaultPhone();
6012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006013 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006014 return RILConstants.PREFERRED_NETWORK_MODE;
6015 }
6016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006020 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
Junda Liu84d15a22014-07-02 11:21:04 -07006024 }
6025
6026 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08006027 * Get the preferred network type.
6028 * Used for device configuration by some CDMA operators.
6029 *
6030 * @return the preferred network type, defined in RILConstants.java.
6031 */
6032 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006033 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006034 TelephonyPermissions
6035 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6036 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037
6038 final long identity = Binder.clearCallingIdentity();
6039 try {
6040 if (DBG) log("getPreferredNetworkType");
6041 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6042 int networkType = (result != null ? result[0] : -1);
6043 if (DBG) log("getPreferredNetworkType: " + networkType);
6044 return networkType;
6045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006048 }
6049
6050 /**
6051 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006052 *
6053 * @param networkType the preferred network type, defined in RILConstants.java.
6054 * @return true on success; false on any failure.
6055 */
6056 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006057 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6059 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
calvinpan8ed33732020-03-12 14:17:55 +08006063 Boolean success = (Boolean) sendRequest(
6064 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006065
6066 if (success) {
6067 Settings.Global.putInt(mApp.getContentResolver(),
6068 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6069 }
calvinpan8ed33732020-03-12 14:17:55 +08006070 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6071 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006074 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006075 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006076
6077 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08006078 * Get the allowed network types that store in the telephony provider.
6079 *
6080 * @param subId the id of the subscription.
6081 * @return allowedNetworkTypes the allowed network types.
6082 */
6083 @Override
6084 public long getAllowedNetworkTypes(int subId) {
6085 TelephonyPermissions
6086 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6087 mApp, subId, "getAllowedNetworkTypes");
6088
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 return SubscriptionManager.getLongSubscriptionProperty(
6092 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
6096 }
6097
6098 /**
6099 * Set the allowed network types.
6100 *
6101 * @param subId the id of the subscription.
6102 * @param allowedNetworkTypes the allowed network types.
6103 * @return true on success; false on any failure.
6104 */
6105 @Override
6106 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6108 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08006109
calvinpan8ed33732020-03-12 14:17:55 +08006110 SubscriptionManager.setSubscriptionProperty(subId,
6111 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6112 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08006113
calvinpan8ed33732020-03-12 14:17:55 +08006114 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6115 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6116 RILConstants.PREFERRED_NETWORK_MODE);
6117 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08006118 }
6119
6120 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006121 * Get the allowed network types for certain reason.
6122 *
6123 * @param subId the id of the subscription.
6124 * @param reason the reason the allowed network type change is taking place
6125 * @return the allowed network types.
6126 */
6127 @Override
6128 public long getAllowedNetworkTypesForReason(int subId,
6129 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6130 TelephonyPermissions
6131 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6132 mApp, subId, "getAllowedNetworkTypesForReason");
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006142 * Enable/Disable E-UTRA-NR Dual Connectivity
6143 * @param subId subscription id of the sim card
6144 * @param nrDualConnectivityState expected NR dual connectivity state
6145 * This can be passed following states
6146 * <ol>
6147 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6148 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6149 * <li>Disable NR dual connectivity and force secondary cell to be released
6150 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6151 * </ol>
6152 * @return operation result.
6153 */
6154 @Override
6155 public int setNrDualConnectivityState(int subId,
6156 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, subId, "enableNRDualConnectivity");
6159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6163 nrDualConnectivityState, subId,
6164 workSource);
6165 if (DBG) log("enableNRDualConnectivity result: " + result);
6166 return result;
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
6170 }
6171
6172 /**
6173 * Is E-UTRA-NR Dual Connectivity enabled
6174 * @return true if dual connectivity is enabled else false
6175 */
6176 @Override
6177 public boolean isNrDualConnectivityEnabled(int subId) {
6178 TelephonyPermissions
6179 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6180 mApp, subId, "isNRDualConnectivityEnabled");
6181 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6185 null, subId, workSource);
6186 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6187 return isEnabled;
6188 } finally {
6189 Binder.restoreCallingIdentity(identity);
6190 }
6191 }
6192
6193 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006194 * get carrier bandwidth per primary and secondary carrier
6195 * @param subId subscription id of the sim card
6196 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6197 */
6198 @Override
6199 public CarrierBandwidth getCarrierBandwidth(int subId) {
6200 TelephonyPermissions
6201 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6202 mApp, subId, "isNRDualConnectivityEnabled");
6203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
6206 CarrierBandwidth carrierBandwidth =
6207 getPhoneFromSubId(subId).getCarrierBandwidth();
6208 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6209 return carrierBandwidth;
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006216 * Get the effective allowed network types on the device.
6217 * This API will return an intersection of allowed network types for all reasons,
6218 * including the configuration done through setAllowedNetworkTypes
6219 *
6220 * @param subId the id of the subscription.
6221 * @return the allowed network types
6222 */
6223 @Override
6224 public long getEffectiveAllowedNetworkTypes(int subId) {
6225 TelephonyPermissions
6226 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6227 mApp, subId, "getEffectiveAllowedNetworkTypes");
6228 final long identity = Binder.clearCallingIdentity();
6229 try {
6230 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
6234 }
6235
6236 /**
6237 * Set the allowed network types of the device and
6238 * provide the reason triggering the allowed network change.
6239 *
6240 * @param subId the id of the subscription.
6241 * @param reason the reason the allowed network type change is taking place
6242 * @param allowedNetworkTypes the allowed network types.
6243 * @return true on success; false on any failure.
6244 */
6245 @Override
6246 public boolean setAllowedNetworkTypesForReason(int subId,
6247 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6249 mApp, subId, "setAllowedNetworkTypesForReason");
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6253 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6254 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6255 RILConstants.PREFERRED_NETWORK_MODE);
6256 return setPreferredNetworkType(subId, preferredNetworkMode);
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
6260 }
6261
6262 /**
Miaoa84611c2019-03-15 09:21:10 +08006263 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006264 *
Miaoa84611c2019-03-15 09:21:10 +08006265 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006266 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006267 * @hide
6268 */
6269 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006270 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006271 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006273 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 try {
Miaoa84611c2019-03-15 09:21:10 +08006275 if (phone != null) {
6276 return phone.hasMatchedTetherApnSetting();
6277 } else {
6278 return false;
6279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006282 }
Junda Liu475951f2014-11-07 16:45:03 -08006283 }
6284
6285 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006286 * Enable or disable always reporting signal strength changes from radio.
6287 *
6288 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6289 */
6290 @Override
6291 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6292 enforceModifyPermission();
6293 enforceSystemCaller();
6294
6295 final long identity = Binder.clearCallingIdentity();
6296 final Phone phone = getPhone(subId);
6297 try {
6298 if (phone != null) {
6299 if (DBG) {
6300 log("setAlwaysReportSignalStrength: subId=" + subId
6301 + " isEnable=" + isEnable);
6302 }
6303 phone.setAlwaysReportSignalStrength(isEnable);
6304 } else {
6305 loge("setAlwaysReportSignalStrength: no phone found for subId="
6306 + subId);
6307 }
6308 } finally {
6309 Binder.restoreCallingIdentity(identity);
6310 }
6311 }
6312
6313 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006314 * Get the user enabled state of Mobile Data.
6315 *
6316 * TODO: remove and use isUserDataEnabled.
6317 * This can't be removed now because some vendor codes
6318 * calls through ITelephony directly while they should
6319 * use TelephonyManager.
6320 *
6321 * @return true on enabled
6322 */
6323 @Override
6324 public boolean getDataEnabled(int subId) {
6325 return isUserDataEnabled(subId);
6326 }
6327
6328 /**
6329 * Get whether mobile data is enabled per user setting.
6330 *
6331 * There are other factors deciding whether mobile data is actually enabled, but they are
6332 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006333 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006334 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006335 *
6336 * @return {@code true} if data is enabled else {@code false}
6337 */
6338 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006339 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006340 try {
6341 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6342 null);
6343 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6345 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
6350 int phoneId = mSubscriptionController.getPhoneId(subId);
6351 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6352 Phone phone = PhoneFactory.getPhone(phoneId);
6353 if (phone != null) {
6354 boolean retVal = phone.isUserDataEnabled();
6355 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6356 return retVal;
6357 } else {
6358 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6359 return false;
6360 }
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006363 }
6364 }
6365
6366 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006367 * Checks if the device is capable of mobile data by considering whether whether the
6368 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6369 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006370 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006371 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006372 */
6373 @Override
6374 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006375 try {
6376 try {
6377 mApp.enforceCallingOrSelfPermission(
6378 android.Manifest.permission.ACCESS_NETWORK_STATE,
6379 null);
6380 } catch (Exception e) {
6381 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6382 "isDataEnabled");
6383 }
6384 } catch (Exception e) {
6385 enforceReadPrivilegedPermission("isDataEnabled");
6386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 int phoneId = mSubscriptionController.getPhoneId(subId);
6391 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6392 Phone phone = PhoneFactory.getPhone(phoneId);
6393 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006394 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6396 return retVal;
6397 } else {
6398 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6399 return false;
6400 }
6401 } finally {
6402 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006403 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006404 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006405
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006406 /**
6407 * Check if data is enabled for a specific reason
6408 * @param subId Subscription index
6409 * @param reason the reason the data enable change is taking place
6410 * @return {@code true} if the overall data is enabled; {@code false} if not.
6411 */
6412 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006413 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006414 @TelephonyManager.DataEnabledReason int reason) {
6415 try {
6416 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6417 null);
6418 } catch (Exception e) {
6419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006420 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006421 }
6422
6423
6424 final long identity = Binder.clearCallingIdentity();
6425 try {
6426 int phoneId = mSubscriptionController.getPhoneId(subId);
6427 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006428 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006429 + " reason=" + reason);
6430 }
6431 Phone phone = PhoneFactory.getPhone(phoneId);
6432 if (phone != null) {
6433 boolean retVal;
6434 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6435 retVal = phone.isUserDataEnabled();
6436 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006437 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006438 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006439 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006440 return retVal;
6441 } else {
6442 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006443 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006444 + subId + " retVal=false");
6445 }
6446 return false;
6447 }
6448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
6451 }
6452
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006453 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006454 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006455 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6456 // Skip the check if it's one of these special uids
6457 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6458 }
6459
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006460 //load access rules from carrier configs, and check those as well: b/139133814
6461 SubscriptionController subController = SubscriptionController.getInstance();
6462 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6463 || subController == null) return privilegeFromSim;
6464
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006465 PackageManager pkgMgr = phone.getContext().getPackageManager();
6466 String[] packages = pkgMgr.getPackagesForUid(uid);
6467
6468 final long identity = Binder.clearCallingIdentity();
6469 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006470 int subId = phone.getSubId();
6471 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6472 // A test override is in place for the privileges for this subId, so don't try to
6473 // read the subscription privileges.
6474 return privilegeFromSim;
6475 }
6476 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006477 SubscriptionManager subManager = (SubscriptionManager)
6478 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6479 for (String pkg : packages) {
6480 if (subManager.canManageSubscription(subInfo, pkg)) {
6481 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6482 }
6483 }
6484 return privilegeFromSim;
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
6490 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6491 String pkgName) {
6492 //load access rules from carrier configs, and check those as well: b/139133814
6493 SubscriptionController subController = SubscriptionController.getInstance();
6494 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6495 || subController == null) return privilegeFromSim;
6496
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006499 int subId = phone.getSubId();
6500 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6501 // A test override is in place for the privileges for this subId, so don't try to
6502 // read the subscription privileges.
6503 return privilegeFromSim;
6504 }
6505 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006506 SubscriptionManager subManager = (SubscriptionManager)
6507 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6508 return subManager.canManageSubscription(subInfo, pkgName)
6509 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
6513 }
6514
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006515 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006516 public int getCarrierPrivilegeStatus(int subId) {
6517 final Phone phone = getPhone(subId);
6518 if (phone == null) {
6519 loge("getCarrierPrivilegeStatus: Invalid subId");
6520 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6521 }
6522 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006523 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006524 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006525 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6526 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006527
6528 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6529 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006530 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006531 }
Junda Liu29340342014-07-10 15:23:27 -07006532
6533 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006534 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006535 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006536 final Phone phone = getPhone(subId);
6537 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006538 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006539 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6540 }
6541 UiccProfile profile =
6542 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6543 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006544 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006545 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6546 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006547 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006548 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006549 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006550 }
6551
6552 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006553 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6554 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006555 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006556 }
6557
6558 int phoneId = SubscriptionManager.getPhoneId(subId);
6559 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006560 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006561 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006562 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6563 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006564 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6565 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6566 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006567 }
6568
6569 @Override
6570 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006571 if (TextUtils.isEmpty(pkgName))
6572 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006573 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6574 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6575 UiccCard card = UiccController.getInstance().getUiccCard(i);
6576 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006577 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006578 continue;
6579 }
6580
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006581 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6582 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6583 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006584 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6585 break;
6586 }
6587 }
6588
6589 return result;
Junda Liu29340342014-07-10 15:23:27 -07006590 }
Derek Tan89e89d42014-07-08 17:00:10 -07006591
6592 @Override
Junda Liue64de782015-04-16 17:19:16 -07006593 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6594 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6595 loge("phoneId " + phoneId + " is not valid.");
6596 return null;
6597 }
6598 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006599 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006600 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006601 return null ;
6602 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006603 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006604 }
6605
Amith Yamasani6e118872016-02-19 12:53:51 -08006606 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006607 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006609 List<String> privilegedPackages = new ArrayList<>();
6610 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006611 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6612 // has UICC in that slot.
6613 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006614 if (card.hasCarrierPrivilegeRules()) {
6615 if (packages == null) {
6616 // Only check packages in user 0 for now
6617 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006618 PackageManager.MATCH_DISABLED_COMPONENTS
6619 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006620 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006621 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006622 }
6623 for (int p = packages.size() - 1; p >= 0; p--) {
6624 PackageInfo pkgInfo = packages.get(p);
6625 if (pkgInfo != null && pkgInfo.packageName != null
6626 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006627 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006628 privilegedPackages.add(pkgInfo.packageName);
6629 }
6630 }
6631 }
6632 }
6633 return privilegedPackages;
6634 }
6635
chen xuf7e9fe82019-05-09 19:31:02 -07006636 @Override
6637 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006638 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6639
6640 final long identity = Binder.clearCallingIdentity();
6641
chen xuf7e9fe82019-05-09 19:31:02 -07006642 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006643 try {
6644 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6645 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6646 }
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006649 }
6650 return privilegedPackages;
6651 }
6652
Wink Savilleb564aae2014-10-23 10:18:09 -07006653 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006654 final Phone phone = getPhone(subId);
6655 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006656 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006657 return null;
6658 }
6659 String iccId = card.getIccId();
6660 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006661 return null;
6662 }
6663 return iccId;
6664 }
6665
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006666 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006667 public void setCallComposerStatus(int subId, int status) {
6668 enforceModifyPermission();
6669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 Phone phone = getPhone(subId);
6673 if (phone != null) {
6674 Phone defaultPhone = phone.getImsPhone();
6675 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6676 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6677 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006678 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6679 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006680 }
6681 }
Shuo Qian284ae752020-12-22 19:10:14 -08006682 } catch (ImsException e) {
6683 throw new ServiceSpecificException(e.getCode());
6684 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006685 Binder.restoreCallingIdentity(identity);
6686 }
6687 }
6688
6689 @Override
6690 public int getCallComposerStatus(int subId) {
6691 enforceReadPrivilegedPermission("getCallComposerStatus");
6692
6693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 Phone phone = getPhone(subId);
6696 if (phone != null) {
6697 Phone defaultPhone = phone.getImsPhone();
6698 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6699 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6700 return imsPhone.getCallComposerStatus();
6701 }
6702 }
6703 } finally {
6704 Binder.restoreCallingIdentity(identity);
6705 }
6706 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6707 }
6708
6709 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006710 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6711 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006712 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006713 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
6717 final String iccId = getIccId(subId);
6718 final Phone phone = getPhone(subId);
6719 if (phone == null) {
6720 return false;
6721 }
6722 final String subscriberId = phone.getSubscriberId();
6723
6724 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006725 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 + subscriberId + " to " + number);
6727 }
6728
6729 if (TextUtils.isEmpty(iccId)) {
6730 return false;
6731 }
6732
6733 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6734
6735 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6736 if (alphaTag == null) {
6737 editor.remove(alphaTagPrefKey);
6738 } else {
6739 editor.putString(alphaTagPrefKey, alphaTag);
6740 }
6741
6742 // Record both the line number and IMSI for this ICCID, since we need to
6743 // track all merged IMSIs based on line number
6744 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6745 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6746 if (number == null) {
6747 editor.remove(numberPrefKey);
6748 editor.remove(subscriberPrefKey);
6749 } else {
6750 editor.putString(numberPrefKey, number);
6751 editor.putString(subscriberPrefKey, subscriberId);
6752 }
6753
6754 editor.commit();
6755 return true;
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006758 }
Derek Tan7226c842014-07-02 17:42:23 -07006759 }
6760
6761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006762 public String getLine1NumberForDisplay(int subId, String callingPackage,
6763 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006764 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006766 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006767 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006768 return null;
6769 }
Derek Tan97ebb422014-09-05 16:55:38 -07006770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 final long identity = Binder.clearCallingIdentity();
6772 try {
6773 String iccId = getIccId(subId);
6774 if (iccId != null) {
6775 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6776 if (DBG_MERGE) {
6777 log("getLine1NumberForDisplay returning "
6778 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6779 }
6780 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6783 return null;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006786 }
Derek Tan7226c842014-07-02 17:42:23 -07006787 }
6788
6789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6791 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006793 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006794 return null;
6795 }
Derek Tan97ebb422014-09-05 16:55:38 -07006796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
6798 try {
6799 String iccId = getIccId(subId);
6800 if (iccId != null) {
6801 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6802 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6803 }
6804 return null;
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006807 }
Derek Tan7226c842014-07-02 17:42:23 -07006808 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006809
6810 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006811 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6812 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006813 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6814 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006816 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006817 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006818 return null;
6819 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006820
Jordan Liub49b04b2019-05-06 14:45:15 -07006821 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6822 // the process, where TelephonyManager was instantiated.
6823 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006824 final long identity = Binder.clearCallingIdentity();
6825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006826 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 final TelephonyManager tele = TelephonyManager.from(context);
6828 final SubscriptionManager sub = SubscriptionManager.from(context);
6829
6830 // Figure out what subscribers are currently active
6831 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832
Jordan Liub49b04b2019-05-06 14:45:15 -07006833 // Only consider subs which match the current subId
6834 // This logic can be simplified. See b/131189269 for progress.
6835 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006836 activeSubscriberIds.add(tele.getSubscriberId(subId));
6837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838
6839 // First pass, find a number override for an active subscriber
6840 String mergeNumber = null;
6841 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6842 for (String key : prefs.keySet()) {
6843 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6844 final String subscriberId = (String) prefs.get(key);
6845 if (activeSubscriberIds.contains(subscriberId)) {
6846 final String iccId = key.substring(
6847 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6848 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6849 mergeNumber = (String) prefs.get(numberKey);
6850 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006851 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 + " for active subscriber " + subscriberId);
6853 }
6854 if (!TextUtils.isEmpty(mergeNumber)) {
6855 break;
6856 }
6857 }
6858 }
6859 }
6860
6861 // Shortcut when no active merged subscribers
6862 if (TextUtils.isEmpty(mergeNumber)) {
6863 return null;
6864 }
6865
6866 // Second pass, find all subscribers under that line override
6867 final ArraySet<String> result = new ArraySet<>();
6868 for (String key : prefs.keySet()) {
6869 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6870 final String number = (String) prefs.get(key);
6871 if (mergeNumber.equals(number)) {
6872 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6873 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6874 final String subscriberId = (String) prefs.get(subscriberKey);
6875 if (!TextUtils.isEmpty(subscriberId)) {
6876 result.add(subscriberId);
6877 }
6878 }
6879 }
6880 }
6881
6882 final String[] resultArray = result.toArray(new String[result.size()]);
6883 Arrays.sort(resultArray);
6884 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006885 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6887 }
6888 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006889 } finally {
6890 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006891 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006892 }
6893
6894 @Override
zoey chen38003472019-12-13 17:16:31 +08006895 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6896 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006897
6898 final long identity = Binder.clearCallingIdentity();
6899 try {
6900 final TelephonyManager telephonyManager = mApp.getSystemService(
6901 TelephonyManager.class);
6902 String subscriberId = telephonyManager.getSubscriberId(subId);
6903 if (subscriberId == null) {
6904 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006905 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006906 + subId);
6907 }
6908 return null;
6909 }
6910
6911 final SubscriptionInfo info = SubscriptionController.getInstance()
6912 .getSubscriptionInfo(subId);
6913 final ParcelUuid groupUuid = info.getGroupUuid();
6914 // If it doesn't belong to any group, return just subscriberId of itself.
6915 if (groupUuid == null) {
6916 return new String[]{subscriberId};
6917 }
6918
6919 // Get all subscriberIds from the group.
6920 final List<String> mergedSubscriberIds = new ArrayList<>();
6921 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006922 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006923 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006924 for (SubscriptionInfo subInfo : groupInfos) {
6925 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6926 if (subscriberId != null) {
6927 mergedSubscriberIds.add(subscriberId);
6928 }
6929 }
6930
6931 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
6934
6935 }
6936 }
6937
6938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006939 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006940 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006941 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942
6943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 final Phone phone = getPhone(subId);
6946 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006950 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006951
6952 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006953 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006954 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6955 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006956 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6957 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958
6959 final long identity = Binder.clearCallingIdentity();
6960 try {
6961 final Phone phone = getPhone(subId);
6962 if (phone == null) {
6963 return false;
6964 }
6965 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6966 cdmaNonRoamingList);
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006969 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006970 }
6971
6972 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006973 @Deprecated
6974 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6975 enforceModifyPermission();
6976
6977 int returnValue = 0;
6978 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006979 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006980 if(result.exception == null) {
6981 if (result.result != null) {
6982 byte[] responseData = (byte[])(result.result);
6983 if(responseData.length > oemResp.length) {
6984 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6985 responseData.length + "bytes. Buffer Size is " +
6986 oemResp.length + "bytes.");
6987 }
6988 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6989 returnValue = responseData.length;
6990 }
6991 } else {
6992 CommandException ex = (CommandException) result.exception;
6993 returnValue = ex.getCommandError().ordinal();
6994 if(returnValue > 0) returnValue *= -1;
6995 }
6996 } catch (RuntimeException e) {
6997 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6998 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6999 if(returnValue > 0) returnValue *= -1;
7000 }
7001
7002 return returnValue;
7003 }
7004
7005 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07007006 public void setRadioCapability(RadioAccessFamily[] rafs) {
7007 try {
7008 ProxyController.getInstance().setRadioCapability(rafs);
7009 } catch (RuntimeException e) {
7010 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
7011 }
7012 }
7013
7014 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007015 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007016 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007017 try {
7018 TelephonyPermissions
7019 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7020 mApp, phone.getSubId(), "getRadioAccessFamily");
7021 } catch (SecurityException e) {
7022 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7023 throw e;
7024 }
chen xub97461a2018-10-26 14:17:57 -07007025 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007026 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007027 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
chen xub97461a2018-10-26 14:17:57 -07007031 TelephonyPermissions
7032 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7033 mApp, phone.getSubId(), "getRadioAccessFamily");
7034 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
chen xub97461a2018-10-26 14:17:57 -07007038 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007039 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007040
7041 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007042 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007043 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007044 try {
7045 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7046 Binder.getCallingUid())) {
7047 throw new SecurityException("Package uid and package name do not match: "
7048 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7049 }
7050 } catch (PackageManager.NameNotFoundException e) {
7051 throw new SecurityException("Package name invalid:" + callingPackage);
7052 }
7053 RoleManager rm = mApp.getSystemService(RoleManager.class);
7054 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7055 if (!dialerRoleHolders.contains(callingPackage)) {
7056 throw new SecurityException("App must be the dialer role holder to"
7057 + " upload a call composer pic");
7058 }
7059
7060 Executors.newSingleThreadExecutor().execute(() -> {
7061 ByteArrayOutputStream output = new ByteArrayOutputStream(
7062 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7063 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7064 boolean readUntilEnd = false;
7065 int totalBytesRead = 0;
7066 byte[] buffer = new byte[16 * 1024];
7067 while (true) {
7068 int numRead;
7069 try {
7070 numRead = input.read(buffer);
7071 } catch (IOException e) {
7072 try {
7073 fd.checkError();
7074 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7075 null);
7076 } catch (IOException e1) {
7077 // This means that the other side closed explicitly with an error. If this
7078 // happens, log and ignore.
7079 loge("Remote end of call composer picture pipe closed: " + e1);
7080 }
7081 break;
7082 }
7083 if (numRead == -1) {
7084 readUntilEnd = true;
7085 break;
7086 }
7087 totalBytesRead += numRead;
7088 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7089 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7090 try {
7091 input.close();
7092 } catch (IOException e) {
7093 // ignore
7094 }
7095 break;
7096 }
7097 output.write(buffer, 0, numRead);
7098 }
7099 // Generally, the remote end will close the file descriptors. The only case where we
7100 // close is above, where the picture size is too big.
7101
7102 try {
7103 fd.checkError();
7104 } catch (IOException e) {
7105 loge("Remote end for call composer closed with an error: " + e);
7106 return;
7107 }
7108
7109 // TODO: pass along the bytes read to the carrier somehow
7110
7111 ParcelUuid result = new ParcelUuid(UUID.randomUUID());
7112 // TODO: cache this uuid that's been associated with the picture
7113 Bundle outputResult = new Bundle();
7114 outputResult.putParcelable(TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, result);
7115 callback.send(-1, outputResult);
7116 });
7117 }
7118
7119 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007120 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007126 ImsManager.getInstance(defaultPhone.getContext(),
7127 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007131 }
7132
7133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007134 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007135 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7137 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007138 return false;
7139 }
Svet Ganovb320e182015-04-16 12:30:10 -07007140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 // Check the user preference and the system-level IMS setting. Even if the user has
7144 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7145 // In the long run, we may instead need to check if there exists a connection service
7146 // which can support video calling.
7147 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007148 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 return imsManager.isVtEnabledByPlatform()
7150 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7151 && imsManager.isVtEnabledByUser();
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007155 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007156
Andrew Leea1239f22015-03-02 17:44:07 -08007157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007158 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7159 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007161 mApp, subId, callingPackage, callingFeatureId,
7162 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 return false;
7164 }
7165
7166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 CarrierConfigManager configManager =
7169 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007170 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
Andrew Leea1239f22015-03-02 17:44:07 -08007175 }
7176
7177 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007180 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 return false;
7182 }
7183
7184 final long identity = Binder.clearCallingIdentity();
7185 try {
7186 CarrierConfigManager configManager =
7187 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007188 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
Andrew Leea1239f22015-03-02 17:44:07 -08007193 }
7194
Andrew Lee9431b832015-03-09 18:46:45 -07007195 @Override
7196 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007197 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007198 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007199 }
7200
7201 @Override
7202 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 final long identity = Binder.clearCallingIdentity();
7204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007205 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
Andrew Lee9431b832015-03-09 18:46:45 -07007209 }
7210
Hall Liuf6668912018-10-31 17:05:23 -07007211 /**
7212 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7213 * support for the feature and device firmware support.
7214 *
7215 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7216 */
7217 @Override
7218 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007220 final Phone phone = getPhone(subscriptionId);
7221 if (phone == null) {
7222 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7223 return false;
7224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007226 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7228 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007229 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 return isCarrierSupported && isDeviceSupported;
7231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
Hall Liu98187582018-01-22 19:15:32 -08007234 }
7235
Hall Liuf6668912018-10-31 17:05:23 -07007236 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007237 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7238 * RTT setting, will return true if the device and carrier both support RTT.
7239 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007240 */
7241 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 final long identity = Binder.clearCallingIdentity();
7243 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007244 boolean isRttSupported = isRttSupported(subscriptionId);
7245 boolean isUserRttSettingOn = Settings.Secure.getInt(
7246 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7247 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7248 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7249 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007253 }
7254
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007255 @Deprecated
7256 @Override
7257 public String getDeviceId(String callingPackage) {
7258 return getDeviceIdWithFeature(callingPackage, null);
7259 }
7260
Sanket Padawe7310cc72015-01-14 09:53:20 -08007261 /**
7262 * Returns the unique device ID of phone, for example, the IMEI for
7263 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7264 *
7265 * <p>Requires Permission:
7266 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7267 */
7268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007269 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007270 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007272 return null;
7273 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007274 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007275 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007276 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007277 return null;
7278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279
7280 final long identity = Binder.clearCallingIdentity();
7281 try {
7282 return phone.getDeviceId();
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
7285 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007286 }
7287
Ping Sunc67b7c22016-03-02 19:16:45 +08007288 /**
7289 * {@hide}
7290 * Returns the IMS Registration Status on a particular subid
7291 *
7292 * @param subId
7293 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007294 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007295 Phone phone = getPhone(subId);
7296 if (phone != null) {
7297 return phone.isImsRegistered();
7298 } else {
7299 return false;
7300 }
7301 }
7302
Santos Cordon7a1885b2015-02-03 11:15:19 -08007303 @Override
7304 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
7310 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007311 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007312
Tyler Gunnf70ed162019-04-03 15:28:53 -07007313 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007314 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007315 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007317 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007318 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7319 }
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
7327
7328 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007329 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007330 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7331 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 Phone phone = getPhone(subscriptionId);
7335 if (phone == null) {
7336 return null;
7337 }
7338 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
7342 }
7343
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007344 /**
7345 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007346 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007347 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 Phone phone = getPhone(subId);
7351 if (phone != null) {
7352 return phone.isWifiCallingEnabled();
7353 } else {
7354 return false;
7355 }
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007358 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007359 }
7360
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007361 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007362 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007363 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007364 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Phone phone = getPhone(subId);
7368 if (phone != null) {
7369 return phone.isVideoEnabled();
7370 } else {
7371 return false;
7372 }
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007375 }
7376 }
7377
7378 /**
7379 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7380 * defined in {@link ImsRegistrationImplBase}.
7381 */
7382 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final long identity = Binder.clearCallingIdentity();
7384 try {
7385 Phone phone = getPhone(subId);
7386 if (phone != null) {
7387 return phone.getImsRegistrationTech();
7388 } else {
7389 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7390 }
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007393 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007394 }
7395
Stuart Scott8eef64f2015-04-08 15:13:54 -07007396 @Override
7397 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007398 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007399 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7400 return;
7401 }
7402
Svet Ganovcc087f82015-05-12 20:35:54 -07007403 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007404
Svet Ganovcc087f82015-05-12 20:35:54 -07007405 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007406 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7407 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007408 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007409 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007410 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007411 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7413 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007414 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007415 // There has been issues when Sms raw table somehow stores orphan
7416 // fragments. They lead to garbled message when new fragments come
7417 // in and combined with those stale ones. In case this happens again,
7418 // user can reset all network settings which will clean up this table.
7419 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007420 // Clean up IMS settings as well here.
7421 int slotId = getSlotIndex(subId);
7422 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7423 ImsManager.getInstance(mApp, slotId).factoryReset();
7424 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007425
7426 // Erase modem config if erase modem on network setting is enabled.
7427 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7428 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7429 if (configValue != null && Boolean.parseBoolean(configValue)) {
7430 sendEraseModemConfig(getDefaultPhone());
7431 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007434 }
7435 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007436
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007437 private void cleanUpSmsRawTable(Context context) {
7438 ContentResolver resolver = context.getContentResolver();
7439 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7440 resolver.delete(uri, null, null);
7441 }
7442
Narayan Kamath1c496c22015-04-16 14:40:19 +01007443 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007444 public String getSimLocaleForSubscriber(int subId) {
7445 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7446 final Phone phone = getPhone(subId);
7447 if (phone == null) {
7448 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007449 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
chen xu5d3637b2019-01-21 23:31:38 -08007453 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007454 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007455 if (info == null) {
7456 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7457 return null;
7458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 // Try and fetch the locale from the carrier properties or from the SIM language
7460 // preferences (EF-PL and EF-LI)...
7461 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007463 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7464 if (localeFromDefaultSim != null) {
7465 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7466 if (DBG) log("Using locale from subId: " + subId + " locale: "
7467 + localeFromDefaultSim);
7468 return localeFromDefaultSim.toLanguageTag();
7469 } else {
7470 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 }
7472 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 // The SIM language preferences only store a language (e.g. fr = French), not an
7475 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7476 // the SIM and carrier preferences does not include a country we add the country
7477 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007478 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007480 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 return mccLocale.toLanguageTag();
7482 }
7483
7484 if (DBG) log("No locale found - returning null");
7485 return null;
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007489 }
7490
7491 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007493 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007494 }
7495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 /**
7497 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7498 */
7499 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007501 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007502 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007503
Chenjie Yu1ba97252018-01-11 18:16:20 -08007504 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007505 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007506
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007507 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007508 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7509 * representing the state of the modem.
7510 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007511 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7512 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007513 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007514 */
7515 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007516 public void requestModemActivityInfo(ResultReceiver result) {
7517 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007522 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 } finally {
7524 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007525 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007526 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007527
Siddharth Rayb8114062018-06-17 15:02:38 -07007528 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7529 // less than total activity duration.
7530 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7531 if (info == null) {
7532 return false;
7533 }
7534 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007535 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7536 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7537
Siddharth Rayb8114062018-06-17 15:02:38 -07007538 return (info.isValid()
7539 && (info.getSleepTimeMillis() <= activityDurationMs)
7540 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007541 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007542 && (totalTxTimeMs <= activityDurationMs));
7543 }
7544
Jack Yu85bd38a2015-11-09 11:34:32 -08007545 /**
7546 * {@hide}
7547 * Returns the service state information on specified subscription.
7548 */
7549 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007550 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7551 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007553 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007554 return null;
7555 }
7556
Hall Liuf19c44f2018-11-27 14:38:17 -08007557 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7558 LocationAccessPolicy.checkLocationPermission(mApp,
7559 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7560 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007561 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007562 .setCallingPid(Binder.getCallingPid())
7563 .setCallingUid(Binder.getCallingUid())
7564 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007565 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007566 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007567 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7568 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007569 .build());
7570
7571 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7572 LocationAccessPolicy.checkLocationPermission(mApp,
7573 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7574 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007575 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007576 .setCallingPid(Binder.getCallingPid())
7577 .setCallingUid(Binder.getCallingUid())
7578 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007579 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007580 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007581 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7582 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007583 .build());
7584 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7585 boolean hasFinePermission =
7586 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7587 boolean hasCoarsePermission =
7588 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7589
Jack Yu479f40e2020-10-27 21:29:25 -07007590 final Phone phone = getPhone(subId);
7591 if (phone == null) {
7592 return null;
7593 }
7594
Jordan Liu0f2bc442020-11-18 16:47:37 -08007595 final long identity = Binder.clearCallingIdentity();
7596
Jack Yu479f40e2020-10-27 21:29:25 -07007597 boolean isCallingPackageDataService = phone.getDataServicePackages()
7598 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007600 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7601 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7602 Rlog.d(LOG_TAG,
7603 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7604 return null;
7605 }
7606
Hall Liuf19c44f2018-11-27 14:38:17 -08007607 ServiceState ss = phone.getServiceState();
7608
7609 // Scrub out the location info in ServiceState depending on what level of access
7610 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007611 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007612 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7613 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 } finally {
7615 Binder.restoreCallingIdentity(identity);
7616 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007617 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007618
7619 /**
7620 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7621 *
7622 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7623 * voicemail ringtone.
7624 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7625 * PhoneAccount.
7626 */
7627 @Override
7628 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7632 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007633 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007640 }
7641
7642 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007643 * Sets the per-account voicemail ringtone.
7644 *
7645 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7646 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7647 *
7648 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7649 * voicemail ringtone.
7650 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7651 * PhoneAccount.
7652 */
7653 @Override
7654 public void setVoicemailRingtoneUri(String callingPackage,
7655 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007658 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7659 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7661 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7662 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664
7665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7668 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007669 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 }
7671 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007674 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007675 }
7676
7677 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007678 * Returns whether vibration is set for voicemail notification in Phone settings.
7679 *
7680 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7681 * voicemail vibration setting.
7682 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7683 */
7684 @Override
7685 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7689 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007690 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007697 }
7698
Youhan Wange64578a2016-05-02 15:32:42 -07007699 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007700 * Sets the per-account voicemail vibration.
7701 *
7702 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7703 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7704 *
7705 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7706 * voicemail vibration setting.
7707 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7708 * specific PhoneAccount.
7709 */
7710 @Override
7711 public void setVoicemailVibrationEnabled(String callingPackage,
7712 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007713 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007715 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7716 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7718 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7719 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007720 }
7721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7725 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 }
7728 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007731 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007732 }
7733
7734 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007735 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7736 *
7737 * @throws SecurityException if the caller does not have the required permission
7738 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007739 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007740 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007741 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007742 }
7743
7744 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007745 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7746 * permission.
7747 *
7748 * @throws SecurityException if the caller does not have the required permission
7749 */
7750 private void enforceSendSmsPermission() {
7751 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7752 }
7753
7754 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007755 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007756 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007757 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007758 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007759 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 if (componentName == null) {
7765 throw new SecurityException(
7766 "Caller not current active visual voicemail package[null]");
7767 }
7768 String vvmPackage = componentName.getPackageName();
7769 if (!callingPackage.equals(vvmPackage)) {
7770 throw new SecurityException("Caller not current active visual voicemail package["
7771 + vvmPackage + "]");
7772 }
7773 } finally {
7774 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007775 }
7776 }
7777
7778 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007779 * Return the application ID for the app type.
7780 *
7781 * @param subId the subscription ID that this request applies to.
7782 * @param appType the uicc app type.
7783 * @return Application ID for specificied app type, or null if no uicc.
7784 */
7785 @Override
7786 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007787 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007788 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789
7790 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007791 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 if (phone == null) {
7793 return null;
7794 }
7795 String aid = null;
7796 try {
7797 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7798 .getApplicationByType(appType).getAid();
7799 } catch (Exception e) {
7800 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7801 }
7802 return aid;
7803 } finally {
7804 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007805 }
Youhan Wange64578a2016-05-02 15:32:42 -07007806 }
7807
Youhan Wang4001d252016-05-11 10:29:41 -07007808 /**
7809 * Return the Electronic Serial Number.
7810 *
7811 * @param subId the subscription ID that this request applies to.
7812 * @return ESN or null if error.
7813 */
7814 @Override
7815 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007816 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007817 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818
7819 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007820 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 if (phone == null) {
7822 return null;
7823 }
7824 String esn = null;
7825 try {
7826 esn = phone.getEsn();
7827 } catch (Exception e) {
7828 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7829 }
7830 return esn;
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007833 }
Youhan Wang4001d252016-05-11 10:29:41 -07007834 }
7835
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007836 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007837 * Return the Preferred Roaming List Version.
7838 *
7839 * @param subId the subscription ID that this request applies to.
7840 * @return PRLVersion or null if error.
7841 */
7842 @Override
7843 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007844 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007845 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846
7847 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007848 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 if (phone == null) {
7850 return null;
7851 }
7852 String cdmaPrlVersion = null;
7853 try {
7854 cdmaPrlVersion = phone.getCdmaPrlVersion();
7855 } catch (Exception e) {
7856 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7857 }
7858 return cdmaPrlVersion;
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007861 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007862 }
7863
7864 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007865 * Get snapshot of Telephony histograms
7866 * @return List of Telephony histograms
7867 * @hide
7868 */
7869 @Override
7870 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7872 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873
7874 final long identity = Binder.clearCallingIdentity();
7875 try {
7876 return RIL.getTelephonyRILTimingHistograms();
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007880 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007881
7882 /**
7883 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007884 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7885 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007886 * Require system privileges. In the future we may add this to carrier APIs.
7887 *
Michele Berionne482f8202018-11-27 18:57:59 -08007888 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007889 */
7890 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007891 @TelephonyManager.SetCarrierRestrictionResult
7892 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007893 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007895
Michele Berionne482f8202018-11-27 18:57:59 -08007896 if (carrierRestrictionRules == null) {
7897 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007898 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final long identity = Binder.clearCallingIdentity();
7901 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007902 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007903 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007907 }
7908
7909 /**
7910 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007911 * Get the allowed carrier list and the excluded carrier list, including the priority between
7912 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007913 * Require system privileges. In the future we may add this to carrier APIs.
7914 *
Michele Berionne482f8202018-11-27 18:57:59 -08007915 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007916 */
7917 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007918 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007919 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007920 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921
7922 final long identity = Binder.clearCallingIdentity();
7923 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007924 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7925 if (response instanceof CarrierRestrictionRules) {
7926 return (CarrierRestrictionRules) response;
7927 }
7928 // Response is an Exception of some kind,
7929 // which is signalled to the user as a NULL retval
7930 return null;
7931 } catch (Exception e) {
7932 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7933 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007937 }
7938
fionaxu59545b42016-05-25 15:53:37 -07007939 /**
fionaxu59545b42016-05-25 15:53:37 -07007940 * Action set from carrier signalling broadcast receivers to enable/disable radio
7941 * @param subId the subscription ID that this action applies to.
7942 * @param enabled control enable or disable radio.
7943 * {@hide}
7944 */
7945 @Override
7946 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7947 enforceModifyPermission();
7948 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949
7950 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007951 if (phone == null) {
7952 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7953 return;
7954 }
7955 try {
7956 phone.carrierActionSetRadioEnabled(enabled);
7957 } catch (Exception e) {
7958 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 } finally {
7960 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007961 }
7962 }
7963
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007964 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007965 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7966 * network status based on which carrier apps could apply actions accordingly,
7967 * enable/disable default url handler for example.
7968 *
7969 * @param subId the subscription ID that this action applies to.
7970 * @param report control start/stop reporting the default network status.
7971 * {@hide}
7972 */
7973 @Override
7974 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7975 enforceModifyPermission();
7976 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977
7978 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007979 if (phone == null) {
7980 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7981 return;
7982 }
7983 try {
7984 phone.carrierActionReportDefaultNetworkStatus(report);
7985 } catch (Exception e) {
7986 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 } finally {
7988 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007989 }
7990 }
7991
7992 /**
fionaxud9622282017-07-17 17:51:30 -07007993 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7994 * @param subId the subscription ID that this action applies to.
7995 * {@hide}
7996 */
7997 @Override
7998 public void carrierActionResetAll(int subId) {
7999 enforceModifyPermission();
8000 final Phone phone = getPhone(subId);
8001 if (phone == null) {
8002 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8003 return;
8004 }
8005 try {
8006 phone.carrierActionResetAll();
8007 } catch (Exception e) {
8008 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8009 }
8010 }
8011
8012 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008013 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8014 * bug report is being generated.
8015 */
8016 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008017 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008018 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8019 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008020 writer.println("Permission Denial: can't dump Phone from pid="
8021 + Binder.getCallingPid()
8022 + ", uid=" + Binder.getCallingUid()
8023 + "without permission "
8024 + android.Manifest.permission.DUMP);
8025 return;
8026 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008027 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008028 }
Jack Yueb89b242016-06-22 13:27:47 -07008029
Brad Ebingerdac2f002018-04-03 15:17:52 -07008030 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008031 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8032 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8033 @NonNull String[] args) {
8034 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8035 this, in.getFileDescriptor(), out.getFileDescriptor(),
8036 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008037 }
8038
Jack Yueb89b242016-06-22 13:27:47 -07008039 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008040 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008041 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008042 * @param reason the reason the data enable change is taking place
8043 * @param enabled True if enabling the data, otherwise disabling.
8044 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008045 */
8046 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008047 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008048 boolean enabled) {
8049 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8050 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8051 try {
8052 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008053 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008054 } catch (SecurityException se) {
8055 enforceModifyPermission();
8056 }
8057 } else {
8058 enforceModifyPermission();
8059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060
8061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 Phone phone = getPhone(subId);
8064 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008065 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8066 phone.carrierActionSetMeteredApnsEnabled(enabled);
8067 } else {
8068 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 }
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008073 }
8074 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008075
8076 /**
8077 * Get Client request stats
8078 * @return List of Client Request Stats
8079 * @hide
8080 */
8081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008082 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8083 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008085 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008086 return null;
8087 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008088 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 final long identity = Binder.clearCallingIdentity();
8091 try {
8092 if (phone != null) {
8093 return phone.getClientRequestStats();
8094 }
8095
8096 return null;
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008100 }
8101
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008102 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008103 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008104 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008105 }
Jack Yueb4124c2017-02-16 15:32:43 -08008106
8107 /**
Grace Chen70990072017-03-24 17:21:30 -07008108 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008109 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008110 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008111 * @param state State of SIM (power down, power up, pass through)
8112 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8113 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8114 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008115 *
8116 **/
8117 @Override
Grace Chen70990072017-03-24 17:21:30 -07008118 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008119 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008120 Phone phone = PhoneFactory.getPhone(slotIndex);
8121
vagdeviaf9a5b92018-08-15 16:01:53 -07008122 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 final long identity = Binder.clearCallingIdentity();
8125 try {
8126 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008127 phone.setSimPowerState(state, null, workSource);
8128 }
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
8131 }
8132 }
8133
8134 /**
8135 * Set SIM card power state.
8136 *
8137 * @param slotIndex SIM slot id.
8138 * @param state State of SIM (power down, power up, pass through)
8139 * @param callback callback to trigger after success or failure
8140 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8141 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8142 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8143 *
8144 **/
8145 @Override
8146 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8147 IIntegerConsumer callback) {
8148 enforceModifyPermission();
8149 Phone phone = PhoneFactory.getPhone(slotIndex);
8150
8151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8152
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 if (phone != null) {
8156 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8157 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 }
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008161 }
8162 }
Shuo Qiandd210312017-04-12 22:11:33 +00008163
Tyler Gunn65d45c22017-06-05 11:22:26 -07008164 private boolean isUssdApiAllowed(int subId) {
8165 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008166 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008167 if (configManager == null) {
8168 return false;
8169 }
8170 PersistableBundle pb = configManager.getConfigForSubId(subId);
8171 if (pb == null) {
8172 return false;
8173 }
8174 return pb.getBoolean(
8175 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8176 }
8177
Shuo Qiandd210312017-04-12 22:11:33 +00008178 /**
8179 * Check if phone is in emergency callback mode
8180 * @return true if phone is in emergency callback mode
8181 * @param subId sub id
8182 */
goneil9c5f4872017-12-05 14:07:56 -08008183 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008184 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008185 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008186 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187
8188 final long identity = Binder.clearCallingIdentity();
8189 try {
8190 if (phone != null) {
8191 return phone.isInEcm();
8192 } else {
8193 return false;
8194 }
8195 } finally {
8196 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008197 }
8198 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008199
8200 /**
8201 * Get the current signal strength information for the given subscription.
8202 * Because this information is not updated when the device is in a low power state
8203 * it should not be relied-upon to be current.
8204 * @param subId Subscription index
8205 * @return the most recent cached signal strength info from the modem
8206 */
8207 @Override
8208 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 Phone p = getPhone(subId);
8212 if (p == null) {
8213 return null;
8214 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 return p.getSignalStrength();
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008221
Pengquan Meng77b7f132018-08-22 14:49:57 -07008222 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008223 * Get the current modem radio state for the given slot.
8224 * @param slotIndex slot index.
8225 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008226 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008227 * @return the current radio power state from the modem
8228 */
8229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008230 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008231 Phone phone = PhoneFactory.getPhone(slotIndex);
8232 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8234 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008235 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8236 }
8237
8238 final long identity = Binder.clearCallingIdentity();
8239 try {
8240 return phone.getRadioPowerState();
8241 } finally {
8242 Binder.restoreCallingIdentity(identity);
8243 }
8244 }
8245 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8246 }
8247
8248 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008249 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8250 *
8251 * <p>Requires one of the following permissions:
8252 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8253 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8254 * privileges.
8255 *
8256 * @param subId subscription id
8257 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8258 * {@code false}.
8259 */
8260 @Override
8261 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008262 try {
8263 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8264 null);
8265 } catch (Exception e) {
8266 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8267 mApp, subId, "isDataRoamingEnabled");
8268 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008269
Pengquan Menga1bb6272018-09-06 09:59:22 -07008270 boolean isEnabled = false;
8271 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008272 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008273 Phone phone = getPhone(subId);
8274 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008275 } finally {
8276 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008277 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008278 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008279 }
8280
8281
8282 /**
8283 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8284 *
8285 * <p> Requires permission:
8286 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8287 * privileges.
8288 *
8289 * @param subId subscription id
8290 * @param isEnabled {@code true} means enable, {@code false} means disable.
8291 */
8292 @Override
8293 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8295 mApp, subId, "setDataRoamingEnabled");
8296
Pengquan Menga1bb6272018-09-06 09:59:22 -07008297 final long identity = Binder.clearCallingIdentity();
8298 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008299 Phone phone = getPhone(subId);
8300 if (phone != null) {
8301 phone.setDataRoamingEnabled(isEnabled);
8302 }
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008305 }
8306 }
8307
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008308 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008309 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008310 TelephonyPermissions
8311 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008312 mApp, subId, "isManualNetworkSelectionAllowed");
8313
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008314 boolean isAllowed = true;
8315 final long identity = Binder.clearCallingIdentity();
8316 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008317 Phone phone = getPhone(subId);
8318 if (phone != null) {
8319 isAllowed = phone.isCspPlmnEnabled();
8320 }
8321 } finally {
8322 Binder.restoreCallingIdentity(identity);
8323 }
8324 return isAllowed;
8325 }
8326
8327 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008328 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008329 // Verify that tha callingPackage belongs to the calling UID
8330 mApp.getSystemService(AppOpsManager.class)
8331 .checkPackage(Binder.getCallingUid(), callingPackage);
8332
Jordan Liu1e142fc2019-04-22 15:10:43 -07008333 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008334 try {
8335 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008336 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008337 } catch (SecurityException e) {
8338 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8339 // has carrier privileges on an active UICC
8340 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8341 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008342 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008343 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008344 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008345
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008348 UiccController uiccController = UiccController.getInstance();
8349 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008350 if (hasReadPermission) {
8351 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008352 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008353
8354 // Remove private info if the caller doesn't have access
8355 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8356 for (UiccCardInfo cardInfo : cardInfos) {
8357 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8358 // is available
8359 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8360 if (card == null || card.getUiccProfile() == null) {
8361 // assume no access if the card or profile is unavailable
8362 filteredInfos.add(cardInfo.getUnprivileged());
8363 continue;
8364 }
8365 UiccProfile profile = card.getUiccProfile();
8366 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8367 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8368 filteredInfos.add(cardInfo);
8369 } else {
8370 filteredInfos.add(cardInfo.getUnprivileged());
8371 }
8372 }
8373 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008374 } finally {
8375 Binder.restoreCallingIdentity(identity);
8376 }
8377 }
8378
8379 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008380 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008381 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8386 if (slots == null) {
8387 Rlog.i(LOG_TAG, "slots is null.");
8388 return null;
8389 }
8390
8391 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8392 for (int i = 0; i < slots.length; i++) {
8393 UiccSlot slot = slots[i];
8394 if (slot == null) {
8395 continue;
8396 }
8397
Jordan Liu7be7e652019-05-06 18:55:02 +00008398 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008399 UiccCard card = slot.getUiccCard();
8400 if (card != null) {
8401 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008402 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008403 cardId = slot.getEid();
8404 if (TextUtils.isEmpty(cardId)) {
8405 cardId = slot.getIccId();
8406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 }
8408
Jordan Liu857451f2019-05-09 16:35:35 -07008409 if (cardId != null) {
8410 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8411 // if cardId is an EID, it's all digits so this is fine
8412 cardId = IccUtils.stripTrailingFs(cardId);
8413 }
8414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415 int cardState = 0;
8416 switch (slot.getCardState()) {
8417 case CARDSTATE_ABSENT:
8418 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8419 break;
8420 case CARDSTATE_PRESENT:
8421 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8422 break;
8423 case CARDSTATE_ERROR:
8424 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8425 break;
8426 case CARDSTATE_RESTRICTED:
8427 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8428 break;
8429 default:
8430 break;
8431
8432 }
8433
8434 infos[i] = new UiccSlotInfo(
8435 slot.isActive(),
8436 slot.isEuicc(),
8437 cardId,
8438 cardState,
8439 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008440 slot.isExtendedApduSupported(),
8441 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 }
8443 return infos;
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008446 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008447 }
8448
8449 @Override
8450 public boolean switchSlots(int[] physicalSlots) {
8451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452
8453 final long identity = Binder.clearCallingIdentity();
8454 try {
8455 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8456 } finally {
8457 Binder.restoreCallingIdentity(identity);
8458 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008459 }
Jack Yu4c988042018-02-27 15:30:01 -08008460
8461 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008462 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 return UiccController.getInstance().getCardIdForDefaultEuicc();
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
Pengquan Meng85728fb2018-03-12 16:31:21 -07008471 /**
goneil47ffb6e2018-04-06 15:40:58 -07008472 * A test API to reload the UICC profile.
8473 *
8474 * <p>Requires that the calling app has permission
8475 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8476 * @hide
8477 */
8478 @Override
8479 public void refreshUiccProfile(int subId) {
8480 enforceModifyPermission();
8481
8482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 Phone phone = getPhone(subId);
8485 if (phone == null) {
8486 return;
8487 }
8488 UiccCard uiccCard = phone.getUiccCard();
8489 if (uiccCard == null) {
8490 return;
8491 }
8492 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8493 if (uiccProfile == null) {
8494 return;
8495 }
8496 uiccProfile.refresh();
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
8501
8502 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008503 * Returns false if the mobile data is disabled by default, otherwise return true.
8504 */
8505 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008506 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008507 }
8508
8509 /**
8510 * Returns true if the data roaming is enabled by default, i.e the system property
8511 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8512 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8513 */
8514 private boolean getDefaultDataRoamingEnabled(int subId) {
8515 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008516 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008517 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008518 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8519 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8520 return isDataRoamingEnabled;
8521 }
8522
8523 /**
8524 * Returns the default network type for the given {@code subId}, if the default network type is
8525 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8526 */
8527 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008528 List<Integer> list = TelephonyProperties.default_network();
8529 int phoneId = mSubscriptionController.getPhoneId(subId);
8530 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8531 return list.get(phoneId);
8532 }
8533 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008534 }
fionaxua13278b2018-03-21 00:08:13 -07008535
8536 @Override
8537 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008538 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008539 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 final Phone phone = getPhone(subId);
8544 if (phone == null) {
8545 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8546 return;
8547 }
chen xueaba88a2019-03-15 13:15:10 -07008548 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8549 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008550 if (carrierPrivilegeRules == null) {
8551 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8552 } else {
8553 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555 } finally {
8556 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008557 }
fionaxua13278b2018-03-21 00:08:13 -07008558 }
8559
8560 @Override
8561 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008562 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563
8564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 final Phone phone = getPhone(subId);
8567 if (phone == null) {
8568 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8569 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8570 }
8571 return phone.getCarrierIdListVersion();
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008574 }
fionaxua13278b2018-03-21 00:08:13 -07008575 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008576
8577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008578 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8579 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008581 mApp, subId, callingPackage, callingFeatureId,
8582 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008583 return -1;
8584 }
8585
8586 final long identity = Binder.clearCallingIdentity();
8587 try {
8588 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008593
8594 @Override
8595 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008596 TelephonyPermissions
8597 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008598 mApp, subId, "getCdmaRoamingMode");
8599
8600 final long identity = Binder.clearCallingIdentity();
8601 try {
8602 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
8605 }
8606 }
8607
8608 @Override
8609 public boolean setCdmaRoamingMode(int subId, int mode) {
8610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8611 mApp, subId, "setCdmaRoamingMode");
8612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
8618 }
8619 }
8620
8621 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008622 public int getCdmaSubscriptionMode(int subId) {
8623 TelephonyPermissions
8624 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8625 mApp, subId, "getCdmaSubscriptionMode");
8626
8627 final long identity = Binder.clearCallingIdentity();
8628 try {
8629 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
8635 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008636 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8638 mApp, subId, "setCdmaSubscriptionMode");
8639
8640 final long identity = Binder.clearCallingIdentity();
8641 try {
8642 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8643 } finally {
8644 Binder.restoreCallingIdentity(identity);
8645 }
8646 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008647
sqianc5eccab2018-10-19 18:46:41 -07008648 @Override
sqian8c685422019-02-22 15:55:18 -08008649 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008650 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008652 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8653 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008654 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8655 }
8656 final long identity = Binder.clearCallingIdentity();
8657 try {
sqian854d44b2018-12-12 16:48:18 -08008658 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8659 for (Phone phone: PhoneFactory.getPhones()) {
8660 if (phone.getEmergencyNumberTracker() != null
8661 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8662 emergencyNumberListInternal.put(
8663 phone.getSubId(),
8664 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8665 }
sqian11b7a0e2018-12-05 18:48:28 -08008666 }
sqian854d44b2018-12-12 16:48:18 -08008667 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008668 } finally {
8669 Binder.restoreCallingIdentity(identity);
8670 }
sqianc5eccab2018-10-19 18:46:41 -07008671 }
8672
8673 @Override
sqian8c685422019-02-22 15:55:18 -08008674 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008675 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008676 if (!exactMatch) {
8677 TelephonyPermissions
8678 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008679 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008680 }
8681 final long identity = Binder.clearCallingIdentity();
8682 try {
sqian854d44b2018-12-12 16:48:18 -08008683 for (Phone phone: PhoneFactory.getPhones()) {
8684 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008685 && phone.getEmergencyNumberTracker()
8686 .isEmergencyNumber(number, exactMatch)) {
8687 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008688 }
sqian11b7a0e2018-12-05 18:48:28 -08008689 }
8690 return false;
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
8694 }
8695
sqianf4ca7ed2019-01-15 18:32:07 -08008696 /**
8697 * Update emergency number list for test mode.
8698 */
8699 @Override
8700 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8702 "updateEmergencyNumberListTestMode");
8703
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 for (Phone phone: PhoneFactory.getPhones()) {
8707 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8708 if (tracker != null) {
8709 tracker.executeEmergencyNumberTestModeCommand(action, num);
8710 }
8711 }
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 }
8716
8717 /**
8718 * Get the full emergency number list for test mode.
8719 */
8720 @Override
8721 public List<String> getEmergencyNumberListTestMode() {
8722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8723 "getEmergencyNumberListTestMode");
8724
8725 final long identity = Binder.clearCallingIdentity();
8726 try {
8727 Set<String> emergencyNumbers = new HashSet<>();
8728 for (Phone phone: PhoneFactory.getPhones()) {
8729 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8730 if (tracker != null) {
8731 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8732 emergencyNumbers.add(num.getNumber());
8733 }
8734 }
8735 }
8736 return new ArrayList<>(emergencyNumbers);
8737 } finally {
8738 Binder.restoreCallingIdentity(identity);
8739 }
8740 }
8741
chen xud6b45bd2018-10-30 22:27:10 -07008742 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008743 public int getEmergencyNumberDbVersion(int subId) {
8744 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8745
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 final Phone phone = getPhone(subId);
8749 if (phone == null) {
8750 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8751 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8752 }
8753 return phone.getEmergencyNumberDbVersion();
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
8759 @Override
8760 public void notifyOtaEmergencyNumberDbInstalled() {
8761 enforceModifyPermission();
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 for (Phone phone: PhoneFactory.getPhones()) {
8766 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8767 if (tracker != null) {
8768 tracker.updateOtaEmergencyNumberDatabase();
8769 }
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
8775
8776 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008777 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008778 enforceActiveEmergencySessionPermission();
8779
8780 final long identity = Binder.clearCallingIdentity();
8781 try {
8782 for (Phone phone: PhoneFactory.getPhones()) {
8783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8784 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008785 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8786 }
8787 }
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
8791 }
8792
8793 @Override
8794 public void resetOtaEmergencyNumberDbFilePath() {
8795 enforceActiveEmergencySessionPermission();
8796
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 for (Phone phone: PhoneFactory.getPhones()) {
8800 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8801 if (tracker != null) {
8802 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008803 }
8804 }
8805 } finally {
8806 Binder.restoreCallingIdentity(identity);
8807 }
8808 }
8809
8810 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008811 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8812 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8813 Phone phone = getPhone(subId);
8814 if (phone == null) {
8815 return null;
8816 }
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 UiccProfile profile = UiccController.getInstance()
8820 .getUiccProfileForPhone(phone.getPhoneId());
8821 if (profile != null) {
8822 return profile.getCertsFromCarrierPrivilegeAccessRules();
8823 }
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 return null;
8828 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008829
8830 /**
8831 * Enable or disable a modem stack.
8832 */
8833 @Override
8834 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8835 enforceModifyPermission();
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 Phone phone = PhoneFactory.getPhone(slotIndex);
8840 if (phone == null) {
8841 return false;
8842 } else {
8843 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8844 }
8845 } finally {
8846 Binder.restoreCallingIdentity(identity);
8847 }
8848 }
Michelecea4cf22018-12-21 15:00:11 -08008849
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008850 /**
8851 * Whether a modem stack is enabled or not.
8852 */
8853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008854 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8855 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008856 Phone phone = PhoneFactory.getPhone(slotIndex);
8857 if (phone == null) return false;
8858
8859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008860 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8861 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008862 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8863 }
8864
8865 final long identity = Binder.clearCallingIdentity();
8866 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008867 try {
8868 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8869 } catch (NoSuchElementException ex) {
8870 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8871 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008872 } finally {
8873 Binder.restoreCallingIdentity(identity);
8874 }
8875 }
8876
Michelecea4cf22018-12-21 15:00:11 -08008877 @Override
Michele0ea7d782019-03-19 14:58:42 -07008878 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008879 enforceModifyPermission();
8880
8881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008884 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008885 .commit();
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
8888 }
8889 }
8890
8891 @Override
Michele0ea7d782019-03-19 14:58:42 -07008892 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008895 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8896 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008897 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008898 }
Michelecea4cf22018-12-21 15:00:11 -08008899
8900 final long identity = Binder.clearCallingIdentity();
8901 try {
Michele0ea7d782019-03-19 14:58:42 -07008902 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008903 } finally {
8904 Binder.restoreCallingIdentity(identity);
8905 }
8906 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008907
Michele0ea7d782019-03-19 14:58:42 -07008908 @TelephonyManager.IsMultiSimSupportedResult
8909 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008910 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8911 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8912 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008913 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008915 }
8916 // Check if the hardware supports multisim functionality. If usage of multisim is not
8917 // supported by the modem, indicate that it is restricted.
8918 PhoneCapability staticCapability =
8919 mPhoneConfigurationManager.getStaticPhoneCapability();
8920 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008921 loge("isMultiSimSupportedInternal: no static configuration available");
8922 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008923 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008924 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008925 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8926 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008927 }
8928 // Check if support of multiple SIMs is restricted by carrier
8929 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008930 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008931 }
8932
Michele0ea7d782019-03-19 14:58:42 -07008933 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008934 }
8935
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008936 /**
8937 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008938 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8939 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8940 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008941 * @param numOfSims number of active sims we want to switch to
8942 */
8943 @Override
8944 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008945 if (numOfSims == 1) {
8946 enforceModifyPermission();
8947 } else {
8948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8949 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8950 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008951 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008952
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008953 try {
Michele30b57b22019-03-01 12:01:14 -08008954 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008955 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008956 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8957 return;
8958 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008959 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
8963 }
8964
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008965 @Override
8966 public boolean isApplicationOnUicc(int subId, int appType) {
8967 enforceReadPrivilegedPermission("isApplicationOnUicc");
8968 Phone phone = getPhone(subId);
8969 if (phone == null) {
8970 return false;
8971 }
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
8974 UiccCard uiccCard = phone.getUiccCard();
8975 if (uiccCard == null) {
8976 return false;
8977 }
8978 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8979 if (uiccProfile == null) {
8980 return false;
8981 }
8982 if (TelephonyManager.APPTYPE_SIM <= appType
8983 && appType <= TelephonyManager.APPTYPE_ISIM) {
8984 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8985 }
8986 return false;
8987 } finally {
8988 Binder.restoreCallingIdentity(identity);
8989 }
8990 }
8991
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008992 /**
chen xub4baa772019-04-03 10:23:41 -07008993 * Get whether making changes to modem configurations will trigger reboot.
8994 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008995 */
8996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008997 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8998 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009000 mApp, subId, callingPackage, callingFeatureId,
9001 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009002 return false;
9003 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009004 final long identity = Binder.clearCallingIdentity();
9005 try {
9006 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9007 } finally {
9008 Binder.restoreCallingIdentity(identity);
9009 }
9010 }
9011
Nathan Harold29f5f052019-02-15 13:41:57 -08009012 private void updateModemStateMetrics() {
9013 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9014 // TODO: check the state for each modem if the api is ready.
9015 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9016 }
9017
Pengquan Meng3889a572019-01-23 11:16:29 -08009018 @Override
9019 public int[] getSlotsMapping() {
9020 enforceReadPrivilegedPermission("getSlotsMapping");
9021
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9025 // All logical slots should have a mapping to a physical slot.
9026 int[] logicalSlotsMapping = new int[phoneCount];
9027 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9028 for (int i = 0; i < slotInfos.length; i++) {
9029 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9030 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9031 }
9032 }
9033 return logicalSlotsMapping;
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009038
9039 /**
9040 * Get the IRadio HAL Version
9041 */
9042 @Override
9043 public int getRadioHalVersion() {
9044 Phone phone = getDefaultPhone();
9045 if (phone == null) return -1;
9046 HalVersion hv = phone.getHalVersion();
9047 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9048 return hv.major * 100 + hv.minor;
9049 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009050
9051 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009052 * Get the current calling package name.
9053 * @return the current calling package name
9054 */
9055 @Override
9056 public String getCurrentPackageName() {
9057 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9058 }
9059
9060 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009061 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9062 * corresponding network requests on a subId.
9063 *
9064 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009065 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009066 * 2) APN is un-metered for this subscription, or
9067 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009068 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009069 *
9070 * @return whether data is allowed for a apn type.
9071 *
9072 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009073 */
9074 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009075 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009076 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9077 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009078
9079 // Now that all security checks passes, perform the operation as ourselves.
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 Phone phone = getPhone(subId);
9083 if (phone == null) return false;
9084
Jack Yu41407ee2019-05-13 16:54:09 -07009085 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009086 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
9089 }
9090 }
9091
9092 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009093 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009094 enforceReadPrivilegedPermission("isApnMetered");
9095
9096 // Now that all security checks passes, perform the operation as ourselves.
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 Phone phone = getPhone(subId);
9100 if (phone == null) return true; // By default return true.
9101
Jack Yu41407ee2019-05-13 16:54:09 -07009102 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009103 } finally {
9104 Binder.restoreCallingIdentity(identity);
9105 }
9106 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009107
9108 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009109 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9110 int subscriptionId, IBooleanConsumer resultCallback) {
9111 enforceModifyPermission();
9112 long token = Binder.clearCallingIdentity();
9113 try {
9114 Phone phone = getPhone(subscriptionId);
9115 if (phone == null) {
9116 try {
9117 if (resultCallback != null) {
9118 resultCallback.accept(false);
9119 }
9120 } catch (RemoteException e) {
9121 // ignore
9122 }
9123 return;
9124 }
9125 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9126 Pair.create(specifiers, (x) -> {
9127 try {
9128 if (resultCallback != null) {
9129 resultCallback.accept(x);
9130 }
9131 } catch (RemoteException e) {
9132 // ignore
9133 }
9134 });
9135 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9136 } finally {
9137 Binder.restoreCallingIdentity(token);
9138 }
9139 }
9140
9141 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009142 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9143 TelephonyPermissions
9144 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9145 mApp, subId, "getSystemSelectionChannels");
9146 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9147 final long identity = Binder.clearCallingIdentity();
9148 try {
9149 List<RadioAccessSpecifier> specifiers =
9150 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9151 null, subId, workSource);
9152 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9153 return specifiers;
9154 } finally {
9155 Binder.restoreCallingIdentity(identity);
9156 }
9157 }
9158
9159 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009160 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009161 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009162 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9163 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9164 if (iccRecords == null) {
9165 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9166 return false;
9167 }
9168 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9169 }
9170
9171 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009172 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9173 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009174 if (callingPackage == null) {
9175 callingPackage = getCurrentPackageName();
9176 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009177 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9178 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009179 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9180 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009181 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9182 }
9183 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9184 Intent intent = new Intent();
9185 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9186 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9187 // Bring up choose default SMS subscription dialog right now
9188 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9189 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9190 mApp.startActivity(intent);
9191 }
chen xud5ca2d52019-05-28 15:20:57 -07009192
9193 @Override
9194 public String getMmsUAProfUrl(int subId) {
9195 //TODO investigate if this API should require proper permission check in R b/133791609
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009198 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9199 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9200 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9201 return carrierUAProfUrl;
9202 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009203 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9204 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009205 } finally {
9206 Binder.restoreCallingIdentity(identity);
9207 }
9208 }
9209
9210 @Override
9211 public String getMmsUserAgent(int subId) {
9212 //TODO investigate if this API should require proper permission check in R b/133791609
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009215 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9216 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9217 if (!TextUtils.isEmpty(carrierUserAgent)) {
9218 return carrierUserAgent;
9219 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009220 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9221 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
Jack Yub07d4972019-05-28 16:12:25 -07009226
9227 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009228 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9229 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009230
Jack Yub07d4972019-05-28 16:12:25 -07009231 final long identity = Binder.clearCallingIdentity();
9232 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009233 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009234 if (phone == null) return false;
9235
Hall Liua62f5da2020-09-25 10:42:19 -07009236 switch (policy) {
9237 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9238 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9239 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9240 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9241 default:
9242 throw new IllegalArgumentException(policy + " is not a valid policy");
9243 }
Jack Yub07d4972019-05-28 16:12:25 -07009244 } finally {
9245 Binder.restoreCallingIdentity(identity);
9246 }
9247 }
9248
9249 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009250 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9251 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009252 enforceModifyPermission();
9253
changbettyd5c246e2019-12-24 15:40:37 +08009254 final long identity = Binder.clearCallingIdentity();
9255 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009256 Phone phone = getPhone(subscriptionId);
9257 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009258
Hall Liua62f5da2020-09-25 10:42:19 -07009259 switch (policy) {
9260 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9261 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9262 break;
9263 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9264 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9265 break;
9266 default:
9267 throw new IllegalArgumentException(policy + " is not a valid policy");
9268 }
changbettyd5c246e2019-12-24 15:40:37 +08009269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009274 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009275 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009276 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9277 * otherwise.
9278 */
9279 @Override
9280 public void setCepEnabled(boolean isCepEnabled) {
9281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9282
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
9285 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9286 for (Phone phone : PhoneFactory.getPhones()) {
9287 Phone defaultPhone = phone.getImsPhone();
9288 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9289 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9290 ImsPhoneCallTracker imsPhoneCallTracker =
9291 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9292 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9293 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9294 + imsPhone.getMsisdn());
9295 }
9296 }
9297 } finally {
9298 Binder.restoreCallingIdentity(identity);
9299 }
9300 }
allenwtsu46dcc572020-01-08 18:24:03 +08009301
9302 /**
9303 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9304 *
9305 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9306 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9307 * before being read.
9308 */
9309 @Override
9310 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9311 isCompressed) {
9312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9313 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009314 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9315 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9316 }
9317 if (!isImsAvailableOnDevice()) {
9318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9319 "IMS not available on device.");
9320 }
9321
9322 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009323 try {
Hui Wang761a6682020-10-31 05:12:53 +00009324 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9325 } finally {
9326 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009327 }
9328 }
zoey chene02881a2019-12-30 16:11:23 +08009329
9330 @Override
9331 public boolean isIccLockEnabled(int subId) {
9332 enforceReadPrivilegedPermission("isIccLockEnabled");
9333
9334 // Now that all security checks passes, perform the operation as ourselves.
9335 final long identity = Binder.clearCallingIdentity();
9336 try {
9337 Phone phone = getPhone(subId);
9338 if (phone != null && phone.getIccCard() != null) {
9339 return phone.getIccCard().getIccLockEnabled();
9340 } else {
9341 return false;
9342 }
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
9348 /**
9349 * Set the ICC pin lock enabled or disabled.
9350 *
9351 * @return an integer representing the status of IccLock enabled or disabled in the following
9352 * three cases:
9353 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9354 * successfully.
9355 * - Positive number and zero for remaining password attempts.
9356 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9357 *
9358 */
9359 @Override
9360 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9361 enforceModifyPermission();
9362
9363 Phone phone = getPhone(subId);
9364 if (phone == null) {
9365 return 0;
9366 }
9367 // Now that all security checks passes, perform the operation as ourselves.
9368 final long identity = Binder.clearCallingIdentity();
9369 try {
9370 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9371 new Pair<Boolean, String>(enabled, password), phone, null);
9372 return attemptsRemaining;
9373
9374 } catch (Exception e) {
9375 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
9379 return 0;
9380 }
9381
9382 /**
9383 * Change the ICC password used in ICC pin lock.
9384 *
9385 * @return an integer representing the status of IccLock changed in the following three cases:
9386 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9387 * - Positive number and zero for remaining password attempts.
9388 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9389 *
9390 */
9391 @Override
9392 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9393 enforceModifyPermission();
9394
9395 Phone phone = getPhone(subId);
9396 if (phone == null) {
9397 return 0;
9398 }
9399 // Now that all security checks passes, perform the operation as ourselves.
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9403 new Pair<String, String>(oldPassword, newPassword), phone, null);
9404 return attemptsRemaining;
9405
9406 } catch (Exception e) {
9407 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
9410 }
9411 return 0;
9412 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009413
9414 /**
9415 * Request for receiving user activity notification
9416 */
9417 @Override
9418 public void requestUserActivityNotification() {
9419 if (!mNotifyUserActivity.get()
9420 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9421 mNotifyUserActivity.set(true);
9422 }
9423 }
9424
9425 /**
9426 * Called when userActivity is signalled in the power manager.
9427 * This is safe to call from any thread, with any window manager locks held or not.
9428 */
9429 @Override
9430 public void userActivity() {
9431 // ***************************************
9432 // * Inherited from PhoneWindowManager *
9433 // ***************************************
9434 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9435 // WITH ITS LOCKS HELD.
9436 //
9437 // This code must be VERY careful about the locks
9438 // it acquires.
9439 // In fact, the current code acquires way too many,
9440 // and probably has lurking deadlocks.
9441
9442 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9443 throw new SecurityException("Only the OS may call notifyUserActivity()");
9444 }
9445
9446 if (mNotifyUserActivity.getAndSet(false)) {
9447 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9448 USER_ACTIVITY_NOTIFICATION_DELAY);
9449 }
9450 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009451
9452 @Override
9453 public boolean canConnectTo5GInDsdsMode() {
9454 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9455 }
Jack Yud10cdd42020-09-28 20:28:01 -07009456
9457 @Override
9458 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9459 String callingFeatureId) {
9460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9461 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9462 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9463 }
9464
9465 Phone phone = getPhone(subId);
9466 if (phone == null) {
9467 throw new RuntimeException("phone is not available");
9468 }
9469 // Now that all security checks passes, perform the operation as ourselves.
9470 final long identity = Binder.clearCallingIdentity();
9471 try {
9472 return phone.getEquivalentHomePlmns();
9473 } finally {
9474 Binder.restoreCallingIdentity(identity);
9475 }
9476 }
Daniel Bright59e67312020-11-13 11:49:37 -08009477
9478 @Override
9479 public boolean isRadioInterfaceCapabilitySupported(
9480 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9481 RadioInterfaceCapabilities radioInterfaceCapabilities =
9482 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9483 if (radioInterfaceCapabilities == null) {
9484 throw new RuntimeException("radio interface capabilities are not available");
9485 } else {
9486 return radioInterfaceCapabilities.isSupported(capability);
9487 }
9488 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009489
Hui Wang641e81c2020-10-12 12:14:23 -07009490 @Override
9491 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9492 UaSecurityProtocolIdentifier securityProtocol,
9493 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9494 throws RemoteException {
9495 enforceModifyPermission();
9496 if (DBG) {
9497 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9498 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9499 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9500 }
9501
9502 if (!SubscriptionManager.isValidSubscriptionId(subId)
9503 || appType < TelephonyManager.APPTYPE_UNKNOWN
9504 || appType > TelephonyManager.APPTYPE_ISIM
9505 || nafUrl == null || securityProtocol == null || callback == null) {
9506 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9507 if (callback != null) {
9508 try {
9509 callback.onAuthenticationFailure(
9510 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9511 } catch (RemoteException exception) {
9512 log("Fail to notify onAuthenticationFailure due to " + exception);
9513 }
9514 return;
9515 }
9516 }
9517
9518 final long token = Binder.clearCallingIdentity();
9519 try {
9520 getGbaManager(subId).bootstrapAuthenticationRequest(
9521 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9522 forceBootStrapping, callback));
9523 } finally {
9524 Binder.restoreCallingIdentity(token);
9525 }
9526 }
9527
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009528 /**
9529 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9530 * requested radio power state will actually be set. See {@link
9531 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9532 *
9533 * @param subId the subscription ID of the phone requesting to set the radio power state.
9534 * @param enable {@code true} if trying to turn radio on.
9535 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9536 * false}.
9537 */
9538 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9539 Phone phone = getPhone(subId);
9540 if (phone != null) {
9541 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9542 return true;
9543 }
9544 return false;
9545 }
9546
9547 private int handleDataThrottlingRequest(int subId,
9548 DataThrottlingRequest dataThrottlingRequest) {
9549 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9550 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9551 if (!setRadioPowerForThermal(subId, true)) {
9552 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9553 }
9554
9555 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9556
9557 int thermalMitigationResult =
9558 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9559 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9560 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9561 }
9562 return thermalMitigationResult;
9563 }
9564
9565 /**
9566 * Thermal mitigation request to control functionalities at modem.
9567 *
9568 * @param subId the id of the subscription.
9569 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9570 *
9571 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9572 */
9573 @Override
9574 @ThermalMitigationResult
9575 public int sendThermalMitigationRequest(
9576 int subId,
9577 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9578 enforceModifyPermission();
9579
9580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9581 final long identity = Binder.clearCallingIdentity();
9582
9583 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9584 try {
9585 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9586 switch (thermalMitigationAction) {
9587 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9588 thermalMitigationResult =
9589 handleDataThrottlingRequest(subId,
9590 thermalMitigationRequest.getDataThrottlingRequest());
9591 break;
9592 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9593 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9594 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9595 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9596 }
9597
9598 // Ensure that radio is on. If not able to power on due to phone being
9599 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9600 if (!setRadioPowerForThermal(subId, true)) {
9601 thermalMitigationResult =
9602 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9603 break;
9604 }
9605
9606 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9607 false);
9608 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9609 break;
9610 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9611 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9612 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9613 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9614 }
9615
9616 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9617 if (registry != null) {
9618 TelephonyConnectionService service =
9619 registry.getTelephonyConnectionService();
9620 Phone phone = getPhone(subId);
9621 if (phone == null) {
9622 thermalMitigationResult =
9623 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9624 break;
9625 }
9626
9627 if (PhoneConstantConversions.convertCallState(phone.getState())
9628 != TelephonyManager.CALL_STATE_IDLE
9629 || phone.isInEmergencySmsMode() || phone.isInEcm()
9630 || (service != null && service.isEmergencyCallPending())) {
9631 String errorMessage = "Phone state is not valid. call state = "
9632 + PhoneConstantConversions.convertCallState(phone.getState())
9633 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9634 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9635 errorMessage += service == null
9636 ? " TelephonyConnectionService is null"
9637 : " isEmergencyCallPending = "
9638 + service.isEmergencyCallPending();
9639 Log.e(LOG_TAG, errorMessage);
9640 thermalMitigationResult =
9641 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9642 break;
9643 }
9644 } else {
9645 thermalMitigationResult =
9646 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9647 break;
9648 }
9649
9650 // Turn radio off. If not able to power off due to phone being unavailable,
9651 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9652 if (!setRadioPowerForThermal(subId, false)) {
9653 thermalMitigationResult =
9654 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9655 break;
9656 }
9657 thermalMitigationResult =
9658 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9659 break;
9660 default:
9661 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9662 + "not exist. Requested action: " + thermalMitigationAction);
9663 }
9664 } catch (IllegalArgumentException e) {
9665 throw e;
9666 } catch (Exception e) {
9667 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9668 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9669 } finally {
9670 Binder.restoreCallingIdentity(identity);
9671 }
9672
9673 if (DBG) {
9674 log("thermalMitigationRequest returning with thermalMitigationResult: "
9675 + thermalMitigationResult);
9676 }
9677
9678 return thermalMitigationResult;
9679 }
Hui Wang641e81c2020-10-12 12:14:23 -07009680
9681 /**
9682 * Set the GbaService Package Name that Telephony will bind to.
9683 *
9684 * @param subId The sim that the GbaService is associated with.
9685 * @param packageName The name of the package to be replaced with.
9686 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9687 */
9688 @Override
9689 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9690 enforceModifyPermission();
9691
9692 final long identity = Binder.clearCallingIdentity();
9693 try {
9694 return getGbaManager(subId).overrideServicePackage(packageName);
9695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
9698 }
9699
9700 /**
9701 * Return the package name of the currently bound GbaService.
9702 *
9703 * @param subId The sim that the GbaService is associated with.
9704 * @return the package name of the GbaService configuration, null if GBA is not supported.
9705 */
9706 @Override
9707 public String getBoundGbaService(int subId) {
9708 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9709
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 return getGbaManager(subId).getServicePackage();
9713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
9718 /**
9719 * Set the release time for telephony to unbind GbaService.
9720 *
9721 * @param subId The sim that the GbaService is associated with.
9722 * @param interval The release time to unbind GbaService by millisecond.
9723 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9724 */
9725 @Override
9726 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9727 enforceModifyPermission();
9728
9729 final long identity = Binder.clearCallingIdentity();
9730 try {
9731 return getGbaManager(subId).overrideReleaseTime(interval);
9732 } finally {
9733 Binder.restoreCallingIdentity(identity);
9734 }
9735 }
9736
9737 /**
9738 * Return the release time for telephony to unbind GbaService.
9739 *
9740 * @param subId The sim that the GbaService is associated with.
9741 * @return The release time to unbind GbaService by millisecond.
9742 */
9743 @Override
9744 public int getGbaReleaseTime(int subId) {
9745 enforceReadPrivilegedPermission("getGbaReleaseTime");
9746
9747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 return getGbaManager(subId).getReleaseTime();
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 private GbaManager getGbaManager(int subId) {
9756 GbaManager instance = GbaManager.getInstance(subId);
9757 if (instance == null) {
9758 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9759 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9760 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9761 }
9762 return instance;
9763 }
Hui Wang761a6682020-10-31 05:12:53 +00009764
9765 /**
9766 * indicate whether the device and the carrier can support
9767 * RCS VoLTE single registration.
9768 */
9769 @Override
9770 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9771 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9772
9773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9775 }
9776
9777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9780 if (rpm != null) {
9781 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9782 }
9783 return false;
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
9789 /**
9790 * Register RCS provisioning callback.
9791 */
9792 @Override
9793 public void registerRcsProvisioningChangedCallback(int subId,
9794 IRcsConfigCallback callback) {
9795 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9796
9797 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9798 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9799 }
9800 if (!isImsAvailableOnDevice()) {
9801 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9802 "IMS not available on device.");
9803 }
9804
9805 final long identity = Binder.clearCallingIdentity();
9806 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009807 if (!RcsProvisioningMonitor.getInstance()
9808 .registerRcsProvisioningChangedCallback(subId, callback)) {
9809 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9810 "Service not available for the subscription.");
9811 }
Hui Wang761a6682020-10-31 05:12:53 +00009812 } finally {
9813 Binder.restoreCallingIdentity(identity);
9814 }
9815 }
9816
9817 /**
9818 * Unregister RCS provisioning callback.
9819 */
9820 @Override
9821 public void unregisterRcsProvisioningChangedCallback(int subId,
9822 IRcsConfigCallback callback) {
9823 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9824
9825 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9826 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9827 }
9828 if (!isImsAvailableOnDevice()) {
9829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9830 "IMS not available on device.");
9831 }
9832
9833 final long identity = Binder.clearCallingIdentity();
9834 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009835 RcsProvisioningMonitor.getInstance()
9836 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009837 } finally {
9838 Binder.restoreCallingIdentity(identity);
9839 }
9840 }
9841
9842 /**
9843 * trigger RCS reconfiguration.
9844 */
9845 public void triggerRcsReconfiguration(int subId) {
9846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9847 mApp, subId, "triggerRcsReconfiguration");
9848
9849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9850 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9851 }
9852 if (!isImsAvailableOnDevice()) {
9853 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9854 "IMS not available on device.");
9855 }
9856
9857 final long identity = Binder.clearCallingIdentity();
9858 try {
9859 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
9864
9865 /**
9866 * Provide the client configuration parameters of the RCS application.
9867 */
9868 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9870 mApp, subId, "setRcsClientConfiguration");
9871
9872 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9873 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9874 }
9875 if (!isImsAvailableOnDevice()) {
9876 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9877 "IMS not available on device.");
9878 }
9879
9880 final long identity = Binder.clearCallingIdentity();
9881
9882 try {
9883 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9884 if (configBinder == null) {
9885 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9886 } else {
9887 configBinder.setRcsClientConfiguration(rcc);
9888 }
9889 } catch (RemoteException e) {
9890 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
9895
9896 /**
9897 * Overrides the config of RCS VoLTE single registration enabled for the device.
9898 */
9899 @Override
9900 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9902 "setDeviceSingleRegistrationEnabledOverride");
9903 enforceModifyPermission();
9904
9905 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9906 : Boolean.parseBoolean(enabledStr);
9907 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9908 }
9909
9910 /**
9911 * Gets the config of RCS VoLTE single registration enabled for the device.
9912 */
9913 @Override
9914 public boolean getDeviceSingleRegistrationEnabled() {
9915 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9916 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9917 }
9918
9919 /**
9920 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9921 */
9922 @Override
9923 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9925 "setCarrierSingleRegistrationEnabledOverride");
9926 enforceModifyPermission();
9927
9928 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9929 : Boolean.parseBoolean(enabledStr);
9930 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9931 subId, enabled);
9932 }
9933
9934 /**
9935 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9936 */
9937 @Override
9938 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9939 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9940 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9941 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009942
9943 /**
9944 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9945 * their mobile plan.
9946 */
9947 @Override
9948 public String getMobileProvisioningUrl() {
9949 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9950 final long identity = Binder.clearCallingIdentity();
9951 try {
9952 return getDefaultPhone().getMobileProvisioningUrl();
9953 } finally {
9954 Binder.restoreCallingIdentity(identity);
9955 }
9956 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009957
9958 @Override
9959 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9960 String callingPackage) {
9961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9962 mApp, subId, "setSignalStrengthUpdateRequest");
9963
9964 final int callingUid = Binder.getCallingUid();
9965 // Verify that tha callingPackage belongs to the calling UID
9966 mApp.getSystemService(AppOpsManager.class)
9967 .checkPackage(callingUid, callingPackage);
9968
9969 validateSignalStrengthUpdateRequest(request, callingUid);
9970
9971 final long identity = Binder.clearCallingIdentity();
9972 try {
9973 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9974 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9975
9976 if (result instanceof IllegalStateException) {
9977 throw (IllegalStateException) result;
9978 }
9979 } finally {
9980 Binder.restoreCallingIdentity(identity);
9981 }
9982 }
9983
9984 @Override
9985 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9986 String callingPackage) {
9987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9988 mApp, subId, "clearSignalStrengthUpdateRequest");
9989
9990 final int callingUid = Binder.getCallingUid();
9991 // Verify that tha callingPackage belongs to the calling UID
9992 mApp.getSystemService(AppOpsManager.class)
9993 .checkPackage(callingUid, callingPackage);
9994
9995 final long identity = Binder.clearCallingIdentity();
9996 try {
9997 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9998 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9999
10000 if (result instanceof IllegalStateException) {
10001 throw (IllegalStateException) result;
10002 }
10003 } finally {
10004 Binder.restoreCallingIdentity(identity);
10005 }
10006 }
10007
10008 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10009 int callingUid) {
10010 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10011 // phone/system process do not have further restriction on request
10012 return;
10013 }
10014
10015 // Applications has restrictions on how to use the request:
10016 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10017 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10018 // This is not system caller which has been checked above
10019 throw new IllegalArgumentException(
10020 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10021 }
10022
10023 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10024 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10025 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10026 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10027 || info.isEnabled()) {
10028 throw new IllegalArgumentException(
10029 "Only system can set hide fields in SignalThresholdInfo");
10030 }
10031
10032 // Thresholds length for each RAN need in range. This has been validated in
10033 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10034 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10035 final int[] thresholds = info.getThresholds();
10036 Objects.requireNonNull(thresholds);
10037 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10038 || thresholds.length
10039 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10040 throw new IllegalArgumentException(
10041 "thresholds length is out of range: " + thresholds.length);
10042 }
10043 }
10044 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010045
10046 /**
10047 * Gets the current phone capability.
10048 *
10049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10050 * @return the PhoneCapability which describes the data connection capability of modem.
10051 * It's used to evaluate possible phone config change, for example from single
10052 * SIM device to multi-SIM device.
10053 */
10054 @Override
10055 public PhoneCapability getPhoneCapability() {
10056 enforceReadPrivilegedPermission("getPhoneCapability");
10057 final long identity = Binder.clearCallingIdentity();
10058 try {
10059 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10060 } finally {
10061 Binder.restoreCallingIdentity(identity);
10062 }
10063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010064}