blob: 2c83ff999d98b0dcd6b372ee3316152491336c2c [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080029import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080067import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080091import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800134import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700136import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700137import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800138import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700143import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800144import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800145import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700146import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800148import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700152import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700155import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800156import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700157import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700158import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700159import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700160import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700161import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700162import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800164import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800165import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700167import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800168import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700169import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800170import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700171import com.android.internal.telephony.imsphone.ImsPhone;
172import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800173import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700174import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800176import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700179import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800182import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000183import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800184import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700185import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700186import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800188import com.android.phone.callcomposer.CallComposerPictureManager;
189import com.android.phone.callcomposer.CallComposerPictureTransfer;
190import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700191import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800193import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700194import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700195import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800196import com.android.services.telephony.TelecomAccountRegistry;
197import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800198import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800199
Hall Liu82694d52020-12-11 18:22:04 -0800200import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700201import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800202import java.io.IOException;
203import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700204import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800207import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800208import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800209import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100210import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800211import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700212import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800214import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800215import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800216import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800217import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218
219/**
220 * Implementation of the ITelephony interface.
221 */
Santos Cordon117fee72014-05-16 17:56:12 -0700222public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 private static final String LOG_TAG = "PhoneInterfaceManager";
224 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
225 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227
228 // Message codes used with mMainThreadHandler
229 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700230 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
231 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700232 private static final int CMD_OPEN_CHANNEL = 9;
233 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
234 private static final int CMD_CLOSE_CHANNEL = 11;
235 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800236 private static final int CMD_NV_READ_ITEM = 13;
237 private static final int EVENT_NV_READ_ITEM_DONE = 14;
238 private static final int CMD_NV_WRITE_ITEM = 15;
239 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
240 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
241 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700242 private static final int CMD_RESET_MODEM_CONFIG = 19;
243 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800244 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
245 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800246 private static final int CMD_SEND_ENVELOPE = 25;
247 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000248 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
249 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700250 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
251 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
252 private static final int CMD_EXCHANGE_SIM_IO = 31;
253 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800254 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
255 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700256 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
257 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700258 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
259 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700260 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
261 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
262 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
263 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700264 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
265 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
266 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
267 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700268 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800269 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
270 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000271 private static final int CMD_SWITCH_SLOTS = 50;
272 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700273 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
274 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
275 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
276 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
277 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
278 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
279 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
280 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700281 private static final int CMD_GET_ALL_CELL_INFO = 60;
282 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
283 private static final int CMD_GET_CELL_LOCATION = 62;
284 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700285 private static final int CMD_MODEM_REBOOT = 64;
286 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700287 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
288 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800289 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
290 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700291 private static final int CMD_GET_MODEM_STATUS = 70;
292 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700293 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
294 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700295 private static final int CMD_ERASE_MODEM_CONFIG = 74;
296 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800297 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
298 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
299 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
300 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800301 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
302 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800303 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800304 private static final int CMD_GET_CALL_FORWARDING = 83;
305 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
306 private static final int CMD_SET_CALL_FORWARDING = 85;
307 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
308 private static final int CMD_GET_CALL_WAITING = 87;
309 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
310 private static final int CMD_SET_CALL_WAITING = 89;
311 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700312 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
313 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
314 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
315 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700316 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
317 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800318 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
319 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800320 private static final int CMD_SET_DATA_THROTTLING = 99;
321 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800322 private static final int CMD_SET_SIM_POWER = 101;
323 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800324 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
325 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
326 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
327 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800328 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
329 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800331 // Parameters of select command.
332 private static final int SELECT_COMMAND = 0xA4;
333 private static final int SELECT_P1 = 0x04;
334 private static final int SELECT_P2 = 0;
335 private static final int SELECT_P3 = 0x10;
336
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 /** The singleton instance. */
338 private static PhoneInterfaceManager sInstance;
339
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800342 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700343 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800344 private AppOpsManager mAppOps;
345 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800346 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700348 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 /** User Activity */
351 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800352 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
353
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700354 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
355
Derek Tan97ebb422014-09-05 16:55:38 -0700356 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
357 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800358 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800359 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700360
Michelecea4cf22018-12-21 15:00:11 -0800361 // String to store multi SIM allowed
362 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
363
Derek Tan740e1672017-06-27 14:56:27 -0700364 // The AID of ISD-R.
365 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
366
yinxub1bed742017-04-17 11:45:04 -0700367 private NetworkScanRequestTracker mNetworkScanRequestTracker;
368
David Kelly5e06a7f2018-03-12 14:10:59 +0000369 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
370 private static final int MANUFACTURER_CODE_LENGTH = 8;
371
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800372 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
373
Derek Tan89e89d42014-07-08 17:00:10 -0700374 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700375 * Experiment flag to enable erase modem config on reset network, default value is false
376 */
377 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
378 "reset_network_erase_modem_config_enabled";
379
380 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700381 * A request object to use for transmitting data to an ICC.
382 */
383 private static final class IccAPDUArgument {
384 public int channel, cla, command, p1, p2, p3;
385 public String data;
386
387 public IccAPDUArgument(int channel, int cla, int command,
388 int p1, int p2, int p3, String data) {
389 this.channel = channel;
390 this.cla = cla;
391 this.command = command;
392 this.p1 = p1;
393 this.p2 = p2;
394 this.p3 = p3;
395 this.data = data;
396 }
397 }
398
399 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700400 * A request object to use for transmitting data to an ICC.
401 */
402 private static final class ManualNetworkSelectionArgument {
403 public OperatorInfo operatorInfo;
404 public boolean persistSelection;
405
406 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
407 this.operatorInfo = operatorInfo;
408 this.persistSelection = persistSelection;
409 }
410 }
411
412 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
414 * request after sending. The main thread will notify the request when it is complete.
415 */
416 private static final class MainThreadRequest {
417 /** The argument to use for the request */
418 public Object argument;
419 /** The result of the request that is run on the main thread */
420 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800421 // The subscriber id that this request applies to. Defaults to
422 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
423 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Nathan Harold92bed182018-10-12 18:16:49 -0700425 // In cases where subId is unavailable, the caller needs to specify the phone.
426 public Phone phone;
427
vagdeviaf9a5b92018-08-15 16:01:53 -0700428 public WorkSource workSource;
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 public MainThreadRequest(Object argument) {
431 this.argument = argument;
432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800433
Nathan Harold92bed182018-10-12 18:16:49 -0700434 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
435 this.argument = argument;
436 if (phone != null) {
437 this.phone = phone;
438 }
439 this.workSource = workSource;
440 }
441
vagdeviaf9a5b92018-08-15 16:01:53 -0700442 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800444 if (subId != null) {
445 this.subId = subId;
446 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700447 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 }
450
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800451 private static final class IncomingThirdPartyCallArgs {
452 public final ComponentName component;
453 public final String callId;
454 public final String callerDisplayName;
455
456 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
457 String callerDisplayName) {
458 this.component = component;
459 this.callId = callId;
460 this.callerDisplayName = callerDisplayName;
461 }
462 }
463
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 /**
465 * A handler that processes messages on the main thread in the phone process. Since many
466 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
467 * inbound binder threads to the main thread in the phone process. The Binder thread
468 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
469 * on, which will be notified when the operation completes and will contain the result of the
470 * request.
471 *
472 * <p>If a MainThreadRequest object is provided in the msg.obj field,
473 * note that request.result must be set to something non-null for the calling thread to
474 * unblock.
475 */
476 private final class MainThreadHandler extends Handler {
477 @Override
478 public void handleMessage(Message msg) {
479 MainThreadRequest request;
480 Message onCompleted;
481 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800484 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
486 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 case CMD_HANDLE_USSD_REQUEST: {
488 request = (MainThreadRequest) msg.obj;
489 final Phone phone = getPhoneFromRequest(request);
490 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
491 String ussdRequest = ussdObject.first;
492 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700493
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 if (!isUssdApiAllowed(request.subId)) {
495 // Carrier does not support use of this API, return failure.
496 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
497 UssdResponse response = new UssdResponse(ussdRequest, null);
498 Bundle returnData = new Bundle();
499 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
500 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700501
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 request.result = true;
503 notifyRequester(request);
504 return;
505 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700506
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 try {
508 request.result = phone != null
509 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
510 } catch (CallStateException cse) {
511 request.result = false;
512 }
513 // Wake up the requesting thread
514 notifyRequester(request);
515 break;
pkanwar32d516d2016-10-14 19:37:38 -0700516 }
517
Yorke Lee716f67e2015-06-17 15:39:16 -0700518 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 final Phone phone = getPhoneFromRequest(request);
521 request.result = phone != null ?
522 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
523 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800532 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 if (uiccCard == null) {
534 loge("iccTransmitApduLogicalChannel: No UICC");
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
539 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 iccArgument.channel, iccArgument.cla, iccArgument.command,
542 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 break;
546
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 ar = (AsyncResult) msg.obj;
549 request = (MainThreadRequest) ar.userObj;
550 if (ar.exception == null && ar.result != null) {
551 request.result = ar.result;
552 } else {
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
554 if (ar.result == null) {
555 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800556 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800558 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 } else {
560 loge("iccTransmitApduLogicalChannel: Unknown exception");
561 }
562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
568 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800569 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (uiccCard == null) {
571 loge("iccTransmitApduBasicChannel: No UICC");
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
576 request);
577 uiccCard.iccTransmitApduBasicChannel(
578 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
579 iccArgument.p3, iccArgument.data, onCompleted);
580 }
581 break;
582
583 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
586 if (ar.exception == null && ar.result != null) {
587 request.result = ar.result;
588 } else {
589 request.result = new IccIoResult(0x6F, 0, (byte[])null);
590 if (ar.result == null) {
591 loge("iccTransmitApduBasicChannel: Empty response");
592 } else if (ar.exception instanceof CommandException) {
593 loge("iccTransmitApduBasicChannel: CommandException: " +
594 ar.exception);
595 } else {
596 loge("iccTransmitApduBasicChannel: Unknown exception");
597 }
598 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 break;
601
602 case CMD_EXCHANGE_SIM_IO:
603 request = (MainThreadRequest) msg.obj;
604 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800605 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 if (uiccCard == null) {
607 loge("iccExchangeSimIO: No UICC");
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 } else {
611 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
612 request);
613 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
614 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
615 iccArgument.data, onCompleted);
616 }
617 break;
618
619 case EVENT_EXCHANGE_SIM_IO_DONE:
620 ar = (AsyncResult) msg.obj;
621 request = (MainThreadRequest) ar.userObj;
622 if (ar.exception == null && ar.result != null) {
623 request.result = ar.result;
624 } else {
625 request.result = new IccIoResult(0x6f, 0, (byte[])null);
626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 break;
629
Derek Tan4d5e5c12014-02-04 11:54:58 -0800630 case CMD_SEND_ENVELOPE:
631 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800632 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 if (uiccCard == null) {
634 loge("sendEnvelopeWithStatus: No UICC");
635 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 } else {
638 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
639 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
640 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 break;
642
643 case EVENT_SEND_ENVELOPE_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700649 request.result = new IccIoResult(0x6F, 0, (byte[])null);
650 if (ar.result == null) {
651 loge("sendEnvelopeWithStatus: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("sendEnvelopeWithStatus: CommandException: " +
654 ar.exception);
655 } else {
656 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
657 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 break;
661
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 case CMD_OPEN_CHANNEL:
663 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800664 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800665 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 if (uiccCard == null) {
667 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800668 request.result = new IccOpenLogicalChannelResponse(-1,
669 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 } else {
672 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800673 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
674 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case EVENT_OPEN_CHANNEL_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 int[] result = (int[]) ar.result;
684 int channelId = result[0];
685 byte[] selectResponse = null;
686 if (result.length > 1) {
687 selectResponse = new byte[result.length - 1];
688 for (int i = 1; i < result.length; ++i) {
689 selectResponse[i - 1] = (byte) result[i];
690 }
691 }
692 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700693 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 if (ar.result == null) {
696 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 if (ar.exception != null) {
699 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
700 }
701
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700703 if (ar.exception instanceof CommandException) {
704 CommandException.Error error =
705 ((CommandException) (ar.exception)).getCommandError();
706 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700708 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(
713 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700715 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
719 case CMD_CLOSE_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800721 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 if (uiccCard == null) {
723 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900724 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 } else {
727 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
728 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
729 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 break;
731
732 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800733 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
734 break;
735
736 case CMD_NV_READ_ITEM:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
740 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
743 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 ar = (AsyncResult) msg.obj;
745 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800746 if (ar.exception == null && ar.result != null) {
747 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800749 request.result = "";
750 if (ar.result == null) {
751 loge("nvReadItem: Empty response");
752 } else if (ar.exception instanceof CommandException) {
753 loge("nvReadItem: CommandException: " +
754 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800756 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
Jake Hambye994d462014-02-03 13:10:13 -0800762 case CMD_NV_WRITE_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
765 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700767 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800768 break;
769
770 case EVENT_NV_WRITE_ITEM_DONE:
771 handleNullReturnEvent(msg, "nvWriteItem");
772 break;
773
774 case CMD_NV_WRITE_CDMA_PRL:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800777 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
780 case EVENT_NV_WRITE_CDMA_PRL_DONE:
781 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
782 break;
783
chen xu6dac5ab2018-10-26 17:39:23 -0700784 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800785 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700786 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
chen xu6dac5ab2018-10-26 17:39:23 -0700790 case EVENT_RESET_MODEM_CONFIG_DONE:
791 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
Sooraj Sasindran37444802020-08-11 10:40:43 -0700794 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
797 request);
798 Phone phone = getPhoneFromRequest(request);
799 if (phone != null) {
800 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
801 } else {
802 loge("isNRDualConnectivityEnabled: No phone object");
803 request.result = false;
804 notifyRequester(request);
805 }
806 break;
807 }
808
809 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 // request.result must be set to something non-null
816 // for the calling thread to unblock
817 if (request.result != null) {
818 request.result = ar.result;
819 } else {
820 request.result = false;
821 }
822 if (ar.result == null) {
823 loge("isNRDualConnectivityEnabled: Empty response");
824 } else if (ar.exception instanceof CommandException) {
825 loge("isNRDualConnectivityEnabled: CommandException: "
826 + ar.exception);
827 } else {
828 loge("isNRDualConnectivityEnabled: Unknown exception");
829 }
830 }
831 notifyRequester(request);
832 break;
833
834 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
837 Phone phone = getPhoneFromRequest(request);
838 if (phone != null) {
839 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
840 request.workSource);
841 } else {
842 loge("enableNrDualConnectivity: No phone object");
843 request.result =
844 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
845 notifyRequester(request);
846 }
847 break;
848 }
849
850 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null) {
854 request.result =
855 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
856 } else {
857 request.result =
858 TelephonyManager
859 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
860 if (ar.exception instanceof CommandException) {
861 CommandException.Error error =
862 ((CommandException) (ar.exception)).getCommandError();
863 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
864 request.result =
865 TelephonyManager
866 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
867 }
868 loge("enableNrDualConnectivity" + ": CommandException: "
869 + ar.exception);
870 } else {
871 loge("enableNrDualConnectivity" + ": Unknown exception");
872 }
873 }
874 notifyRequester(request);
875 break;
876 }
877
SongFerngWang3ef3e072020-12-21 16:41:52 +0800878 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800880 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
881 request);
882 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800883 break;
884
SongFerngWang3ef3e072020-12-21 16:41:52 +0800885 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result; // Integer
890 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530891 // request.result must be set to something non-null
892 // for the calling thread to unblock
893 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800895 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800897 loge("getAllowedNetworkTypesBitmask: CommandException: "
898 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 break;
905
SongFerngWang3ef3e072020-12-21 16:41:52 +0800906 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800908 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
909 request);
910 Pair<Integer, Long> reasonWithNetworkTypes =
911 (Pair<Integer, Long>) request.argument;
912 getPhoneFromRequest(request).setAllowedNetworkTypes(
913 reasonWithNetworkTypes.first,
914 reasonWithNetworkTypes.second,
915 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 break;
917
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
919 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 break;
921
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000922 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
923 request = (MainThreadRequest)msg.obj;
924 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800925 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000926 break;
927
928 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
929 ar = (AsyncResult)msg.obj;
930 request = (MainThreadRequest)ar.userObj;
931 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000933 break;
934
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800935 case CMD_SET_VOICEMAIL_NUMBER:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
938 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800939 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
940 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800941 break;
942
943 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
944 handleNullReturnEvent(msg, "setVoicemailNumber");
945 break;
946
Stuart Scott54788802015-03-30 13:18:01 -0700947 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
950 request);
951 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
952 break;
953
954 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
955 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
956 break;
957
Shishir Agrawal302c8692015-06-19 13:49:39 -0700958 case CMD_PERFORM_NETWORK_SCAN:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
961 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
962 break;
963
Hall Liu27d24262020-09-18 19:04:59 -0700964 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700967 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
968 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
969 request.argument;
970 int callForwardingReason = args.first;
971 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800972 break;
Hall Liu27d24262020-09-18 19:04:59 -0700973 }
974 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700977 TelephonyManager.CallForwardingInfoCallback callback =
978 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
979 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800980 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700981 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800982 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
983 for (CallForwardInfo callForwardInfo : callForwardInfos) {
984 // Service Class is a bit mask per 3gpp 27.007. Search for
985 // any service for voice call.
986 if ((callForwardInfo.serviceClass
987 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700988 callForwardingInfo = new CallForwardingInfo(true,
989 callForwardInfo.reason,
990 callForwardInfo.number,
991 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800992 break;
993 }
994 }
995 // Didn't find a call forward info for voice call.
996 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700997 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
998 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800999 }
Hall Liu27d24262020-09-18 19:04:59 -07001000 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001001 } else {
1002 if (ar.result == null) {
1003 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1004 }
1005 if (ar.exception != null) {
1006 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1007 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001008 int errorCode = TelephonyManager
1009 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001010 if (ar.exception instanceof CommandException) {
1011 CommandException.Error error =
1012 ((CommandException) (ar.exception)).getCommandError();
1013 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001014 errorCode = TelephonyManager
1015 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001016 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001017 errorCode = TelephonyManager
1018 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001019 }
1020 }
Hall Liu27d24262020-09-18 19:04:59 -07001021 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001022 }
Shuo Qian4a594052020-01-23 11:59:30 -08001023 break;
Hall Liu27d24262020-09-18 19:04:59 -07001024 }
Shuo Qian4a594052020-01-23 11:59:30 -08001025
Hall Liu27d24262020-09-18 19:04:59 -07001026 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001029 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001030 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001031 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1032 request.argument).first;
1033 request.phone.setCallForwardingOption(
1034 callForwardingInfoToSet.isEnabled()
1035 ? CommandsInterface.CF_ACTION_ENABLE
1036 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001037 callForwardingInfoToSet.getReason(),
1038 callForwardingInfoToSet.getNumber(),
1039 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1040 break;
Hall Liu27d24262020-09-18 19:04:59 -07001041 }
Shuo Qian4a594052020-01-23 11:59:30 -08001042
Hall Liu27d24262020-09-18 19:04:59 -07001043 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001046 Consumer<Integer> callback =
1047 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1048 request.argument).second;
1049 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001050 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001051 int errorCode = TelephonyManager.CallForwardingInfoCallback
1052 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001053 if (ar.exception instanceof CommandException) {
1054 CommandException.Error error =
1055 ((CommandException) (ar.exception)).getCommandError();
1056 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001057 errorCode = TelephonyManager.CallForwardingInfoCallback
1058 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001059 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001060 errorCode = TelephonyManager.CallForwardingInfoCallback
1061 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001062 }
1063 }
1064 callback.accept(errorCode);
1065 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001066 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001067 }
Shuo Qian4a594052020-01-23 11:59:30 -08001068 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 CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1074 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1075 break;
Hall Liu27d24262020-09-18 19:04:59 -07001076 }
Shuo Qian4a594052020-01-23 11:59:30 -08001077
Hall Liu27d24262020-09-18 19:04:59 -07001078 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001081 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001082 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1083 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001084 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001085 // Service Class is a bit mask per 3gpp 27.007.
1086 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001087 if (callForwardResults.length > 1
1088 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001089 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001090 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001091 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1092 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001094 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 }
1096 } else {
1097 if (ar.result == null) {
1098 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1099 }
1100 if (ar.exception != null) {
1101 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1102 }
1103 if (ar.exception instanceof CommandException) {
1104 CommandException.Error error =
1105 ((CommandException) (ar.exception)).getCommandError();
1106 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1107 callForwardingStatus =
1108 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1109 }
1110 }
1111 }
Hall Liu27d24262020-09-18 19:04:59 -07001112 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001113 break;
Hall Liu27d24262020-09-18 19:04:59 -07001114 }
Shuo Qian4a594052020-01-23 11:59:30 -08001115
Hall Liu27d24262020-09-18 19:04:59 -07001116 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001119 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1120 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001121 break;
Hall Liu27d24262020-09-18 19:04:59 -07001122 }
Shuo Qian4a594052020-01-23 11:59:30 -08001123
Hall Liu27d24262020-09-18 19:04:59 -07001124 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001127 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1128 Consumer<Integer> callback =
1129 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1130 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001131 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001132 if (ar.exception instanceof CommandException) {
1133 CommandException.Error error =
1134 ((CommandException) (ar.exception)).getCommandError();
1135 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1136 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1137 } else {
1138 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1139 }
1140 } else {
1141 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1142 }
1143 } else {
1144 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1145 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001146 }
Shuo Qian4a594052020-01-23 11:59:30 -08001147 break;
Hall Liu27d24262020-09-18 19:04:59 -07001148 }
Shuo Qian4a594052020-01-23 11:59:30 -08001149
Shishir Agrawal302c8692015-06-19 13:49:39 -07001150 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
1153 CellNetworkScanResult cellScanResult;
1154 if (ar.exception == null && ar.result != null) {
1155 cellScanResult = new CellNetworkScanResult(
1156 CellNetworkScanResult.STATUS_SUCCESS,
1157 (List<OperatorInfo>) ar.result);
1158 } else {
1159 if (ar.result == null) {
1160 loge("getCellNetworkScanResults: Empty response");
1161 }
1162 if (ar.exception != null) {
1163 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1164 }
1165 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1166 if (ar.exception instanceof CommandException) {
1167 CommandException.Error error =
1168 ((CommandException) (ar.exception)).getCommandError();
1169 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1170 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1171 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1172 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1173 }
1174 }
1175 cellScanResult = new CellNetworkScanResult(errorCode, null);
1176 }
1177 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001178 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001179 break;
1180
1181 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1182 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001183 ManualNetworkSelectionArgument selArg =
1184 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001185 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1186 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001187 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1188 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
1191 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001192 ar = (AsyncResult) msg.obj;
1193 request = (MainThreadRequest) ar.userObj;
1194 if (ar.exception == null) {
1195 request.result = true;
1196 } else {
1197 request.result = false;
1198 loge("setNetworkSelectionModeManual " + ar.exception);
1199 }
1200 notifyRequester(request);
1201 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 break;
1203
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001204 case CMD_GET_MODEM_ACTIVITY_INFO:
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001207 if (defaultPhone != null) {
1208 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001209 } else {
1210 ResultReceiver result = (ResultReceiver) request.argument;
1211 Bundle bundle = new Bundle();
1212 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001213 new ModemActivityInfo(0, 0, 0,
1214 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001215 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001216 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001217 break;
1218
Hall Liud0f208c2020-10-14 16:54:44 -07001219 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001222 ResultReceiver result = (ResultReceiver) request.argument;
1223
Hall Liud0f208c2020-10-14 16:54:44 -07001224 ModemActivityInfo ret = null;
1225 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001227 // Update the last modem activity info and the result of the request.
1228 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1229 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001230 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001231 int[] txTimeMs = info.getTransmitTimeMillis();
1232 int[] lastModemTxTimeMs = mLastModemActivityInfo
1233 .getTransmitTimeMillis();
1234 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1235 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1236 }
Hall Liu49656c02020-10-09 19:00:11 -07001237 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001238 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1239 + mLastModemActivityInfo.getSleepTimeMillis());
1240 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1241 + mLastModemActivityInfo.getIdleTimeMillis());
1242 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1243 mLastModemActivityInfo.setReceiveTimeMillis(
1244 info.getReceiveTimeMillis()
1245 + mLastModemActivityInfo.getReceiveTimeMillis());
1246 }
Hall Liu49656c02020-10-09 19:00:11 -07001247 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001248 mLastModemActivityInfo.getSleepTimeMillis(),
1249 mLastModemActivityInfo.getIdleTimeMillis(),
1250 mLastModemActivityInfo.getTransmitTimeMillis(),
1251 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001252 } else {
1253 if (ar.result == null) {
1254 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001255 error = TelephonyManager.ModemActivityInfoException
1256 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001257 } else if (ar.exception instanceof CommandException) {
1258 loge("queryModemActivityInfo: CommandException: " +
1259 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001260 error = TelephonyManager.ModemActivityInfoException
1261 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001262 } else {
1263 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001264 error = TelephonyManager.ModemActivityInfoException
1265 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001266 }
1267 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001268 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001269 if (ret != null) {
1270 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1271 } else {
1272 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1273 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001274 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001275 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001277 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001278
Meng Wang1a7c35a2016-05-05 20:56:15 -07001279 case CMD_SET_ALLOWED_CARRIERS:
1280 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001281 CarrierRestrictionRules argument =
1282 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001283 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001284 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001285 break;
1286
1287 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1288 ar = (AsyncResult) msg.obj;
1289 request = (MainThreadRequest) ar.userObj;
1290 if (ar.exception == null && ar.result != null) {
1291 request.result = ar.result;
1292 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001293 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1294 if (ar.exception instanceof CommandException) {
1295 loge("setAllowedCarriers: CommandException: " + ar.exception);
1296 CommandException.Error error =
1297 ((CommandException) (ar.exception)).getCommandError();
1298 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1299 request.result =
1300 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1301 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 } else {
1303 loge("setAllowedCarriers: Unknown exception");
1304 }
1305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001306 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 break;
1308
1309 case CMD_GET_ALLOWED_CARRIERS:
1310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001312 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001313 break;
1314
1315 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
1318 if (ar.exception == null && ar.result != null) {
1319 request.result = ar.result;
1320 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001321 request.result = new IllegalStateException(
1322 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 if (ar.result == null) {
1324 loge("getAllowedCarriers: Empty response");
1325 } else if (ar.exception instanceof CommandException) {
1326 loge("getAllowedCarriers: CommandException: " +
1327 ar.exception);
1328 } else {
1329 loge("getAllowedCarriers: Unknown exception");
1330 }
1331 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001332 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001333 break;
1334
Nathan Haroldb3014052017-01-25 15:57:32 -08001335 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 if (ar.exception == null && ar.result != null) {
1339 request.result = ar.result;
1340 } else {
1341 request.result = new IllegalArgumentException(
1342 "Failed to retrieve Forbidden Plmns");
1343 if (ar.result == null) {
1344 loge("getForbiddenPlmns: Empty response");
1345 } else {
1346 loge("getForbiddenPlmns: Unknown exception");
1347 }
1348 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001349 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001350 break;
1351
1352 case CMD_GET_FORBIDDEN_PLMNS:
1353 request = (MainThreadRequest) msg.obj;
1354 uiccCard = getUiccCardFromRequest(request);
1355 if (uiccCard == null) {
1356 loge("getForbiddenPlmns() UiccCard is null");
1357 request.result = new IllegalArgumentException(
1358 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 break;
1361 }
1362 Integer appType = (Integer) request.argument;
1363 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1364 if (uiccApp == null) {
1365 loge("getForbiddenPlmns() no app with specified type -- "
1366 + appType);
1367 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001368 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001369 break;
1370 } else {
1371 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1372 + " specified type -- " + appType);
1373 }
1374 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1375 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1376 onCompleted);
1377 break;
1378
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001379 case CMD_SWITCH_SLOTS:
1380 request = (MainThreadRequest) msg.obj;
1381 int[] physicalSlots = (int[]) request.argument;
1382 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1383 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1384 break;
1385
1386 case EVENT_SWITCH_SLOTS_DONE:
1387 ar = (AsyncResult) msg.obj;
1388 request = (MainThreadRequest) ar.userObj;
1389 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001390 notifyRequester(request);
1391 break;
1392 case CMD_GET_NETWORK_SELECTION_MODE:
1393 request = (MainThreadRequest) msg.obj;
1394 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1395 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1396 break;
1397
1398 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception != null) {
1402 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1403 } else {
1404 int mode = ((int[]) ar.result)[0];
1405 if (mode == 0) {
1406 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1407 } else {
1408 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1409 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001410 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001411 notifyRequester(request);
1412 break;
1413 case CMD_GET_CDMA_ROAMING_MODE:
1414 request = (MainThreadRequest) msg.obj;
1415 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1416 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1417 break;
1418 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception != null) {
1422 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1423 } else {
1424 request.result = ((int[]) ar.result)[0];
1425 }
1426 notifyRequester(request);
1427 break;
1428 case CMD_SET_CDMA_ROAMING_MODE:
1429 request = (MainThreadRequest) msg.obj;
1430 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1431 int mode = (int) request.argument;
1432 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1433 break;
1434 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
1437 request.result = ar.exception == null;
1438 notifyRequester(request);
1439 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001440 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1443 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1444 break;
1445 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception != null) {
1449 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1450 } else {
1451 request.result = ((int[]) ar.result)[0];
1452 }
1453 notifyRequester(request);
1454 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001455 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1458 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001459 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1460 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 break;
1462 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1463 ar = (AsyncResult) msg.obj;
1464 request = (MainThreadRequest) ar.userObj;
1465 request.result = ar.exception == null;
1466 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001467 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001468 case CMD_GET_ALL_CELL_INFO:
1469 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001471 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001472 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001473 case EVENT_GET_ALL_CELL_INFO_DONE:
1474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001476 // If a timeout occurs, the response will be null
1477 request.result = (ar.exception == null && ar.result != null)
1478 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001479 synchronized (request) {
1480 request.notifyAll();
1481 }
1482 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001483 case CMD_REQUEST_CELL_INFO_UPDATE:
1484 request = (MainThreadRequest) msg.obj;
1485 request.phone.requestCellInfoUpdate(request.workSource,
1486 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1487 break;
1488 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1489 ar = (AsyncResult) msg.obj;
1490 request = (MainThreadRequest) ar.userObj;
1491 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1492 try {
1493 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001494 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001495 cb.onError(
1496 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1497 ar.exception.getClass().getName(),
1498 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001499 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001500 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001501 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001502 } else {
1503 // use the result as returned
1504 cb.onCellInfo((List<CellInfo>) ar.result);
1505 }
1506 } catch (RemoteException re) {
1507 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1508 }
1509 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001510 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001511 request = (MainThreadRequest) msg.obj;
1512 WorkSource ws = (WorkSource) request.argument;
1513 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001514 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001515 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001516 }
1517 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001518 ar = (AsyncResult) msg.obj;
1519 request = (MainThreadRequest) ar.userObj;
1520 if (ar.exception == null) {
1521 request.result = ar.result;
1522 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001523 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001524 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001525 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001526 }
1527
1528 synchronized (request) {
1529 request.notifyAll();
1530 }
1531 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001532 }
chen xu6dac5ab2018-10-26 17:39:23 -07001533 case CMD_MODEM_REBOOT:
1534 request = (MainThreadRequest) msg.obj;
1535 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001536 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001537 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001538 case EVENT_CMD_MODEM_REBOOT_DONE:
1539 handleNullReturnEvent(msg, "rebootModem");
1540 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001541 case CMD_REQUEST_ENABLE_MODEM:
1542 request = (MainThreadRequest) msg.obj;
1543 boolean enable = (boolean) request.argument;
1544 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001545 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001546 PhoneConfigurationManager.getInstance()
1547 .enablePhone(request.phone, enable, onCompleted);
1548 break;
1549 case EVENT_ENABLE_MODEM_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001553 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001554 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001555 if ((boolean) request.result) {
1556 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1557 updateModemStateMetrics();
1558 } else {
1559 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1560 + ar.exception);
1561 }
1562 notifyRequester(request);
1563 break;
1564 case CMD_GET_MODEM_STATUS:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1567 PhoneConfigurationManager.getInstance()
1568 .getPhoneStatusFromModem(request.phone, onCompleted);
1569 break;
1570 case EVENT_GET_MODEM_STATUS_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 int id = request.phone.getPhoneId();
1574 if (ar.exception == null && ar.result != null) {
1575 request.result = ar.result;
1576 //update the cache as modem status has changed
1577 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1578 (boolean) request.result);
1579 } else {
1580 // Return true if modem status cannot be retrieved. For most cases,
1581 // modem status is on. And for older version modems, GET_MODEM_STATUS
1582 // and disable modem are not supported. Modem is always on.
1583 // TODO: this should be fixed in R to support a third
1584 // status UNKNOWN b/131631629
1585 request.result = true;
1586 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1587 + ar.exception);
1588 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001589 notifyRequester(request);
1590 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001591 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1594 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1595 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1596 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1597 break;
1598 }
1599 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1603 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1604 args.second.accept(ar.exception == null);
1605 notifyRequester(request);
1606 break;
1607 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001608 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1609 request = (MainThreadRequest) msg.obj;
1610 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1611 Phone phone = getPhoneFromRequest(request);
1612 if (phone != null) {
1613 phone.getSystemSelectionChannels(onCompleted);
1614 } else {
1615 loge("getSystemSelectionChannels: No phone object");
1616 request.result = new ArrayList<RadioAccessSpecifier>();
1617 notifyRequester(request);
1618 }
1619 break;
1620 }
1621 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 if (ar.exception == null && ar.result != null) {
1625 request.result = ar.result;
1626 } else {
1627 request.result = new IllegalArgumentException(
1628 "Failed to retrieve system selection channels");
1629 if (ar.result == null) {
1630 loge("getSystemSelectionChannels: Empty response");
1631 } else {
1632 loge("getSystemSelectionChannels: Unknown exception");
1633 }
1634 }
1635 notifyRequester(request);
1636 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001637 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception == null && ar.result != null) {
1641 request.result = ar.result;
1642 } else {
1643 request.result = -1;
1644 loge("Failed to set Forbidden Plmns");
1645 if (ar.result == null) {
1646 loge("setForbidenPlmns: Empty response");
1647 } else if (ar.exception != null) {
1648 loge("setForbiddenPlmns: Exception: " + ar.exception);
1649 request.result = -1;
1650 } else {
1651 loge("setForbiddenPlmns: Unknown exception");
1652 }
1653 }
1654 notifyRequester(request);
1655 break;
1656 case CMD_SET_FORBIDDEN_PLMNS:
1657 request = (MainThreadRequest) msg.obj;
1658 uiccCard = getUiccCardFromRequest(request);
1659 if (uiccCard == null) {
1660 loge("setForbiddenPlmns: UiccCard is null");
1661 request.result = -1;
1662 notifyRequester(request);
1663 break;
1664 }
1665 Pair<Integer, List<String>> setFplmnsArgs =
1666 (Pair<Integer, List<String>>) request.argument;
1667 appType = setFplmnsArgs.first;
1668 List<String> fplmns = setFplmnsArgs.second;
1669 uiccApp = uiccCard.getApplicationByType(appType);
1670 if (uiccApp == null) {
1671 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1672 request.result = -1;
1673 loge("Failed to get UICC App");
1674 notifyRequester(request);
1675 } else {
1676 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1677 ((SIMRecords) uiccApp.getIccRecords())
1678 .setForbiddenPlmns(onCompleted, fplmns);
1679 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001680 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001681 case CMD_ERASE_MODEM_CONFIG:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1684 defaultPhone.eraseModemConfig(onCompleted);
1685 break;
1686 case EVENT_ERASE_MODEM_CONFIG_DONE:
1687 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001688 break;
zoey chene02881a2019-12-30 16:11:23 +08001689
1690 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1691 request = (MainThreadRequest) msg.obj;
1692 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1693 Pair<String, String> changed = (Pair<String, String>) request.argument;
1694 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1695 changed.first, changed.second, onCompleted);
1696 break;
1697 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception == null) {
1701 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1702 } else {
1703 request.result = msg.arg1;
1704 }
1705 notifyRequester(request);
1706 break;
1707
1708 case CMD_SET_ICC_LOCK_ENABLED:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1711 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1712 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1713 enabled.first, enabled.second, onCompleted);
1714 break;
1715 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 if (ar.exception == null) {
1719 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1720 } else {
1721 request.result = msg.arg1;
1722 }
1723 notifyRequester(request);
1724 break;
1725
Peter Wangdafb9ac2020-01-15 14:13:38 -08001726 case MSG_NOTIFY_USER_ACTIVITY:
1727 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001728 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001729 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1730 getDefaultPhone().getContext().sendBroadcastAsUser(
1731 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1732 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001733
1734 case CMD_SET_DATA_THROTTLING: {
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1737 DataThrottlingRequest dataThrottlingRequest =
1738 (DataThrottlingRequest) request.argument;
1739 Phone phone = getPhoneFromRequest(request);
1740 if (phone != null) {
1741 phone.setDataThrottling(onCompleted,
1742 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1743 dataThrottlingRequest.getCompletionDurationMillis());
1744 } else {
1745 loge("setDataThrottling: No phone object");
1746 request.result =
1747 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1748 notifyRequester(request);
1749 }
1750
1751 break;
1752 }
1753 case EVENT_SET_DATA_THROTTLING_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756
1757 if (ar.exception == null) {
1758 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1759 } else if (ar.exception instanceof CommandException) {
1760 loge("setDataThrottling: CommandException: " + ar.exception);
1761 CommandException.Error error =
1762 ((CommandException) (ar.exception)).getCommandError();
1763
1764 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1765 request.result = TelephonyManager
1766 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1767 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1768 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1769 } else {
1770 request.result =
1771 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1772 }
1773 } else {
1774 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1775 }
1776 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1777 notifyRequester(request);
1778 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001779
1780 case CMD_SET_SIM_POWER: {
1781 request = (MainThreadRequest) msg.obj;
1782 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1783 request = (MainThreadRequest) msg.obj;
1784 int stateToSet =
1785 ((Pair<Integer, IIntegerConsumer>)
1786 request.argument).first;
1787 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1788 break;
1789 }
1790 case EVENT_SET_SIM_POWER_DONE: {
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793 IIntegerConsumer callback =
1794 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1795 if (ar.exception != null) {
1796 loge("setSimPower exception: " + ar.exception);
1797 int errorCode = TelephonyManager.CallForwardingInfoCallback
1798 .RESULT_ERROR_UNKNOWN;
1799 if (ar.exception instanceof CommandException) {
1800 CommandException.Error error =
1801 ((CommandException) (ar.exception)).getCommandError();
1802 if (error == CommandException.Error.SIM_ERR) {
1803 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1804 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1805 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1806 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1807 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1808 } else {
1809 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1810 }
1811 }
1812 try {
1813 callback.accept(errorCode);
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 } else {
1819 try {
1820 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1821 } catch (RemoteException e) {
1822 // Ignore if the remote process is no longer available to call back.
1823 Log.w(LOG_TAG, "setSimPower: callback not available.");
1824 }
1825 }
1826 break;
1827 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001828 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1829 request = (MainThreadRequest) msg.obj;
1830
1831 final Phone phone = getPhoneFromRequest(request);
1832 if (phone == null || phone.getServiceStateTracker() == null) {
1833 request.result = new IllegalStateException("Phone or SST is null");
1834 notifyRequester(request);
1835 break;
1836 }
1837
1838 Pair<Integer, SignalStrengthUpdateRequest> pair =
1839 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1840 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1841 request);
1842 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1843 request.subId, pair.first /*callingUid*/,
1844 pair.second /*request*/, onCompleted);
1845 break;
1846 }
1847 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1848 ar = (AsyncResult) msg.obj;
1849 request = (MainThreadRequest) ar.userObj;
1850 // request.result will be the exception of ar if present, true otherwise.
1851 // Be cautious not to leave result null which will wait() forever
1852 request.result = ar.exception != null ? ar.exception : true;
1853 notifyRequester(request);
1854 break;
1855 }
1856 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1857 request = (MainThreadRequest) msg.obj;
1858
1859 Phone phone = getPhoneFromRequest(request);
1860 if (phone == null || phone.getServiceStateTracker() == null) {
1861 request.result = new IllegalStateException("Phone or SST is null");
1862 notifyRequester(request);
1863 break;
1864 }
1865
1866 Pair<Integer, SignalStrengthUpdateRequest> pair =
1867 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1868 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1869 request);
1870 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1871 request.subId, pair.first /*callingUid*/,
1872 pair.second /*request*/, onCompleted);
1873 break;
1874 }
1875 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1876 ar = (AsyncResult) msg.obj;
1877 request = (MainThreadRequest) ar.userObj;
1878 request.result = ar.exception != null ? ar.exception : true;
1879 notifyRequester(request);
1880 break;
1881 }
Jordan Liu109698e2020-11-24 14:50:34 -08001882
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 default:
1884 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1885 break;
1886 }
1887 }
Jake Hambye994d462014-02-03 13:10:13 -08001888
Pengquan Menga1bb6272018-09-06 09:59:22 -07001889 private void notifyRequester(MainThreadRequest request) {
1890 synchronized (request) {
1891 request.notifyAll();
1892 }
1893 }
1894
Jake Hambye994d462014-02-03 13:10:13 -08001895 private void handleNullReturnEvent(Message msg, String command) {
1896 AsyncResult ar = (AsyncResult) msg.obj;
1897 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1898 if (ar.exception == null) {
1899 request.result = true;
1900 } else {
1901 request.result = false;
1902 if (ar.exception instanceof CommandException) {
1903 loge(command + ": CommandException: " + ar.exception);
1904 } else {
1905 loge(command + ": Unknown exception");
1906 }
1907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001908 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
1912 /**
1913 * Posts the specified command to be executed on the main thread,
1914 * waits for the request to complete, and returns the result.
1915 * @see #sendRequestAsync
1916 */
1917 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001918 return sendRequest(
1919 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001920 }
1921
1922 /**
1923 * Posts the specified command to be executed on the main thread,
1924 * waits for the request to complete, and returns the result.
1925 * @see #sendRequestAsync
1926 */
1927 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1928 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001929 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001930 }
1931
1932 /**
1933 * Posts the specified command to be executed on the main thread,
1934 * waits for the request to complete, and returns the result.
1935 * @see #sendRequestAsync
1936 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001937 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001938 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001939 }
1940
1941 /**
1942 * Posts the specified command to be executed on the main thread,
1943 * waits for the request to complete, and returns the result.
1944 * @see #sendRequestAsync
1945 */
Nathan Harold92bed182018-10-12 18:16:49 -07001946 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1947 return sendRequest(command, argument, subId, null, workSource);
1948 }
1949
1950 /**
1951 * Posts the specified command to be executed on the main thread,
1952 * waits for the request to complete, and returns the result.
1953 * @see #sendRequestAsync
1954 */
1955 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1956 return sendRequest(
1957 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1958 }
1959
1960 /**
1961 * Posts the specified command to be executed on the main thread,
1962 * waits for the request to complete, and returns the result.
1963 * @see #sendRequestAsync
1964 */
1965 private Object sendRequest(
1966 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1968 throw new RuntimeException("This method will deadlock if called from the main thread.");
1969 }
1970
Nathan Harold92bed182018-10-12 18:16:49 -07001971 MainThreadRequest request = null;
1972 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1973 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1974 } else if (phone != null) {
1975 request = new MainThreadRequest(argument, phone, workSource);
1976 } else {
1977 request = new MainThreadRequest(argument, subId, workSource);
1978 }
1979
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 Message msg = mMainThreadHandler.obtainMessage(command, request);
1981 msg.sendToTarget();
1982
1983 // Wait for the request to complete
1984 synchronized (request) {
1985 while (request.result == null) {
1986 try {
1987 request.wait();
1988 } catch (InterruptedException e) {
1989 // Do nothing, go back and wait until the request is complete
1990 }
1991 }
1992 }
1993 return request.result;
1994 }
1995
1996 /**
1997 * Asynchronous ("fire and forget") version of sendRequest():
1998 * Posts the specified command to be executed on the main thread, and
1999 * returns immediately.
2000 * @see #sendRequest
2001 */
2002 private void sendRequestAsync(int command) {
2003 mMainThreadHandler.sendEmptyMessage(command);
2004 }
2005
2006 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002007 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002008 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002009 */
2010 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002011 sendRequestAsync(command, argument, null, null);
2012 }
2013
2014 /**
2015 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2016 * @see {@link #sendRequest(int,Object)}
2017 */
2018 private void sendRequestAsync(
2019 int command, Object argument, Phone phone, WorkSource workSource) {
2020 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002021 Message msg = mMainThreadHandler.obtainMessage(command, request);
2022 msg.sendToTarget();
2023 }
2024
2025 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 * Initialize the singleton PhoneInterfaceManager instance.
2027 * This is only done once, at startup, from PhoneApp.onCreate().
2028 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002029 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 synchronized (PhoneInterfaceManager.class) {
2031 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002032 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 } else {
2034 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2035 }
2036 return sInstance;
2037 }
2038 }
2039
2040 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002041 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002044 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002045 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2047 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002048 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002049 mTelephonySharedPreferences =
2050 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002051 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002052 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002053 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002054
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 publish();
2056 }
2057
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002058 private Phone getDefaultPhone() {
2059 Phone thePhone = getPhone(getDefaultSubscription());
2060 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2061 }
2062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 private void publish() {
2064 if (DBG) log("publish: " + this);
2065
Peter Wangc035ce42020-01-08 21:00:22 -08002066 TelephonyFrameworkInitializer
2067 .getTelephonyServiceManager()
2068 .getTelephonyServiceRegisterer()
2069 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 }
2071
Stuart Scott584921c2015-01-15 17:10:34 -08002072 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002073 if (request.phone != null) {
2074 return request.phone;
2075 } else {
2076 return getPhoneFromSubId(request.subId);
2077 }
2078 }
2079
2080 private Phone getPhoneFromSubId(int subId) {
2081 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2082 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002083 }
2084
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002085 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2086 Phone phone = getPhoneFromRequest(request);
2087 return phone == null ? null :
2088 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2089 }
2090
Wink Saville36469e72014-06-11 15:17:00 -07002091 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002092 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002093 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095
Naina Nallurid63128d2019-09-17 14:10:30 -07002096 private void sendEraseModemConfig(Phone phone) {
2097 if (phone != null) {
2098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2099 mApp, phone.getSubId(), "eraseModemConfig");
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2103 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
2106 }
2107 }
2108 }
2109
Peter Wang44b186e2020-01-13 23:33:09 -08002110 private boolean isImsAvailableOnDevice() {
2111 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2112 if (pm == null) {
2113 // For some reason package manger is not available.. This will fail internally anyway,
2114 // so do not throw error and allow.
2115 return true;
2116 }
2117 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2118 }
2119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002121 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002122 }
2123
Wink Savilleb564aae2014-10-23 10:18:09 -07002124 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 if (DBG) log("dial: " + number);
2126 // No permission check needed here: This is just a wrapper around the
2127 // ACTION_DIAL intent, which is available to any app since it puts up
2128 // the UI before it does anything.
2129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002130 final long identity = Binder.clearCallingIdentity();
2131 try {
2132 String url = createTelUrl(number);
2133 if (url == null) {
2134 return;
2135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 // PENDING: should we just silently fail if phone is offhook or ringing?
2138 PhoneConstants.State state = mCM.getState(subId);
2139 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2140 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2141 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2142 mApp.startActivity(intent);
2143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147 }
2148
2149 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002150 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002151 }
2152
Wink Savilleb564aae2014-10-23 10:18:09 -07002153 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 if (DBG) log("call: " + number);
2155
2156 // This is just a wrapper around the ACTION_CALL intent, but we still
2157 // need to do a permission check since we're calling startActivity()
2158 // from the context of the phone app.
2159 enforceCallPermission();
2160
Jordan Liu1617b712019-07-10 15:06:26 -07002161 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 != AppOpsManager.MODE_ALLOWED) {
2163 return;
2164 }
2165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166 final long identity = Binder.clearCallingIdentity();
2167 try {
2168 String url = createTelUrl(number);
2169 if (url == null) {
2170 return;
2171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173 boolean isValid = false;
2174 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2175 if (slist != null) {
2176 for (SubscriptionInfo subInfoRecord : slist) {
2177 if (subInfoRecord.getSubscriptionId() == subId) {
2178 isValid = true;
2179 break;
2180 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002181 }
Wink Saville08874612014-08-31 19:19:58 -07002182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183 if (!isValid) {
2184 return;
2185 }
Wink Saville08874612014-08-31 19:19:58 -07002186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2188 intent.putExtra(SUBSCRIPTION_KEY, subId);
2189 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2190 mApp.startActivity(intent);
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
2193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195
Wink Savilleb564aae2014-10-23 10:18:09 -07002196 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002197 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002198 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2199 }
2200
Wink Savilleb564aae2014-10-23 10:18:09 -07002201 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002202 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002203 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2204 }
2205
Wink Savilleb564aae2014-10-23 10:18:09 -07002206 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208
2209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2212 checkSimPin.start();
2213 return checkSimPin.unlockSim(null, pin);
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Wink Savilleb564aae2014-10-23 10:18:09 -07002219 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002221
2222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2225 checkSimPuk.start();
2226 return checkSimPuk.unlockSim(puk, pin);
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
2232 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002233 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 * a synchronous one.
2235 */
2236 private static class UnlockSim extends Thread {
2237
2238 private final IccCard mSimCard;
2239
2240 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002241 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2242 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243
2244 // For replies from SimCard interface
2245 private Handler mHandler;
2246
2247 // For async handler to identify request type
2248 private static final int SUPPLY_PIN_COMPLETE = 100;
2249
2250 public UnlockSim(IccCard simCard) {
2251 mSimCard = simCard;
2252 }
2253
2254 @Override
2255 public void run() {
2256 Looper.prepare();
2257 synchronized (UnlockSim.this) {
2258 mHandler = new Handler() {
2259 @Override
2260 public void handleMessage(Message msg) {
2261 AsyncResult ar = (AsyncResult) msg.obj;
2262 switch (msg.what) {
2263 case SUPPLY_PIN_COMPLETE:
2264 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2265 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002266 mRetryCount = msg.arg1;
2267 if (ar.exception != null) {
2268 if (ar.exception instanceof CommandException &&
2269 ((CommandException)(ar.exception)).getCommandError()
2270 == CommandException.Error.PASSWORD_INCORRECT) {
2271 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002272 } //When UiccCardApp dispose,handle message and return exception
2273 else if (ar.exception instanceof CommandException &&
2274 ((CommandException) (ar.exception)).getCommandError()
2275 == CommandException.Error.ABORTED) {
2276 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002277 } else {
2278 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2279 }
2280 } else {
2281 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 mDone = true;
2284 UnlockSim.this.notifyAll();
2285 }
2286 break;
2287 }
2288 }
2289 };
2290 UnlockSim.this.notifyAll();
2291 }
2292 Looper.loop();
2293 }
2294
2295 /*
2296 * Use PIN or PUK to unlock SIM card
2297 *
2298 * If PUK is null, unlock SIM card with PIN
2299 *
2300 * If PUK is not null, unlock SIM card with PUK and set PIN code
2301 */
Wink Saville9de0f752013-10-22 19:04:03 -07002302 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303
2304 while (mHandler == null) {
2305 try {
2306 wait();
2307 } catch (InterruptedException e) {
2308 Thread.currentThread().interrupt();
2309 }
2310 }
2311 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2312
2313 if (puk == null) {
2314 mSimCard.supplyPin(pin, callback);
2315 } else {
2316 mSimCard.supplyPuk(puk, pin, callback);
2317 }
2318
2319 while (!mDone) {
2320 try {
2321 Log.d(LOG_TAG, "wait for done");
2322 wait();
2323 } catch (InterruptedException e) {
2324 // Restore the interrupted status
2325 Thread.currentThread().interrupt();
2326 }
2327 }
2328 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002329 int[] resultArray = new int[2];
2330 resultArray[0] = mResult;
2331 resultArray[1] = mRetryCount;
2332 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334 }
2335
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002336 /**
2337 * This method has been removed due to privacy and stability concerns.
2338 */
2339 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002341 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2342 return;
Wink Saville36469e72014-06-11 15:17:00 -07002343 }
2344
Nathan Harold1f889d82020-06-04 17:05:26 -07002345 @Override
2346 public void updateServiceLocationWithPackageName(String callingPackage) {
2347 mApp.getSystemService(AppOpsManager.class)
2348 .checkPackage(Binder.getCallingUid(), callingPackage);
2349
Nathan Haroldf096d982020-11-18 17:18:06 -08002350 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002351 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2352 // Callers targeting S have no business invoking this method.
2353 return;
2354 }
2355
2356 LocationAccessPolicy.LocationPermissionResult locationResult =
2357 LocationAccessPolicy.checkLocationPermission(mApp,
2358 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2359 .setCallingPackage(callingPackage)
2360 .setCallingFeatureId(null)
2361 .setCallingPid(Binder.getCallingPid())
2362 .setCallingUid(Binder.getCallingUid())
2363 .setMethod("updateServiceLocation")
2364 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2365 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2366 .build());
2367 // Apps that lack location permission have no business calling this method;
2368 // however, because no permission was declared in the public API, denials must
2369 // all be "soft".
2370 switch (locationResult) {
2371 case DENIED_HARD: /* fall through */
2372 case DENIED_SOFT:
2373 return;
2374 }
2375
2376 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002379 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002381 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 }
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 }
2387
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002388 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 @Override
2390 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002391 return isRadioOnWithFeature(callingPackage, null);
2392 }
2393
2394
2395 @Override
2396 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2397 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2398 callingFeatureId);
2399 }
2400
2401 @Deprecated
2402 @Override
2403 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2404 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002405 }
2406
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002408 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2409 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002411 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 return false;
2413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002414
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 return isRadioOnForSubscriber(subId);
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
2420 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002421 }
2422
2423 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 final Phone phone = getPhone(subId);
2427 if (phone != null) {
2428 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2429 } else {
2430 return false;
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
2437 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002438 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
Wink Saville36469e72014-06-11 15:17:00 -07002440
Wink Savilleb564aae2014-10-23 10:18:09 -07002441 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 final Phone phone = getPhone(subId);
2447 if (phone != null) {
2448 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 }
Wink Saville36469e72014-06-11 15:17:00 -07002453 }
2454
2455 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002456 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002457 }
2458
Wink Savilleb564aae2014-10-23 10:18:09 -07002459 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461
2462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 final Phone phone = getPhone(subId);
2465 if (phone == null) {
2466 return false;
2467 }
2468 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2469 toggleRadioOnOffForSubscriber(subId);
2470 }
2471 return true;
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 }
Wink Saville36469e72014-06-11 15:17:00 -07002476
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002477 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002478 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002479 /*
2480 * If any of the Radios are available, it will need to be
2481 * shutdown. So return true if any Radio is available.
2482 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 final long identity = Binder.clearCallingIdentity();
2484 try {
2485 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2486 Phone phone = PhoneFactory.getPhone(i);
2487 if (phone != null && phone.isRadioAvailable()) return true;
2488 }
2489 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2490 return false;
2491 } finally {
2492 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002493 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002494 }
2495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002497 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 enforceModifyPermission();
2499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2503 logv("Shutting down Phone " + i);
2504 shutdownRadioUsingPhoneId(i);
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002508 }
2509 }
2510
2511 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002512 Phone phone = PhoneFactory.getPhone(phoneId);
2513 if (phone != null && phone.isRadioAvailable()) {
2514 phone.shutdownRadio();
2515 }
2516 }
2517
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520
2521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2524 if (defaultPhone != null) {
2525 defaultPhone.setRadioPower(turnOn);
2526 return true;
2527 } else {
2528 loge("There's no default phone.");
2529 return false;
2530 }
2531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002533 }
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
Wink Savilleb564aae2014-10-23 10:18:09 -07002536 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 if (phone != null) {
2543 phone.setRadioPower(turnOn);
2544 return true;
2545 } else {
2546 return false;
2547 }
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552
Wink Saville36469e72014-06-11 15:17:00 -07002553 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002554 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 public boolean enableDataConnectivity() {
2556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 int subId = mSubscriptionController.getDefaultDataSubId();
2561 final Phone phone = getPhone(subId);
2562 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002563 phone.getDataEnabledSettings().setDataEnabled(
2564 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 return true;
2566 } else {
2567 return false;
2568 }
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573
Wink Saville36469e72014-06-11 15:17:00 -07002574 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 public boolean disableDataConnectivity() {
2577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 int subId = mSubscriptionController.getDefaultDataSubId();
2582 final Phone phone = getPhone(subId);
2583 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002584 phone.getDataEnabledSettings().setDataEnabled(
2585 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586 return true;
2587 } else {
2588 return false;
2589 }
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
2594
Sanket Padawe356d7632015-06-22 14:03:32 -07002595 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002596 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(subId);
2600 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002601 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 } else {
2603 return false;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
2610 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002611 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
pkanwarae03a6b2016-11-06 20:37:09 -08002614 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 enforceCallPermission();
2616
2617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2620 return;
2621 }
2622 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2623 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
pkanwar32d516d2016-10-14 19:37:38 -07002627 };
2628
Wink Savilleb564aae2014-10-23 10:18:09 -07002629 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631
2632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2635 return false;
2636 }
2637 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 }
2642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002644 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002645 }
2646
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002647 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 Phone phone = PhoneFactory.getPhone(slotIndex);
2651 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2652 PhoneConstantConversions.convertCallState(phone.getState());
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002659 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002660 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2661 }
2662
2663 @Override
2664 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002667 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 if (phone != null) {
2669 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2670 } else {
2671 return PhoneConstantConversions.convertDataState(
2672 PhoneConstants.DataState.DISCONNECTED);
2673 }
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
2678
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002680 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002681 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2682 }
2683
2684 @Override
2685 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002688 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 if (phone != null) {
2690 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2691 } else {
2692 return TelephonyManager.DATA_ACTIVITY_NONE;
2693 }
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
2699 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002700 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002701 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002702 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002703
2704 LocationAccessPolicy.LocationPermissionResult locationResult =
2705 LocationAccessPolicy.checkLocationPermission(mApp,
2706 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2707 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002708 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002709 .setCallingPid(Binder.getCallingPid())
2710 .setCallingUid(Binder.getCallingUid())
2711 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002712 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002713 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2714 .build());
2715 switch (locationResult) {
2716 case DENIED_HARD:
2717 throw new SecurityException("Not allowed to access cell location");
2718 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002719 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2720 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 }
2722
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002727 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002728 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 } finally {
2730 Binder.restoreCallingIdentity(identity);
2731 }
Svetoslav64fad262015-04-14 14:35:21 -07002732 }
2733
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002735 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002736 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2737 // registered cell info, so return a NULL country instead.
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002740 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2741 // Get default phone in this case.
2742 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2743 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002744 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002746 if (phone == null) return "";
2747 ServiceStateTracker sst = phone.getServiceStateTracker();
2748 if (sst == null) return "";
2749 LocaleTracker lt = sst.getLocaleTracker();
2750 if (lt == null) return "";
2751 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2752 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2753 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002757 }
2758
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002759 /**
2760 * This method was removed due to potential issues caused by performing partial
2761 * updates of service state, and lack of a credible use case.
2762 *
2763 * This has the ability to break the telephony implementation by disabling notification of
2764 * changes in device connectivity. DO NOT USE THIS!
2765 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002766 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 public void enableLocationUpdates() {
2768 mApp.enforceCallingOrSelfPermission(
2769 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002772 /**
2773 * This method was removed due to potential issues caused by performing partial
2774 * updates of service state, and lack of a credible use case.
2775 *
2776 * This has the ability to break the telephony implementation by disabling notification of
2777 * changes in device connectivity. DO NOT USE THIS!
2778 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 @Override
2780 public void disableLocationUpdates() {
2781 mApp.enforceCallingOrSelfPermission(
2782 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
2785 @Override
2786 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002787 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2788 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002789 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002790 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2791 throw new SecurityException(
2792 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2793 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002794
Jordan Liu1617b712019-07-10 15:06:26 -07002795 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2797 return null;
2798 }
Svetoslav64fad262015-04-14 14:35:21 -07002799
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002800 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002802 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002803 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804
Nathan Haroldf180aac2018-06-01 18:43:55 -07002805 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2806 for (CellInfo ci : info) {
2807 if (ci instanceof CellInfoGsm) {
2808 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2809 } else if (ci instanceof CellInfoWcdma) {
2810 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002813 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002816 private List<CellInfo> getCachedCellInfo() {
2817 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2818 for (Phone phone : PhoneFactory.getPhones()) {
2819 List<CellInfo> info = phone.getAllCellInfo();
2820 if (info != null) cellInfos.addAll(info);
2821 }
2822 return cellInfos;
2823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824
2825 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002826 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002827 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002828 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002829
2830 LocationAccessPolicy.LocationPermissionResult locationResult =
2831 LocationAccessPolicy.checkLocationPermission(mApp,
2832 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2833 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002834 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002835 .setCallingPid(Binder.getCallingPid())
2836 .setCallingUid(Binder.getCallingUid())
2837 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002838 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002839 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2840 .build());
2841 switch (locationResult) {
2842 case DENIED_HARD:
2843 throw new SecurityException("Not allowed to access cell info");
2844 case DENIED_SOFT:
2845 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
Nathan Haroldf096d982020-11-18 17:18:06 -08002848 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002849 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2850 return getCachedCellInfo();
2851 }
2852
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002853 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002854 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2858 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002859 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002860 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861 if (info != null) cellInfos.addAll(info);
2862 }
2863 return cellInfos;
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
2867 }
2868
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002869 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002870 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2871 String callingFeatureId) {
2872 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2873 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002874 }
2875
2876 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002877 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2878 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002879 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002880 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002881 }
2882
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002883 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2884 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002886 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002887
2888 LocationAccessPolicy.LocationPermissionResult locationResult =
2889 LocationAccessPolicy.checkLocationPermission(mApp,
2890 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2891 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002892 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002893 .setCallingPid(Binder.getCallingPid())
2894 .setCallingUid(Binder.getCallingUid())
2895 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002896 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2897 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002898 .build());
2899 switch (locationResult) {
2900 case DENIED_HARD:
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 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002906 throw new SecurityException("Not allowed to access cell info");
2907 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002908 if (TelephonyPermissions
2909 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002910 // Safetynet logging for b/154934934
2911 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2912 }
Nathan Harold5320c422019-05-09 10:26:08 -07002913 try {
2914 cb.onCellInfo(new ArrayList<CellInfo>());
2915 } catch (RemoteException re) {
2916 // Drop without consequences
2917 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002918 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002919 }
2920
Nathan Harolda939a962019-05-09 10:13:47 -07002921
2922 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002923 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2924
2925 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2926 }
2927
2928 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002930 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002935 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 }
2940
Shishir Agrawala9f32182016-04-12 12:00:16 -07002941 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002942 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002943 Phone phone = PhoneFactory.getPhone(slotIndex);
2944 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002945 return null;
2946 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002947 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002948 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002949 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002950 return null;
2951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 return phone.getImei();
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002959 }
2960
2961 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002962 public String getTypeAllocationCodeForSlot(int slotIndex) {
2963 Phone phone = PhoneFactory.getPhone(slotIndex);
2964 String tac = null;
2965 if (phone != null) {
2966 String imei = phone.getImei();
2967 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2968 }
2969 return tac;
2970 }
2971
2972 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002973 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002974 Phone phone = PhoneFactory.getPhone(slotIndex);
2975 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002976 return null;
2977 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978
Jeff Davidson913390f2018-02-23 17:11:49 -08002979 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002980 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002981 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002982 return null;
2983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 return phone.getMeid();
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
Jack Yu2af8d712017-03-15 17:14:14 -07002991 }
2992
2993 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002994 public String getManufacturerCodeForSlot(int slotIndex) {
2995 Phone phone = PhoneFactory.getPhone(slotIndex);
2996 String manufacturerCode = null;
2997 if (phone != null) {
2998 String meid = phone.getMeid();
2999 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3000 }
3001 return manufacturerCode;
3002 }
3003
3004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003005 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3006 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003007 Phone phone = PhoneFactory.getPhone(slotIndex);
3008 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003009 return null;
3010 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003011 int subId = phone.getSubId();
3012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003013 mApp, subId, callingPackage, callingFeatureId,
3014 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003015 return null;
3016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 return phone.getDeviceSvn();
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003024 }
3025
fionaxu43304da2017-11-27 22:51:16 -08003026 @Override
3027 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 final Phone phone = getPhone(subId);
3031 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
fionaxu43304da2017-11-27 22:51:16 -08003035 }
3036
3037 @Override
3038 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 final Phone phone = getPhone(subId);
3042 return phone == null ? null : phone.getCarrierName();
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
fionaxu43304da2017-11-27 22:51:16 -08003046 }
3047
calvinpanffe225e2018-11-01 19:43:06 +08003048 @Override
chen xu0026ca62019-03-06 15:28:50 -08003049 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 final Phone phone = getPhone(subId);
3053 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003054 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
3058 }
3059
3060 @Override
chen xu0026ca62019-03-06 15:28:50 -08003061 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003065 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
chen xu651eec72018-11-11 19:03:44 -08003071 @Override
chen xu864e11c2018-12-06 22:10:03 -08003072 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3073 if (!isSubscriptionMccMnc) {
3074 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3075 }
chen xu651eec72018-11-11 19:03:44 -08003076 final Phone phone = PhoneFactory.getPhone(slotIndex);
3077 if (phone == null) {
3078 return TelephonyManager.UNKNOWN_CARRIER_ID;
3079 }
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
3086 }
3087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 //
3089 // Internal helper methods.
3090 //
3091
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003092 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3094 *
3095 * @throws SecurityException if the caller does not have the required permission
3096 */
3097 private void enforceModifyPermission() {
3098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3099 }
3100
Shuo Qiancd19c462020-01-16 20:51:11 -08003101 /**
3102 * Make sure the caller is system.
3103 *
3104 * @throws SecurityException if the caller is not system.
3105 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003106 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003107 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3108 throw new SecurityException("Caller must be system");
3109 }
3110 }
3111
Shuo Qian3b6ee772019-11-13 17:43:31 -08003112 private void enforceActiveEmergencySessionPermission() {
3113 mApp.enforceCallingOrSelfPermission(
3114 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3115 }
3116
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 /**
3118 * Make sure the caller has the CALL_PHONE permission.
3119 *
3120 * @throws SecurityException if the caller does not have the required permission
3121 */
3122 private void enforceCallPermission() {
3123 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3124 }
3125
paulhu5a773602019-08-23 19:17:33 +08003126 private void enforceSettingsPermission() {
3127 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003128 }
3129
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130 private String createTelUrl(String number) {
3131 if (TextUtils.isEmpty(number)) {
3132 return null;
3133 }
3134
Jake Hambye994d462014-02-03 13:10:13 -08003135 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 }
3137
Ihab Awadf9e92732013-12-05 18:02:52 -08003138 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3140 }
3141
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003142 private static void logv(String msg) {
3143 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3144 }
3145
Ihab Awadf9e92732013-12-05 18:02:52 -08003146 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3148 }
3149
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003150 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003152 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003153 }
3154
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003156 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 final Phone phone = PhoneFactory.getPhone(slotIndex);
3160 if (phone == null) {
3161 return PhoneConstants.PHONE_TYPE_NONE;
3162 } else {
3163 return phone.getPhoneType();
3164 }
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
3169
3170 /**
3171 * Returns the CDMA ERI icon index to display
3172 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003173 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003174 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3175 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3176 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003177 }
3178
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3181 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003183 mApp, subId, callingPackage, callingFeatureId,
3184 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003185 return -1;
3186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187
3188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final Phone phone = getPhone(subId);
3191 if (phone != null) {
3192 return phone.getCdmaEriIconIndex();
3193 } else {
3194 return -1;
3195 }
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 }
3200
3201 /**
3202 * Returns the CDMA ERI icon mode,
3203 * 0 - ON
3204 * 1 - FLASHING
3205 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003207 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3208 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3209 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003213 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3214 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003216 mApp, subId, callingPackage, callingFeatureId,
3217 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 return -1;
3219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone != null) {
3225 return phone.getCdmaEriIconMode();
3226 } else {
3227 return -1;
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 }
3233
3234 /**
3235 * Returns the CDMA ERI text,
3236 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003238 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3239 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3240 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003241 }
3242
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003244 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003247 mApp, subId, callingPackage, callingFeatureId,
3248 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003249 return null;
3250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 final Phone phone = getPhone(subId);
3255 if (phone != null) {
3256 return phone.getCdmaEriText();
3257 } else {
3258 return null;
3259 }
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
3265 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003266 * Returns the CDMA MDN.
3267 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003268 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003269 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3271 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 return phone.getLine1Number();
3278 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003279 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 return null;
3281 }
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003284 }
3285 }
3286
3287 /**
3288 * Returns the CDMA MIN.
3289 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003290 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003291 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3293 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 final Phone phone = getPhone(subId);
3298 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3299 return phone.getCdmaMin();
3300 } else {
3301 return null;
3302 }
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003305 }
3306 }
3307
Hall Liud892bec2018-11-30 14:51:45 -08003308 @Override
3309 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3310 INumberVerificationCallback callback, String callingPackage) {
3311 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3312 != PERMISSION_GRANTED) {
3313 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3314 }
3315 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3316
3317 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3318 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003319 throw new SecurityException("Calling package must be configured in the device config: "
3320 + "calling package: " + callingPackage
3321 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003322 }
3323
3324 if (range == null) {
3325 throw new NullPointerException("Range must be non-null");
3326 }
3327
3328 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003329 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003330
3331 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3332 }
3333
Junda Liuca05d5d2014-08-14 22:36:34 -07003334 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335 * Returns true if CDMA provisioning needs to run.
3336 */
3337 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003340 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 }
3345
3346 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003347 * Sets the voice mail number of a given subId.
3348 */
3349 @Override
3350 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003351 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3352 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3357 new Pair<String, String>(alphaTag, number), new Integer(subId));
3358 return success;
3359 } finally {
3360 Binder.restoreCallingIdentity(identity);
3361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003362 }
3363
Ta-wei Yen87c49842016-05-13 21:19:52 -07003364 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003365 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3366 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003367 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3368 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003369 if (!TextUtils.equals(callingPackage, systemDialer)) {
3370 throw new SecurityException("caller must be system dialer");
3371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3376 if (phoneAccountHandle == null) {
3377 return null;
3378 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003382 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003383 }
3384
3385 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003386 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3387 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003390 mApp, subId, callingPackage, callingFeatureId,
3391 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003392 return null;
3393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003395 final long identity = Binder.clearCallingIdentity();
3396 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003397 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003401 }
3402
3403 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003404 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3405 VisualVoicemailSmsFilterSettings settings) {
3406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003411 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003415 }
3416
3417 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003418 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3419 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003428 }
3429
3430 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003431 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3432 String callingPackage, int subId) {
3433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003442 }
3443
3444 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003445 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003451 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003455 }
3456
3457 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003458 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3459 String callingAttributionTag, int subId, String number, int port, String text,
3460 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003462 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003463 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003464 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003465 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3466 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003467 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003468
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003469 /**
fionaxu0152e512016-11-14 13:36:14 -08003470 * Sets the voice activation state of a given subId.
3471 */
3472 @Override
3473 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3475 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 final Phone phone = getPhone(subId);
3480 if (phone != null) {
3481 phone.setVoiceActivationState(activationState);
3482 } else {
3483 loge("setVoiceActivationState fails with invalid subId: " + subId);
3484 }
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003487 }
3488 }
3489
3490 /**
3491 * Sets the data activation state of a given subId.
3492 */
3493 @Override
3494 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3496 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 final Phone phone = getPhone(subId);
3501 if (phone != null) {
3502 phone.setDataActivationState(activationState);
3503 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003504 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505 }
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003508 }
3509 }
3510
3511 /**
3512 * Returns the voice activation state of a given subId.
3513 */
3514 @Override
3515 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517
fionaxu0152e512016-11-14 13:36:14 -08003518 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 if (phone != null) {
3522 return phone.getVoiceActivationState();
3523 } else {
3524 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3525 }
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003528 }
3529 }
3530
3531 /**
3532 * Returns the data activation state of a given subId.
3533 */
3534 @Override
3535 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537
fionaxu0152e512016-11-14 13:36:14 -08003538 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 if (phone != null) {
3542 return phone.getDataActivationState();
3543 } else {
3544 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003548 }
3549 }
3550
3551 /**
Wink Saville36469e72014-06-11 15:17:00 -07003552 * Returns the unread count of voicemails for a subId
3553 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003555 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3556 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 mApp, subId, callingPackage, callingFeatureId,
3559 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003560 return 0;
3561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 return phone.getVoiceMessageCount();
3567 } else {
3568 return 0;
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 }
3574
3575 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003576 * returns true, if the device is in a state where both voice and data
3577 * are supported simultaneously. This can change based on location or network condition.
3578 */
3579 @Override
3580 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
3584 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
3587 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003588 }
3589
3590 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003591 * Send the dialer code if called from the current default dialer or the caller has
3592 * carrier privilege.
3593 * @param inputCode The dialer code to send
3594 */
3595 @Override
3596 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003597 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003599 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3600 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003601 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003602 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003603 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003608 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
fionaxu235cc5e2017-03-06 22:25:57 -08003612 }
3613
Pengquan Menga1bb6272018-09-06 09:59:22 -07003614 @Override
3615 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003616 TelephonyPermissions
3617 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3618 mApp, subId, "getNetworkSelectionMode");
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 if (!isActiveSubscription(subId)) {
3622 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3623 }
3624 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003628 }
3629
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003631 public boolean isInEmergencySmsMode() {
3632 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 for (Phone phone : PhoneFactory.getPhones()) {
3636 if (phone.isInEmergencySmsMode()) {
3637 return true;
3638 }
3639 }
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 return false;
3644 }
3645
shilu366312e2019-12-17 09:28:10 -08003646 /**
3647 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3648 * @param subId The subscription to use to check the configuration.
3649 * @param c The callback that will be used to send the result.
3650 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003651 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003652 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3653 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003654 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3655 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003656
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003657 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3658 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3659 "IMS not available on device.");
3660 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 final long token = Binder.clearCallingIdentity();
3662 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003666 } catch (ImsException e) {
3667 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 } finally {
3669 Binder.restoreCallingIdentity(token);
3670 }
3671 }
3672
shilu366312e2019-12-17 09:28:10 -08003673 /**
3674 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3675 * @param subId The subscription to use to check the configuration.
3676 * @param c The callback that will be used to send the result.
3677 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003679 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003680 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3681 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3683 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3684 }
Meng Wangafbc5852019-09-19 17:37:13 -07003685 final long token = Binder.clearCallingIdentity();
3686 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003687 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003688 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3689 .removeRegistrationCallbackForSubscription(c, subId);
3690 } catch (ImsException e) {
3691 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3692 + "is inactive, ignoring unregister.");
3693 // If the subscription is no longer active, just return, since the callback
3694 // will already have been removed internally.
3695 } finally {
3696 Binder.restoreCallingIdentity(token);
3697 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 }
3699
Brad Ebingera34a6c22019-10-22 17:36:18 -07003700 /**
3701 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3702 */
3703 @Override
3704 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3705 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3706 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3707 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3708 "IMS not available on device.");
3709 }
3710 final long token = Binder.clearCallingIdentity();
3711 try {
3712 Phone phone = getPhone(subId);
3713 if (phone == null) {
3714 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3715 + subId + "'");
3716 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3717 }
3718 phone.getImsRegistrationState(regState -> {
3719 try {
3720 consumer.accept((regState == null)
3721 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3722 } catch (RemoteException e) {
3723 // Ignore if the remote process is no longer available to call back.
3724 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3725 }
3726 });
3727 } finally {
3728 Binder.restoreCallingIdentity(token);
3729 }
3730 }
3731
3732 /**
3733 * Get the transport type for the IMS service registration state.
3734 */
3735 @Override
3736 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003737 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3738 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003739 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3741 "IMS not available on device.");
3742 }
3743 final long token = Binder.clearCallingIdentity();
3744 try {
3745 Phone phone = getPhone(subId);
3746 if (phone == null) {
3747 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3748 + subId + "'");
3749 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3750 }
3751 phone.getImsRegistrationTech(regTech -> {
3752 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3753 int regTechConverted = (regTech == null)
3754 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3755 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3756 regTechConverted);
3757 try {
3758 consumer.accept(regTechConverted);
3759 } catch (RemoteException e) {
3760 // Ignore if the remote process is no longer available to call back.
3761 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3762 }
3763 });
3764 } finally {
3765 Binder.restoreCallingIdentity(token);
3766 }
3767 }
3768
shilu366312e2019-12-17 09:28:10 -08003769 /**
3770 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3771 * @param subId The subscription to use to check the configuration.
3772 * @param c The callback that will be used to send the result.
3773 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003775 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3776 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003777 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3778 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003779 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3780 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3781 "IMS not available on device.");
3782 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3784 final long token = Binder.clearCallingIdentity();
3785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003786 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003788 } catch (ImsException e) {
3789 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 } finally {
3791 Binder.restoreCallingIdentity(token);
3792 }
3793 }
3794
shilu366312e2019-12-17 09:28:10 -08003795 /**
3796 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3797 * @param subId The subscription to use to check the configuration.
3798 * @param c The callback that will be used to send the result.
3799 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003800 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003801 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003802 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3803 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3805 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3806 }
Meng Wangafbc5852019-09-19 17:37:13 -07003807
3808 final long token = Binder.clearCallingIdentity();
3809 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003810 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003811 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003812 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003813 } catch (ImsException e) {
3814 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3815 + "is inactive, ignoring unregister.");
3816 // If the subscription is no longer active, just return, since the callback
3817 // will already have been removed internally.
3818 } finally {
3819 Binder.restoreCallingIdentity(token);
3820 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 }
3822
3823 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003824 public boolean isCapable(int subId, int capability, int regTech) {
3825 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3827 final long token = Binder.clearCallingIdentity();
3828 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003831 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3833 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003834 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003835 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3836 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003837 } finally {
3838 Binder.restoreCallingIdentity(token);
3839 }
3840 }
3841
3842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003843 public boolean isAvailable(int subId, int capability, int regTech) {
3844 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 final long token = Binder.clearCallingIdentity();
3846 try {
3847 Phone phone = getPhone(subId);
3848 if (phone == null) return false;
3849 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003850 } catch (com.android.ims.ImsException e) {
3851 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3852 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 } finally {
3854 Binder.restoreCallingIdentity(token);
3855 }
3856 }
3857
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003858 /**
3859 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3860 * subscription.
3861 * @param subId The subscription to use to check the configuration.
3862 * @param callback The callback that will be used to send the result.
3863 * @param capability The MmTelFeature capability that will be used to send the result.
3864 * @param transportType The transport type of the MmTelFeature capability.
3865 */
3866 @Override
3867 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3868 int transportType) {
3869 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3870 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3871 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3872 "IMS not available on device.");
3873 }
3874 final long token = Binder.clearCallingIdentity();
3875 try {
3876 int slotId = getSlotIndex(subId);
3877 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3878 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3879 + subId + "'");
3880 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3881 }
3882 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3883 transportType, aBoolean -> {
3884 try {
3885 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3886 } catch (RemoteException e) {
3887 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3888 + "running. Ignore");
3889 }
3890 });
3891 } finally {
3892 Binder.restoreCallingIdentity(token);
3893 }
3894 }
3895
shilu366312e2019-12-17 09:28:10 -08003896 /**
3897 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3898 * @param subId The subscription to use to check the configuration.
3899 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 @Override
3901 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003902 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3903 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003904
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3906 final long token = Binder.clearCallingIdentity();
3907 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003910 } catch (ImsException e) {
3911 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 } finally {
3913 Binder.restoreCallingIdentity(token);
3914 }
3915 }
3916
3917 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003918 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003920 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (ImsException e) {
3927 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
3931 }
3932
shilu366312e2019-12-17 09:28:10 -08003933 /**
3934 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3935 * @param subId The subscription to use to check the configuration.
3936 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003938 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003939 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3940 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003944 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3945 } catch (ImsException e) {
3946 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
3950 }
3951
3952 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003953 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003955 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003959 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003960 } catch (ImsException e) {
3961 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
3965 }
3966
shilu366312e2019-12-17 09:28:10 -08003967 /**
3968 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3969 * @param subId The subscription to use to check the configuration.
3970 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 @Override
3972 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003973 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3974 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
3981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
3985 }
3986
3987 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003988 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003990 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 final long identity = Binder.clearCallingIdentity();
3992 try {
3993 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003994 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003995 } catch (ImsException e) {
3996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
4000 }
4001
shilu366312e2019-12-17 09:28:10 -08004002 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004003 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4004 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4005 * @param subId The subscription to use to check the configuration.
4006 */
4007 @Override
4008 public boolean isCrossSimCallingEnabledByUser(int subId) {
4009 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4010 mApp, subId, "isCrossSimCallingEnabledByUser");
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4014 return ImsManager.getInstance(mApp,
4015 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4016 } catch (ImsException e) {
4017 throw new ServiceSpecificException(e.getCode());
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
4021 }
4022
4023 /**
4024 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4025 * Requires MODIFY_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4028 * false otherwise
4029 */
4030 @Override
4031 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4033 "setCrossSimCallingEnabled");
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4037 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4038 .setCrossSimCallingEnabled(isEnabled);
4039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
4041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
4044 }
4045
4046 /**
shilu366312e2019-12-17 09:28:10 -08004047 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4048 * @param subId The subscription to use to check the configuration.
4049 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 @Override
4051 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4053 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004059 } catch (ImsException e) {
4060 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
4064 }
4065
4066 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004067 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004069 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
4080 }
4081
4082 @Override
4083 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4085 "setVoWiFiNonPersistent");
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004090 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
4096 }
4097
shilu366312e2019-12-17 09:28:10 -08004098 /**
4099 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4100 * @param subId The subscription to use to check the configuration.
4101 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 @Override
4103 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004104 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4105 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004109 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004111 } catch (ImsException e) {
4112 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
4116 }
4117
4118 @Override
4119 public void setVoWiFiModeSetting(int subId, int mode) {
4120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4121 "setVoWiFiModeSetting");
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004125 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004127 } catch (ImsException e) {
4128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
4132 }
4133
4134 @Override
4135 public int getVoWiFiRoamingModeSetting(int subId) {
4136 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
4150 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4152 "setVoWiFiRoamingModeSetting");
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
4165 @Override
4166 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4168 "setRttCapabilityEnabled");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4173 } catch (ImsException e) {
4174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
4178 }
4179
shilu366312e2019-12-17 09:28:10 -08004180 /**
4181 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4182 * @param subId The subscription to use to check the configuration.
4183 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 @Override
4185 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004186 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4187 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004193 } catch (ImsException e) {
4194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
4198 }
4199
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004200 @Override
4201 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4202 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4203 final long identity = Binder.clearCallingIdentity();
4204 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004205 if (!isImsAvailableOnDevice()) {
4206 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4207 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004208 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004210 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004211 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 } catch (ImsException e) {
4213 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
4217 }
4218
4219 @Override
4220 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4221 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4222 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4224 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4225 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004226 try {
4227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004228 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004229 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004230 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004231 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4232 + "is inactive, ignoring unregister.");
4233 // If the subscription is no longer active, just return, since the callback will already
4234 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
4238 }
4239
allenwtsu99c623b2020-01-03 18:24:23 +08004240
4241 private void checkModifyPhoneStatePermission(int subId, String message) {
4242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4243 message);
4244 }
4245
4246 private boolean isImsProvisioningRequired(int subId, int capability,
4247 boolean isMmtelCapability) {
4248 Phone phone = getPhone(subId);
4249 if (phone == null) {
4250 loge("phone instance null for subid " + subId);
4251 return false;
4252 }
4253 if (isMmtelCapability) {
4254 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4255 return false;
4256 }
4257 } else {
4258 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4259 return false;
4260 }
4261 }
4262 return true;
4263 }
4264
4265 @Override
4266 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4267 boolean isProvisioned) {
4268 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4269
4270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4273 if (!isImsProvisioningRequired(subId, capability, false)) {
4274 return;
4275 }
4276
4277 // this capability requires provisioning, route to the correct API.
4278 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4279 switch (capability) {
4280 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4281 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4282 ims.setEabProvisioned(isProvisioned);
4283 break;
4284 default: {
4285 throw new IllegalArgumentException("Tried to set provisioning for "
4286 + "rcs capability '" + capability + "', which does not require "
4287 + "provisioning.");
4288 }
4289 }
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
4293
4294 }
4295
4296
4297 @Override
4298 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4299 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4303 if (!isImsProvisioningRequired(subId, capability, false)) {
4304 return true;
4305 }
4306
4307 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4308 switch (capability) {
4309 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4310 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4311 return ims.isEabProvisionedOnDevice();
4312
4313 default: {
4314 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4315 + "capability '" + capability + "', which does not require "
4316 + "provisioning.");
4317 }
4318 }
4319
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004325 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004326 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4327 boolean isProvisioned) {
4328 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4329 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4330 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4331 }
allenwtsu99c623b2020-01-03 18:24:23 +08004332 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004333 final long identity = Binder.clearCallingIdentity();
4334 try {
4335 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004336 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004337 return;
4338 }
4339
4340 // this capability requires provisioning, route to the correct API.
4341 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4342 switch (capability) {
4343 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4344 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4345 ims.setVolteProvisioned(isProvisioned);
4346 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4347 ims.setWfcProvisioned(isProvisioned);
4348 }
4349 break;
4350 }
4351 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4352 // There is currently no difference in VT provisioning type.
4353 ims.setVtProvisioned(isProvisioned);
4354 break;
4355 }
4356 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4357 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4358 // change the capability of the feature instead if needed.
4359 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4360 == isProvisioned) {
4361 // No change in provisioning.
4362 return;
4363 }
4364 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4365 try {
4366 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004368 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4369 + ", Exception" + e.getMessage());
4370 }
4371 break;
4372 }
4373 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004374 throw new IllegalArgumentException("Tried to set provisioning for "
4375 + "MmTel capability '" + capability + "', which does not require "
4376 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004377 }
4378 }
4379
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
4383 }
4384
4385 @Override
4386 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4387 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4388 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4389 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4390 }
4391 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004395 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004396 return true;
4397 }
4398
4399 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4400 switch (capability) {
4401 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4402 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4403 return ims.isVolteProvisionedOnDevice();
4404 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4405 return ims.isWfcProvisionedOnDevice();
4406 }
4407 // This should never happen, since we are checking tech above to make sure it
4408 // is either LTE or IWLAN.
4409 throw new IllegalArgumentException("Invalid radio technology for voice "
4410 + "capability.");
4411 }
4412 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4413 // There is currently no difference in VT provisioning type.
4414 return ims.isVtProvisionedOnDevice();
4415 }
4416 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4417 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4418 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4419 }
4420 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004421 throw new IllegalArgumentException(
4422 "Tried to get provisioning for MmTel capability '" + capability
4423 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004424 }
4425 }
4426
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
4432 @Override
4433 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4434 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4435 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4436 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4437 }
4438 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4439 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4440 return (provisionedBits & capability) > 0;
4441 }
4442
4443 @Override
4444 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4445 boolean isProvisioned) {
4446 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4447 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4448 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4449 }
4450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4451 "setProvisioningStatusForCapability");
4452 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4453 // If the current provisioning status for capability already matches isProvisioned,
4454 // do nothing.
4455 if (((provisionedBits & capability) > 0) == isProvisioned) {
4456 return;
4457 }
4458 if (isProvisioned) {
4459 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4460 } else {
4461 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4462 }
4463 }
4464
4465 /**
4466 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4467 * technology. The bitfield should mirror the bitfield defined by
4468 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4469 */
4470 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4471 String key = getMmTelProvisioningKey(subId, tech);
4472 // Default is no capabilities are provisioned.
4473 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4474 }
4475
4476 /**
4477 * Sets the MmTel capability provisioning bitfield (defined by
4478 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4479 * technology specified.
4480 *
4481 * Note: This is a synchronous command and should not be called on UI thread.
4482 */
4483 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4484 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4485 String key = getMmTelProvisioningKey(subId, tech);
4486 editor.putInt(key, newField);
4487 editor.commit();
4488 }
4489
4490 private static String getMmTelProvisioningKey(int subId, int tech) {
4491 // resulting key is provision_ims_mmtel_{subId}_{tech}
4492 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4493 }
4494
4495 /**
4496 * Query CarrierConfig to see if the specified capability requires provisioning for the
4497 * carrier associated with the subscription id.
4498 */
4499 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4500 int capability) {
4501 CarrierConfigManager configManager = new CarrierConfigManager(context);
4502 PersistableBundle c = configManager.getConfigForSubId(subId);
4503 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004504 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004505 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4506 false);
4507 boolean requireVoiceVtProvisioning = c.getBoolean(
4508 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4509
4510 // First check to make sure that the capability requires provisioning.
4511 switch (capability) {
4512 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4513 // intentional fallthrough
4514 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4515 if (requireVoiceVtProvisioning) {
4516 // Voice and Video requires provisioning
4517 return true;
4518 }
4519 break;
4520 }
4521 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4522 if (requireUtProvisioning) {
4523 // UT requires provisioning
4524 return true;
4525 }
4526 break;
4527 }
4528 }
4529 return false;
4530 }
4531
allenwtsu99c623b2020-01-03 18:24:23 +08004532 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4533 int capability) {
4534 CarrierConfigManager configManager = new CarrierConfigManager(context);
4535 PersistableBundle c = configManager.getConfigForSubId(subId);
4536
4537 boolean requireRcsProvisioning = c.getBoolean(
4538 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4539
4540 // First check to make sure that the capability requires provisioning.
4541 switch (capability) {
4542 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4543 // intentional fallthrough
4544 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4545 if (requireRcsProvisioning) {
4546 // OPTION or PRESENCE requires provisioning
4547 return true;
4548 }
4549 break;
4550 }
4551 }
4552 return false;
4553 }
4554
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004555 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004556 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004557 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4558 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4559 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004560 enforceReadPrivilegedPermission("getImsProvisioningInt");
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004564 int slotId = getSlotIndex(subId);
4565 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4566 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4567 + subId + "' for key:" + key);
4568 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4569 }
4570 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004571 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4573 + subId + "' for key:" + key);
4574 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
4578 }
4579
4580 @Override
4581 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004582 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4583 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4584 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004585 enforceReadPrivilegedPermission("getImsProvisioningString");
4586 final long identity = Binder.clearCallingIdentity();
4587 try {
4588 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004589 int slotId = getSlotIndex(subId);
4590 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4591 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4592 + subId + "' for key:" + key);
4593 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4594 }
4595 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4598 + subId + "' for key:" + key);
4599 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
4603 }
4604
4605 @Override
4606 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4608 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4609 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4611 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 final long identity = Binder.clearCallingIdentity();
4613 try {
4614 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004615 int slotId = getSlotIndex(subId);
4616 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4617 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4618 + subId + "' for key:" + key);
4619 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4620 }
4621 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004622 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4624 + "' for key:" + key);
4625 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
4629 }
4630
4631 @Override
4632 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4634 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4635 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4637 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004638 final long identity = Binder.clearCallingIdentity();
4639 try {
4640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 int slotId = getSlotIndex(subId);
4642 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4643 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4644 + subId + "' for key:" + key);
4645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4646 }
4647 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004648 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4650 + "' for key:" + key);
4651 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
4655 }
4656
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 int slotId = SubscriptionManager.getSlotIndex(subId);
4659 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004660 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4661 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004662 }
4663 return slotId;
4664 }
4665
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004666 private int getSlotIndex(int subId) {
4667 int slotId = SubscriptionManager.getSlotIndex(subId);
4668 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4669 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4670 }
4671 return slotId;
4672 }
4673
Wink Saville36469e72014-06-11 15:17:00 -07004674 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004675 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004676 */
4677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004678 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4679 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004680 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004681 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004682 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004683 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004684 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004685 mApp, subId, callingPackage, callingFeatureId,
4686 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004687 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4688 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 final Phone phone = getPhone(subId);
4693 if (phone != null) {
4694 return phone.getServiceState().getDataNetworkType();
4695 } else {
4696 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4697 }
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004701 }
4702
4703 /**
4704 * Returns the data network type
4705 */
4706 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004707 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4708 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4709 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004710 }
4711
4712 /**
4713 * Returns the data network type for a subId
4714 */
4715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004716 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4717 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004719 mApp, subId, callingPackage, callingFeatureId,
4720 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004721 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4722 }
4723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 final Phone phone = getPhone(subId);
4727 if (phone != null) {
4728 return phone.getServiceState().getDataNetworkType();
4729 } else {
4730 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4731 }
4732 } finally {
4733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004735 }
4736
4737 /**
Wink Saville36469e72014-06-11 15:17:00 -07004738 * Returns the Voice network type for a subId
4739 */
4740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004741 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4742 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004744 mApp, subId, callingPackage, callingFeatureId,
4745 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004746 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4747 }
4748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 final Phone phone = getPhone(subId);
4752 if (phone != null) {
4753 return phone.getServiceState().getVoiceNetworkType();
4754 } else {
4755 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4756 }
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004760 }
4761
4762 /**
4763 * @return true if a ICC card is present
4764 */
4765 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004766 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004767 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4768 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004769 }
4770
4771 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004772 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004773 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004774 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004775 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 final Phone phone = PhoneFactory.getPhone(slotIndex);
4779 if (phone != null) {
4780 return phone.getIccCard().hasIccCard();
4781 } else {
4782 return false;
4783 }
4784 } finally {
4785 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004787 }
4788
4789 /**
4790 * Return if the current radio is LTE on CDMA. This
4791 * is a tri-state return value as for a period of time
4792 * the mode may be unknown.
4793 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004794 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004795 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004796 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004797 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004799 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4800 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4801 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004802 }
4803
Sanket Padawe356d7632015-06-22 14:03:32 -07004804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004805 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4806 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004807 try {
4808 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4809 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004810 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4811 }
4812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 final Phone phone = getPhone(subId);
4816 if (phone == null) {
4817 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4818 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004819 return TelephonyProperties.lte_on_cdma_device()
4820 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 }
4822 } finally {
4823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004824 }
Wink Saville36469e72014-06-11 15:17:00 -07004825 }
4826
Wink Saville36469e72014-06-11 15:17:00 -07004827 /**
4828 * {@hide}
4829 * Returns Default subId, 0 in the case of single standby.
4830 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004831 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004832 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004833 }
4834
Shishir Agrawala9f32182016-04-12 12:00:16 -07004835 private int getSlotForDefaultSubscription() {
4836 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4837 }
4838
Wink Savilleb564aae2014-10-23 10:18:09 -07004839 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004840 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004841 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004842
Pengquan Menge92a50d2018-09-21 15:54:48 -07004843 private boolean isActiveSubscription(int subId) {
4844 return mSubscriptionController.isActiveSubId(subId);
4845 }
4846
Ihab Awadf2177b72013-11-25 13:33:23 -08004847 /**
4848 * @see android.telephony.TelephonyManager.WifiCallingChoices
4849 */
4850 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004853 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4855 getWhenToMakeWifiCallsDefaultPreference());
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004859 }
4860
4861 /**
4862 * @see android.telephony.TelephonyManager.WifiCallingChoices
4863 */
4864 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004868 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4870 } finally {
4871 Binder.restoreCallingIdentity(identity);
4872 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004873 }
4874
Sailesh Nepald1e68152013-12-12 19:08:02 -08004875 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004876 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004877 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004878 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004879
Jordan Liu4c733742019-02-28 12:03:40 -08004880 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4881 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4882 if (phoneId == -1) {
4883 throw new IllegalArgumentException("Given slot index: " + slotIndex
4884 + " does not correspond to an active phone");
4885 }
4886 return PhoneFactory.getPhone(phoneId);
4887 }
4888
Shishir Agrawal566b7612013-10-28 14:41:00 -07004889 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004890 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4891 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4893 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004895 if (DBG) {
4896 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4897 }
4898 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4899 p2);
4900 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004901
Jordan Liu4c733742019-02-28 12:03:40 -08004902
4903 @Override
4904 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4905 int slotIndex, String callingPackage, String aid, int p2) {
4906 enforceModifyPermission();
4907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4908 if (DBG) {
4909 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4910 }
4911 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4912 callingPackage, aid, p2);
4913 }
4914
4915 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4916 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 if (TextUtils.equals(ISDR_AID, aid)) {
4920 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004921 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4922 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 if (bestComponent == null
4924 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4925 loge("The calling package is not allowed to access ISD-R.");
4926 throw new SecurityException(
4927 "The calling package is not allowed to access ISD-R.");
4928 }
Derek Tan740e1672017-06-27 14:56:27 -07004929 }
Derek Tan740e1672017-06-27 14:56:27 -07004930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004932 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4933 null /* workSource */);
4934 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 return response;
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004939 }
4940
4941 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004942 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4944 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004945 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4946 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4947 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004948
Jordan Liu4c733742019-02-28 12:03:40 -08004949 @Override
4950 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4951 enforceModifyPermission();
4952 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4953 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4954 channel);
4955 }
4956
4957 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 if (channel < 0) {
4961 return false;
4962 }
Jordan Liu4c733742019-02-28 12:03:40 -08004963 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4964 null /* workSource */);
4965 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 return success;
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004969 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004970 }
4971
4972 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004973 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004974 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004977 if (DBG) {
4978 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4979 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4980 + p3 + " data=" + data);
4981 }
4982 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4983 command, p1, p2, p3, data);
4984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985
Jordan Liu4c733742019-02-28 12:03:40 -08004986 @Override
4987 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4988 int command, int p1, int p2, int p3, String data) {
4989 enforceModifyPermission();
4990 if (DBG) {
4991 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4992 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4993 + p3 + " data=" + data);
4994 }
4995 return iccTransmitApduLogicalChannelWithPermission(
4996 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4997 data);
4998 }
4999
5000 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5001 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
5003 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005004 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 return "";
5006 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005009 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5010 null /* workSource */);
5011 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 // Append the returned status code to the end of the response payload.
5014 String s = Integer.toHexString(
5015 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5016 if (response.payload != null) {
5017 s = IccUtils.bytesToHexString(response.payload) + s;
5018 }
5019 return s;
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005023 }
Jake Hambye994d462014-02-03 13:10:13 -08005024
Evan Charltonc66da362014-05-16 14:06:40 -07005025 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005026 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5027 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5029 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005031 if (DBG) {
5032 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5033 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5034 }
5035 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5036 cla, command, p1, p2, p3, data);
5037 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005038
Jordan Liu4c733742019-02-28 12:03:40 -08005039 @Override
5040 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5041 int command, int p1, int p2, int p3, String data) {
5042 enforceModifyPermission();
5043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5044 if (DBG) {
5045 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5046 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5047 + " data=" + data);
5048 }
5049
5050 return iccTransmitApduBasicChannelWithPermission(
5051 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5052 p2, p3, data);
5053 }
5054
5055 // open APDU basic channel assuming the caller has sufficient permissions
5056 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5057 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5061 && TextUtils.equals(ISDR_AID, data)) {
5062 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005063 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5064 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 if (bestComponent == null
5066 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5067 loge("The calling package is not allowed to select ISD-R.");
5068 throw new SecurityException(
5069 "The calling package is not allowed to select ISD-R.");
5070 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005071 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005074 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5075 null /* workSource */);
5076 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 // Append the returned status code to the end of the response payload.
5079 String s = Integer.toHexString(
5080 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5081 if (response.payload != null) {
5082 s = IccUtils.bytesToHexString(response.payload) + s;
5083 }
5084 return s;
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005087 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005088 }
5089
5090 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005091 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005092 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5094 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 if (DBG) {
5099 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5100 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5101 }
5102
5103 IccIoResult response =
5104 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5105 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5106 subId);
5107
5108 if (DBG) {
5109 log("Exchange SIM_IO [R]" + response);
5110 }
5111
5112 byte[] result = null;
5113 int length = 2;
5114 if (response.payload != null) {
5115 length = 2 + response.payload.length;
5116 result = new byte[length];
5117 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5118 } else {
5119 result = new byte[length];
5120 }
5121
5122 result[length - 1] = (byte) response.sw2;
5123 result[length - 2] = (byte) response.sw1;
5124 return result;
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005127 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005128 }
5129
Nathan Haroldb3014052017-01-25 15:57:32 -08005130 /**
5131 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5132 * on a particular subscription
5133 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005134 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5135 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005137 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005138 return null;
5139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140
5141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 if (appType != TelephonyManager.APPTYPE_USIM
5144 && appType != TelephonyManager.APPTYPE_SIM) {
5145 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5146 return null;
5147 }
5148 Object response = sendRequest(
5149 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5150 if (response instanceof String[]) {
5151 return (String[]) response;
5152 }
yincheng zhao2737e882019-09-06 17:06:54 -07005153 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005155 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005158 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005159 }
5160
yincheng zhao2737e882019-09-06 17:06:54 -07005161 /**
5162 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5163 * subscription.
5164 *
5165 * @param subId the id of the subscription.
5166 * @param appType the uicc app type, must be USIM or SIM.
5167 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5168 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005169 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005170 * @return number of fplmns that is successfully written to the SIM.
5171 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005172 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5173 String callingFeatureId) {
5174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5175 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005176 if (DBG) logv("no permissions for setForbiddenplmns");
5177 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5178 }
5179 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5180 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5181 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5182 }
5183 if (fplmns == null) {
5184 throw new IllegalArgumentException("Fplmn List provided is null");
5185 }
5186 for (String fplmn : fplmns) {
5187 if (!CellIdentity.isValidPlmn(fplmn)) {
5188 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5189 }
5190 }
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 Object response = sendRequest(
5194 CMD_SET_FORBIDDEN_PLMNS,
5195 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5196 subId);
5197 return (int) response;
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
5201 }
5202
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005203 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005204 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5206 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 final long identity = Binder.clearCallingIdentity();
5209 try {
5210 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5211 if (response.payload == null) {
5212 return "";
5213 }
Evan Charltonc66da362014-05-16 14:06:40 -07005214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 // Append the returned status code to the end of the response payload.
5216 String s = Integer.toHexString(
5217 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5218 s = IccUtils.bytesToHexString(response.payload) + s;
5219 return s;
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
Evan Charltonc66da362014-05-16 14:06:40 -07005223 }
5224
Jake Hambye994d462014-02-03 13:10:13 -08005225 /**
5226 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5227 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5228 *
5229 * @param itemID the ID of the item to read
5230 * @return the NV item as a String, or null on error.
5231 */
5232 @Override
5233 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5236 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237
5238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005241 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5243 return value;
5244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Jake Hambye994d462014-02-03 13:10:13 -08005247 }
5248
5249 /**
5250 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5251 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5252 *
5253 * @param itemID the ID of the item to read
5254 * @param itemValue the value to write, as a String
5255 * @return true on success; false on any failure
5256 */
5257 @Override
5258 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005259 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5261 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262
5263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5266 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005267 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5269 return success;
5270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Jake Hambye994d462014-02-03 13:10:13 -08005273 }
5274
5275 /**
5276 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5277 * Used for device configuration by some CDMA operators.
5278 *
5279 * @param preferredRoamingList byte array containing the new PRL
5280 * @return true on success; false on any failure
5281 */
5282 @Override
5283 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5285 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286
5287 final long identity = Binder.clearCallingIdentity();
5288 try {
5289 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5290 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5291 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5292 return success;
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Jake Hambye994d462014-02-03 13:10:13 -08005296 }
5297
5298 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005299 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005300 * Used for device configuration by some CDMA operators.
5301 *
chen xu6dac5ab2018-10-26 17:39:23 -07005302 * @param slotIndex - device slot.
5303 *
Jake Hambye994d462014-02-03 13:10:13 -08005304 * @return true on success; false on any failure
5305 */
5306 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005307 public boolean resetModemConfig(int slotIndex) {
5308 Phone phone = PhoneFactory.getPhone(slotIndex);
5309 if (phone != null) {
5310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312
chen xu6dac5ab2018-10-26 17:39:23 -07005313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5316 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5317 return success;
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 }
chen xu6dac5ab2018-10-26 17:39:23 -07005322 return false;
5323 }
5324
5325 /**
5326 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5327 *
5328 * @param slotIndex - device slot.
5329 *
5330 * @return true on success; false on any failure
5331 */
5332 @Override
5333 public boolean rebootModem(int slotIndex) {
5334 Phone phone = PhoneFactory.getPhone(slotIndex);
5335 if (phone != null) {
5336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5337 mApp, phone.getSubId(), "rebootModem");
5338
5339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5342 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5343 return success;
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
5346 }
5347 }
5348 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005349 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005350
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005351 public String[] getPcscfAddress(String apnType, String callingPackage,
5352 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005353 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5355 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005356 return new String[0];
5357 }
5358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005361 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
Wink Saville36469e72014-06-11 15:17:00 -07005365 }
5366
Brad Ebinger51f743a2017-01-23 13:50:20 -08005367 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005368 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5369 * {@link #disableIms(int)}.
5370 * @param slotIndex device slot.
5371 */
5372 public void resetIms(int slotIndex) {
5373 enforceModifyPermission();
5374
5375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 if (mImsResolver == null) {
5378 // may happen if the does not support IMS.
5379 return;
5380 }
5381 mImsResolver.disableIms(slotIndex);
5382 mImsResolver.enableIms(slotIndex);
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
5386 }
5387
5388 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005389 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5390 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005391 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005392 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005393 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394
5395 final long identity = Binder.clearCallingIdentity();
5396 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005397 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005398 // may happen if the device does not support IMS.
5399 return;
5400 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005401 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 } finally {
5403 Binder.restoreCallingIdentity(identity);
5404 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005405 }
5406
5407 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005408 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5409 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005410 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005411 public void disableIms(int slotId) {
5412 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005416 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005417 // may happen if the device does not support IMS.
5418 return;
5419 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005420 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 } finally {
5422 Binder.restoreCallingIdentity(identity);
5423 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005424 }
5425
5426 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005427 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5428 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005429 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005430 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005431 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433
5434 final long identity = Binder.clearCallingIdentity();
5435 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005436 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005437 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5438 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005439 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005440 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005444 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005445 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005446 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5447 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005448 @Override
5449 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005450 enforceModifyPermission();
5451
5452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005455 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
5459 }
5460
5461 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005462 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005463 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005464 */
5465 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005470 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005471 // may happen if the device does not support IMS.
5472 return null;
5473 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005474 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 } finally {
5476 Binder.restoreCallingIdentity(identity);
5477 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005478 }
5479
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005480 /**
5481 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005482 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005483 */
5484 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5485 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486
5487 final long identity = Binder.clearCallingIdentity();
5488 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005489 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005490 // may happen if the device does not support IMS.
5491 return null;
5492 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005493 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005497 }
5498
Brad Ebinger884c07b2018-02-15 16:17:40 -08005499 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005500 * Sets the ImsService Package Name that Telephony will bind to.
5501 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005502 * @param slotIndex the slot ID that the ImsService should bind for.
5503 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005504 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005505 * @param featureTypes An integer array of feature types associated with a packageName.
5506 * @param packageName The name of the package that the current configuration will be replaced
5507 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005508 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005509 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005510 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5511 int[] featureTypes, String packageName) {
5512 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5515 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005516 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 final long identity = Binder.clearCallingIdentity();
5519 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005520 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005521 // may happen if the device does not support IMS.
5522 return false;
5523 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005524 Map<Integer, String> featureConfig = new HashMap<>();
5525 for (int featureType : featureTypes) {
5526 featureConfig.put(featureType, packageName);
5527 }
5528 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5529 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005533 }
5534
5535 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005536 * Clears any carrier ImsService overrides for the slot index specified that were previously
5537 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5538 *
5539 * This should only be used for testing.
5540 *
5541 * @param slotIndex the slot ID that the ImsService should bind for.
5542 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5543 */
5544 @Override
5545 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5546 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5548 "clearCarrierImsServiceOverride");
5549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5550 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5551 "clearCarrierImsServiceOverride");
5552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 if (mImsResolver == null) {
5556 // may happen if the device does not support IMS.
5557 return false;
5558 }
5559 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
5563 }
5564
5565 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005566 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005567 *
5568 * @param slotId The slot that the ImsService is associated with.
5569 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5570 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005571 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005572 * @return the package name of the ImsService configuration.
5573 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005574 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5575 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005576 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005577 TelephonyPermissions
5578 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5579 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5580 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005584 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005585 // may happen if the device does not support IMS.
5586 return "";
5587 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005588 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005589 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5590 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005594 }
5595
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005596 /**
5597 * Get the MmTelFeature state associated with the requested subscription id.
5598 * @param subId The subscription that the MmTelFeature is associated with.
5599 * @param callback A callback with an integer containing the
5600 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5601 */
5602 @Override
5603 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5604 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5605 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5607 "IMS not available on device.");
5608 }
5609 final long token = Binder.clearCallingIdentity();
5610 try {
5611 int slotId = getSlotIndex(subId);
5612 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5613 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5614 + subId + "'");
5615 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5616 }
5617 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5618 try {
5619 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5620 } catch (RemoteException e) {
5621 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5622 + "Ignore");
5623 }
5624 });
5625 } finally {
5626 Binder.restoreCallingIdentity(token);
5627 }
5628 }
5629
Daniel Brightbb5840b2021-01-12 15:48:18 -08005630 /**
5631 * Sets the ims registration state on all valid {@link Phone}s.
5632 */
5633 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005638 // NOTE: Before S, this method only set the default phone.
5639 for (final Phone phone : PhoneFactory.getPhones()) {
5640 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5641 phone.setImsRegistrationState(registered);
5642 }
5643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Wink Saville36469e72014-06-11 15:17:00 -07005647 }
5648
5649 /**
Stuart Scott54788802015-03-30 13:18:01 -07005650 * Set the network selection mode to automatic.
5651 *
5652 */
5653 @Override
5654 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
shilufc958392020-01-20 11:36:01 -08005660 if (!isActiveSubscription(subId)) {
5661 return;
5662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5664 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Stuart Scott54788802015-03-30 13:18:01 -07005668 }
5669
Jack Yud10cdd42020-09-28 20:28:01 -07005670 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005671 * Ask the radio to connect to the input network and change selection mode to manual.
5672 *
5673 * @param subId the id of the subscription.
5674 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5675 * the operator to attach to.
5676 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5677 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5678 * normal network selection next time.
5679 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005680 */
5681 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005682 public boolean setNetworkSelectionModeManual(
5683 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005686
5687 if (!isActiveSubscription(subId)) {
5688 return false;
5689 }
5690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 final long identity = Binder.clearCallingIdentity();
5692 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005693 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005695 if (DBG) {
5696 log("setNetworkSelectionModeManual: subId: " + subId
5697 + " operator: " + operatorInfo);
5698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005703 }
shilu84f6e8b2019-12-19 13:58:01 -08005704 /**
5705 * Get the manual network selection
5706 *
5707 * @param subId the id of the subscription.
5708 *
5709 * @return the previously saved user selected PLMN
5710 */
5711 @Override
5712 public String getManualNetworkSelectionPlmn(int subId) {
5713 TelephonyPermissions
5714 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5715 mApp, subId, "getManualNetworkSelectionPlmn");
5716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005720 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005721 }
5722
5723 final Phone phone = getPhone(subId);
5724 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005725 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005726 }
5727 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5728 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5729 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
5733 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005734
5735 /**
5736 * Scans for available networks.
5737 */
5738 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005739 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5740 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5742 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005743 LocationAccessPolicy.LocationPermissionResult locationResult =
5744 LocationAccessPolicy.checkLocationPermission(mApp,
5745 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5746 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005747 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005748 .setCallingPid(Binder.getCallingPid())
5749 .setCallingUid(Binder.getCallingUid())
5750 .setMethod("getCellNetworkScanResults")
5751 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005752 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5753 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005754 .build());
5755 switch (locationResult) {
5756 case DENIED_HARD:
5757 throw new SecurityException("Not allowed to access scan results -- location");
5758 case DENIED_SOFT:
5759 return null;
5760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
Pengquan Menga1bb6272018-09-06 09:59:22 -07005762 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 try {
5764 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005765 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005770 }
5771
5772 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005773 * Get the call forwarding info, given the call forwarding reason.
5774 */
5775 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005776 public void getCallForwarding(int subId, int callForwardingReason,
5777 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005778 enforceReadPrivilegedPermission("getCallForwarding");
5779 long identity = Binder.clearCallingIdentity();
5780 try {
5781 if (DBG) {
5782 log("getCallForwarding: subId " + subId
5783 + " callForwardingReason" + callForwardingReason);
5784 }
Hall Liu27d24262020-09-18 19:04:59 -07005785
5786 Phone phone = getPhone(subId);
5787 if (phone == null) {
5788 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005789 callback.onError(
5790 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005791 } catch (RemoteException e) {
5792 // ignore
5793 }
5794 return;
5795 }
5796
5797 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5798 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5799 @Override
5800 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5801 try {
5802 callback.onCallForwardingInfoAvailable(info);
5803 } catch (RemoteException e) {
5804 // ignore
5805 }
5806 }
5807
5808 @Override
5809 public void onError(int error) {
5810 try {
5811 callback.onError(error);
5812 } catch (RemoteException e) {
5813 // ignore
5814 }
5815 }
5816 });
5817 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
5821 }
5822
5823 /**
5824 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5825 * reason, the number to forward, and the timeout before the forwarding is attempted.
5826 */
5827 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005828 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5829 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005830 enforceModifyPermission();
5831 long identity = Binder.clearCallingIdentity();
5832 try {
5833 if (DBG) {
5834 log("setCallForwarding: subId " + subId
5835 + " callForwardingInfo" + callForwardingInfo);
5836 }
Hall Liu27d24262020-09-18 19:04:59 -07005837
5838 Phone phone = getPhone(subId);
5839 if (phone == null) {
5840 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005841 callback.accept(
5842 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005843 } catch (RemoteException e) {
5844 // ignore
5845 }
5846 return;
5847 }
5848
5849 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5850 FunctionalUtils.ignoreRemoteException(callback::accept));
5851
5852 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005853 } finally {
5854 Binder.restoreCallingIdentity(identity);
5855 }
5856 }
5857
5858 /**
Hall Liu27d24262020-09-18 19:04:59 -07005859 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005860 */
5861 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005862 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005863 enforceReadPrivilegedPermission("getCallForwarding");
5864 long identity = Binder.clearCallingIdentity();
5865 try {
Hall Liu27d24262020-09-18 19:04:59 -07005866
5867 Phone phone = getPhone(subId);
5868 if (phone == null) {
5869 try {
5870 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5871 } catch (RemoteException e) {
5872 // ignore
5873 }
5874 return;
5875 }
5876
5877 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5878
Shuo Qian4a594052020-01-23 11:59:30 -08005879 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005880 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
5884 }
5885
5886 /**
Hall Liu27d24262020-09-18 19:04:59 -07005887 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005888 */
5889 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005890 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005891 enforceModifyPermission();
5892 long identity = Binder.clearCallingIdentity();
5893 try {
Hall Liu27d24262020-09-18 19:04:59 -07005894 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5895
5896 Phone phone = getPhone(subId);
5897 if (phone == null) {
5898 try {
5899 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5900 } catch (RemoteException e) {
5901 // ignore
5902 }
5903 return;
5904 }
5905
5906 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5907 FunctionalUtils.ignoreRemoteException(callback::accept));
5908
5909 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
5914
5915 /**
yinxub1bed742017-04-17 11:45:04 -07005916 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005917 *
yinxub1bed742017-04-17 11:45:04 -07005918 * @param subId id of the subscription
5919 * @param request contains the radio access networks with bands/channels to scan
5920 * @param messenger callback messenger for scan results or errors
5921 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005922 * @return the id of the requested scan which can be used to stop the scan.
5923 */
5924 @Override
5925 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005926 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5928 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005929 LocationAccessPolicy.LocationPermissionResult locationResult =
5930 LocationAccessPolicy.checkLocationPermission(mApp,
5931 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5932 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005933 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005934 .setCallingPid(Binder.getCallingPid())
5935 .setCallingUid(Binder.getCallingUid())
5936 .setMethod("requestNetworkScan")
5937 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005938 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5939 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005940 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005941 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005942 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5943 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005944 if (e != null) {
5945 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5946 throw e;
5947 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005948 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005949 return TelephonyScanManager.INVALID_SCAN_ID;
5950 }
5951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 }
Hall Liu912dfd32019-04-25 14:02:26 -07005953 int callingUid = Binder.getCallingUid();
5954 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005955 final long identity = Binder.clearCallingIdentity();
5956 try {
5957 return mNetworkScanRequestTracker.startNetworkScan(
5958 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005959 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
yinxu504e1392017-04-12 16:03:22 -07005963 }
5964
Hall Liub2ac8ef2019-02-28 15:56:23 -08005965 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005966 NetworkScanRequest request, int subId, String callingPackage) {
5967 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005968 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5969 boolean hasNetworkScanPermission =
5970 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5971 == PERMISSION_GRANTED;
5972
5973 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5974 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5975 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005976 }
5977
5978 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5979 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005980 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5981 return new SecurityException("Specific channels must not be"
5982 + " scanned without location access.");
5983 }
5984 }
5985 }
5986
Hall Liub2ac8ef2019-02-28 15:56:23 -08005987 return null;
5988 }
5989
yinxu504e1392017-04-12 16:03:22 -07005990 /**
5991 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005992 *
5993 * @param subId id of the subscription
5994 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005995 */
5996 @Override
5997 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5999 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000
Hall Liu912dfd32019-04-25 14:02:26 -07006001 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 final long identity = Binder.clearCallingIdentity();
6003 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006004 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
yinxu504e1392017-04-12 16:03:22 -07006008 }
6009
6010 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006011 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006012 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006013 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006014 */
6015 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006016 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006017 TelephonyPermissions
6018 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006019 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006023 if (DBG) log("getAllowedNetworkTypesBitmask");
6024 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6025 int networkTypesBitmask = (result != null ? result[0] : -1);
6026 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6027 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006031 }
6032
6033 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006034 * Get the allowed network types for certain reason.
6035 *
6036 * @param subId the id of the subscription.
6037 * @param reason the reason the allowed network type change is taking place
6038 * @return the allowed network types.
6039 */
6040 @Override
6041 public long getAllowedNetworkTypesForReason(int subId,
6042 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6043 TelephonyPermissions
6044 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6045 mApp, subId, "getAllowedNetworkTypesForReason");
6046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
6053
6054 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006055 * Enable/Disable E-UTRA-NR Dual Connectivity
6056 * @param subId subscription id of the sim card
6057 * @param nrDualConnectivityState expected NR dual connectivity state
6058 * This can be passed following states
6059 * <ol>
6060 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6061 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6062 * <li>Disable NR dual connectivity and force secondary cell to be released
6063 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6064 * </ol>
6065 * @return operation result.
6066 */
6067 @Override
6068 public int setNrDualConnectivityState(int subId,
6069 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6071 mApp, subId, "enableNRDualConnectivity");
6072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6073 final long identity = Binder.clearCallingIdentity();
6074 try {
6075 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6076 nrDualConnectivityState, subId,
6077 workSource);
6078 if (DBG) log("enableNRDualConnectivity result: " + result);
6079 return result;
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
6083 }
6084
6085 /**
6086 * Is E-UTRA-NR Dual Connectivity enabled
6087 * @return true if dual connectivity is enabled else false
6088 */
6089 @Override
6090 public boolean isNrDualConnectivityEnabled(int subId) {
6091 TelephonyPermissions
6092 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6093 mApp, subId, "isNRDualConnectivityEnabled");
6094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6095 final long identity = Binder.clearCallingIdentity();
6096 try {
6097 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6098 null, subId, workSource);
6099 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6100 return isEnabled;
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006107 * get carrier bandwidth per primary and secondary carrier
6108 * @param subId subscription id of the sim card
6109 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6110 */
6111 @Override
6112 public CarrierBandwidth getCarrierBandwidth(int subId) {
6113 TelephonyPermissions
6114 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6115 mApp, subId, "isNRDualConnectivityEnabled");
6116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6117 final long identity = Binder.clearCallingIdentity();
6118 try {
6119 CarrierBandwidth carrierBandwidth =
6120 getPhoneFromSubId(subId).getCarrierBandwidth();
6121 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6122 return carrierBandwidth;
6123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
6126 }
6127
6128 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006129 * Set the allowed network types of the device and
6130 * provide the reason triggering the allowed network change.
6131 *
6132 * @param subId the id of the subscription.
6133 * @param reason the reason the allowed network type change is taking place
6134 * @param allowedNetworkTypes the allowed network types.
6135 * @return true on success; false on any failure.
6136 */
6137 @Override
6138 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006139 @TelephonyManager.AllowedNetworkTypesReason int reason,
6140 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6142 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006143 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6144 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6145 return false;
6146 }
6147
6148 if (DBG) {
6149 log("setAllowedNetworkTypesForReason: " + reason
6150 + " value: " + allowedNetworkTypes);
6151 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006152 final long identity = Binder.clearCallingIdentity();
6153 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006154 Boolean success = (Boolean) sendRequest(
6155 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6156 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6157
6158 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6159 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006160 } finally {
6161 Binder.restoreCallingIdentity(identity);
6162 }
6163 }
6164
6165 /**
Miaoa84611c2019-03-15 09:21:10 +08006166 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006167 *
Miaoa84611c2019-03-15 09:21:10 +08006168 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006169 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006170 * @hide
6171 */
6172 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006173 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006176 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 try {
Miaoa84611c2019-03-15 09:21:10 +08006178 if (phone != null) {
6179 return phone.hasMatchedTetherApnSetting();
6180 } else {
6181 return false;
6182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 } finally {
6184 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006185 }
Junda Liu475951f2014-11-07 16:45:03 -08006186 }
6187
6188 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006189 * Enable or disable always reporting signal strength changes from radio.
6190 *
6191 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6192 */
6193 @Override
6194 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6195 enforceModifyPermission();
6196 enforceSystemCaller();
6197
6198 final long identity = Binder.clearCallingIdentity();
6199 final Phone phone = getPhone(subId);
6200 try {
6201 if (phone != null) {
6202 if (DBG) {
6203 log("setAlwaysReportSignalStrength: subId=" + subId
6204 + " isEnable=" + isEnable);
6205 }
6206 phone.setAlwaysReportSignalStrength(isEnable);
6207 } else {
6208 loge("setAlwaysReportSignalStrength: no phone found for subId="
6209 + subId);
6210 }
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006217 * Get the user enabled state of Mobile Data.
6218 *
6219 * TODO: remove and use isUserDataEnabled.
6220 * This can't be removed now because some vendor codes
6221 * calls through ITelephony directly while they should
6222 * use TelephonyManager.
6223 *
6224 * @return true on enabled
6225 */
6226 @Override
6227 public boolean getDataEnabled(int subId) {
6228 return isUserDataEnabled(subId);
6229 }
6230
6231 /**
6232 * Get whether mobile data is enabled per user setting.
6233 *
6234 * There are other factors deciding whether mobile data is actually enabled, but they are
6235 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006236 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006237 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006238 *
6239 * @return {@code true} if data is enabled else {@code false}
6240 */
6241 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006242 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006243 try {
6244 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6245 null);
6246 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6248 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250
6251 final long identity = Binder.clearCallingIdentity();
6252 try {
6253 int phoneId = mSubscriptionController.getPhoneId(subId);
6254 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6255 Phone phone = PhoneFactory.getPhone(phoneId);
6256 if (phone != null) {
6257 boolean retVal = phone.isUserDataEnabled();
6258 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6259 return retVal;
6260 } else {
6261 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6262 return false;
6263 }
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006266 }
6267 }
6268
6269 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006270 * Checks if the device is capable of mobile data by considering whether whether the
6271 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6272 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006273 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006274 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006275 */
6276 @Override
6277 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006278 try {
6279 try {
6280 mApp.enforceCallingOrSelfPermission(
6281 android.Manifest.permission.ACCESS_NETWORK_STATE,
6282 null);
6283 } catch (Exception e) {
6284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6285 "isDataEnabled");
6286 }
6287 } catch (Exception e) {
6288 enforceReadPrivilegedPermission("isDataEnabled");
6289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290
6291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 int phoneId = mSubscriptionController.getPhoneId(subId);
6294 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6295 Phone phone = PhoneFactory.getPhone(phoneId);
6296 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006297 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6299 return retVal;
6300 } else {
6301 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6302 return false;
6303 }
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006306 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006307 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006308
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006309 /**
6310 * Check if data is enabled for a specific reason
6311 * @param subId Subscription index
6312 * @param reason the reason the data enable change is taking place
6313 * @return {@code true} if the overall data is enabled; {@code false} if not.
6314 */
6315 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006316 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006317 @TelephonyManager.DataEnabledReason int reason) {
6318 try {
6319 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6320 null);
6321 } catch (Exception e) {
6322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006323 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006324 }
6325
6326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 int phoneId = mSubscriptionController.getPhoneId(subId);
6330 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006331 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006332 + " reason=" + reason);
6333 }
6334 Phone phone = PhoneFactory.getPhone(phoneId);
6335 if (phone != null) {
6336 boolean retVal;
6337 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6338 retVal = phone.isUserDataEnabled();
6339 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006340 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006341 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006342 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006343 return retVal;
6344 } else {
6345 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006346 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006347 + subId + " retVal=false");
6348 }
6349 return false;
6350 }
6351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
6354 }
6355
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006356 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006357 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006358 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6359 // Skip the check if it's one of these special uids
6360 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6361 }
6362
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006363 //load access rules from carrier configs, and check those as well: b/139133814
6364 SubscriptionController subController = SubscriptionController.getInstance();
6365 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6366 || subController == null) return privilegeFromSim;
6367
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006368 PackageManager pkgMgr = phone.getContext().getPackageManager();
6369 String[] packages = pkgMgr.getPackagesForUid(uid);
6370
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006373 int subId = phone.getSubId();
6374 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6375 // A test override is in place for the privileges for this subId, so don't try to
6376 // read the subscription privileges.
6377 return privilegeFromSim;
6378 }
6379 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006380 SubscriptionManager subManager = (SubscriptionManager)
6381 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6382 for (String pkg : packages) {
6383 if (subManager.canManageSubscription(subInfo, pkg)) {
6384 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6385 }
6386 }
6387 return privilegeFromSim;
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
6391 }
6392
6393 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6394 String pkgName) {
6395 //load access rules from carrier configs, and check those as well: b/139133814
6396 SubscriptionController subController = SubscriptionController.getInstance();
6397 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6398 || subController == null) return privilegeFromSim;
6399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006402 int subId = phone.getSubId();
6403 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6404 // A test override is in place for the privileges for this subId, so don't try to
6405 // read the subscription privileges.
6406 return privilegeFromSim;
6407 }
6408 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006409 SubscriptionManager subManager = (SubscriptionManager)
6410 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6411 return subManager.canManageSubscription(subInfo, pkgName)
6412 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
6416 }
6417
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006419 public int getCarrierPrivilegeStatus(int subId) {
6420 final Phone phone = getPhone(subId);
6421 if (phone == null) {
6422 loge("getCarrierPrivilegeStatus: Invalid subId");
6423 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6424 }
6425 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006426 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006427 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006428 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6429 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006430
6431 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6432 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006433 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006434 }
Junda Liu29340342014-07-10 15:23:27 -07006435
6436 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006437 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006438 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006439 final Phone phone = getPhone(subId);
6440 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006441 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006442 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6443 }
6444 UiccProfile profile =
6445 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6446 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006447 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6449 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006450 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006451 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006452 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 }
6454
6455 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006456 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6457 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006459 }
6460
6461 int phoneId = SubscriptionManager.getPhoneId(subId);
6462 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006463 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006464 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006465 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6466 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006467 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6468 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6469 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006470 }
6471
6472 @Override
6473 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006474 if (TextUtils.isEmpty(pkgName))
6475 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006476 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6477 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6478 UiccCard card = UiccController.getInstance().getUiccCard(i);
6479 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006480 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006481 continue;
6482 }
6483
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006484 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6485 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6486 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006487 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6488 break;
6489 }
6490 }
6491
6492 return result;
Junda Liu29340342014-07-10 15:23:27 -07006493 }
Derek Tan89e89d42014-07-08 17:00:10 -07006494
6495 @Override
Junda Liue64de782015-04-16 17:19:16 -07006496 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6497 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6498 loge("phoneId " + phoneId + " is not valid.");
6499 return null;
6500 }
6501 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006502 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006503 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006504 return null ;
6505 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006506 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006507 }
6508
Amith Yamasani6e118872016-02-19 12:53:51 -08006509 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006510 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006512 List<String> privilegedPackages = new ArrayList<>();
6513 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006514 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6515 // has UICC in that slot.
6516 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006517 if (card.hasCarrierPrivilegeRules()) {
6518 if (packages == null) {
6519 // Only check packages in user 0 for now
6520 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006521 PackageManager.MATCH_DISABLED_COMPONENTS
6522 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006523 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006524 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006525 }
6526 for (int p = packages.size() - 1; p >= 0; p--) {
6527 PackageInfo pkgInfo = packages.get(p);
6528 if (pkgInfo != null && pkgInfo.packageName != null
6529 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006530 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006531 privilegedPackages.add(pkgInfo.packageName);
6532 }
6533 }
6534 }
6535 }
6536 return privilegedPackages;
6537 }
6538
chen xuf7e9fe82019-05-09 19:31:02 -07006539 @Override
6540 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006541 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6542
6543 final long identity = Binder.clearCallingIdentity();
6544
chen xuf7e9fe82019-05-09 19:31:02 -07006545 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006546 try {
6547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6548 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6549 }
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006552 }
6553 return privilegedPackages;
6554 }
6555
Wink Savilleb564aae2014-10-23 10:18:09 -07006556 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006557 final Phone phone = getPhone(subId);
6558 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006559 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006560 return null;
6561 }
6562 String iccId = card.getIccId();
6563 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006564 return null;
6565 }
6566 return iccId;
6567 }
6568
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006569 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006570 public void setCallComposerStatus(int subId, int status) {
6571 enforceModifyPermission();
6572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 Phone phone = getPhone(subId);
6576 if (phone != null) {
6577 Phone defaultPhone = phone.getImsPhone();
6578 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6579 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6580 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006581 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6582 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006583 }
6584 }
Shuo Qian284ae752020-12-22 19:10:14 -08006585 } catch (ImsException e) {
6586 throw new ServiceSpecificException(e.getCode());
6587 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006588 Binder.restoreCallingIdentity(identity);
6589 }
6590 }
6591
6592 @Override
6593 public int getCallComposerStatus(int subId) {
6594 enforceReadPrivilegedPermission("getCallComposerStatus");
6595
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
6598 Phone phone = getPhone(subId);
6599 if (phone != null) {
6600 Phone defaultPhone = phone.getImsPhone();
6601 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6602 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6603 return imsPhone.getCallComposerStatus();
6604 }
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6610 }
6611
6612 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006613 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6614 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006615 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006616 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 final String iccId = getIccId(subId);
6621 final Phone phone = getPhone(subId);
6622 if (phone == null) {
6623 return false;
6624 }
6625 final String subscriberId = phone.getSubscriberId();
6626
6627 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006628 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 + subscriberId + " to " + number);
6630 }
6631
6632 if (TextUtils.isEmpty(iccId)) {
6633 return false;
6634 }
6635
6636 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6637
6638 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6639 if (alphaTag == null) {
6640 editor.remove(alphaTagPrefKey);
6641 } else {
6642 editor.putString(alphaTagPrefKey, alphaTag);
6643 }
6644
6645 // Record both the line number and IMSI for this ICCID, since we need to
6646 // track all merged IMSIs based on line number
6647 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6648 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6649 if (number == null) {
6650 editor.remove(numberPrefKey);
6651 editor.remove(subscriberPrefKey);
6652 } else {
6653 editor.putString(numberPrefKey, number);
6654 editor.putString(subscriberPrefKey, subscriberId);
6655 }
6656
6657 editor.commit();
6658 return true;
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006661 }
Derek Tan7226c842014-07-02 17:42:23 -07006662 }
6663
6664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006665 public String getLine1NumberForDisplay(int subId, String callingPackage,
6666 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006667 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006669 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006670 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006671 return null;
6672 }
Derek Tan97ebb422014-09-05 16:55:38 -07006673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 String iccId = getIccId(subId);
6677 if (iccId != null) {
6678 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6679 if (DBG_MERGE) {
6680 log("getLine1NumberForDisplay returning "
6681 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6682 }
6683 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6686 return null;
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006689 }
Derek Tan7226c842014-07-02 17:42:23 -07006690 }
6691
6692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006693 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6694 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006696 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006697 return null;
6698 }
Derek Tan97ebb422014-09-05 16:55:38 -07006699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 String iccId = getIccId(subId);
6703 if (iccId != null) {
6704 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6705 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6706 }
6707 return null;
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006710 }
Derek Tan7226c842014-07-02 17:42:23 -07006711 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006712
6713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006714 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6715 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006716 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6717 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006719 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006720 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006721 return null;
6722 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006723
Jordan Liub49b04b2019-05-06 14:45:15 -07006724 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6725 // the process, where TelephonyManager was instantiated.
6726 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006727 final long identity = Binder.clearCallingIdentity();
6728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006729 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 final TelephonyManager tele = TelephonyManager.from(context);
6731 final SubscriptionManager sub = SubscriptionManager.from(context);
6732
6733 // Figure out what subscribers are currently active
6734 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735
Jordan Liub49b04b2019-05-06 14:45:15 -07006736 // Only consider subs which match the current subId
6737 // This logic can be simplified. See b/131189269 for progress.
6738 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006739 activeSubscriberIds.add(tele.getSubscriberId(subId));
6740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
6742 // First pass, find a number override for an active subscriber
6743 String mergeNumber = null;
6744 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6745 for (String key : prefs.keySet()) {
6746 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6747 final String subscriberId = (String) prefs.get(key);
6748 if (activeSubscriberIds.contains(subscriberId)) {
6749 final String iccId = key.substring(
6750 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6751 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6752 mergeNumber = (String) prefs.get(numberKey);
6753 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006754 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 + " for active subscriber " + subscriberId);
6756 }
6757 if (!TextUtils.isEmpty(mergeNumber)) {
6758 break;
6759 }
6760 }
6761 }
6762 }
6763
6764 // Shortcut when no active merged subscribers
6765 if (TextUtils.isEmpty(mergeNumber)) {
6766 return null;
6767 }
6768
6769 // Second pass, find all subscribers under that line override
6770 final ArraySet<String> result = new ArraySet<>();
6771 for (String key : prefs.keySet()) {
6772 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6773 final String number = (String) prefs.get(key);
6774 if (mergeNumber.equals(number)) {
6775 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6776 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6777 final String subscriberId = (String) prefs.get(subscriberKey);
6778 if (!TextUtils.isEmpty(subscriberId)) {
6779 result.add(subscriberId);
6780 }
6781 }
6782 }
6783 }
6784
6785 final String[] resultArray = result.toArray(new String[result.size()]);
6786 Arrays.sort(resultArray);
6787 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006788 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6790 }
6791 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006792 } finally {
6793 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006794 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006795 }
6796
6797 @Override
zoey chen38003472019-12-13 17:16:31 +08006798 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6799 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 final TelephonyManager telephonyManager = mApp.getSystemService(
6804 TelephonyManager.class);
6805 String subscriberId = telephonyManager.getSubscriberId(subId);
6806 if (subscriberId == null) {
6807 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006808 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006809 + subId);
6810 }
6811 return null;
6812 }
6813
6814 final SubscriptionInfo info = SubscriptionController.getInstance()
6815 .getSubscriptionInfo(subId);
6816 final ParcelUuid groupUuid = info.getGroupUuid();
6817 // If it doesn't belong to any group, return just subscriberId of itself.
6818 if (groupUuid == null) {
6819 return new String[]{subscriberId};
6820 }
6821
6822 // Get all subscriberIds from the group.
6823 final List<String> mergedSubscriberIds = new ArrayList<>();
6824 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006825 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006826 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006827 for (SubscriptionInfo subInfo : groupInfos) {
6828 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6829 if (subscriberId != null) {
6830 mergedSubscriberIds.add(subscriberId);
6831 }
6832 }
6833
6834 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837
6838 }
6839 }
6840
6841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006842 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006843 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
6848 final Phone phone = getPhone(subId);
6849 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006853 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006854
6855 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006856 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006857 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6858 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006859 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6860 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 final Phone phone = getPhone(subId);
6865 if (phone == null) {
6866 return false;
6867 }
6868 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6869 cdmaNonRoamingList);
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006872 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006873 }
6874
6875 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006876 @Deprecated
6877 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6878 enforceModifyPermission();
6879
6880 int returnValue = 0;
6881 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006882 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006883 if(result.exception == null) {
6884 if (result.result != null) {
6885 byte[] responseData = (byte[])(result.result);
6886 if(responseData.length > oemResp.length) {
6887 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6888 responseData.length + "bytes. Buffer Size is " +
6889 oemResp.length + "bytes.");
6890 }
6891 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6892 returnValue = responseData.length;
6893 }
6894 } else {
6895 CommandException ex = (CommandException) result.exception;
6896 returnValue = ex.getCommandError().ordinal();
6897 if(returnValue > 0) returnValue *= -1;
6898 }
6899 } catch (RuntimeException e) {
6900 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6901 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6902 if(returnValue > 0) returnValue *= -1;
6903 }
6904
6905 return returnValue;
6906 }
6907
6908 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006909 public void setRadioCapability(RadioAccessFamily[] rafs) {
6910 try {
6911 ProxyController.getInstance().setRadioCapability(rafs);
6912 } catch (RuntimeException e) {
6913 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6914 }
6915 }
6916
6917 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006918 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006919 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006920 try {
6921 TelephonyPermissions
6922 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6923 mApp, phone.getSubId(), "getRadioAccessFamily");
6924 } catch (SecurityException e) {
6925 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6926 throw e;
6927 }
chen xub97461a2018-10-26 14:17:57 -07006928 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006929 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006930 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 final long identity = Binder.clearCallingIdentity();
6933 try {
chen xub97461a2018-10-26 14:17:57 -07006934 TelephonyPermissions
6935 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6936 mApp, phone.getSubId(), "getRadioAccessFamily");
6937 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 } finally {
6939 Binder.restoreCallingIdentity(identity);
6940 }
chen xub97461a2018-10-26 14:17:57 -07006941 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006942 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006943
6944 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006945 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08006946 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08006947 try {
6948 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6949 Binder.getCallingUid())) {
6950 throw new SecurityException("Package uid and package name do not match: "
6951 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6952 }
6953 } catch (PackageManager.NameNotFoundException e) {
6954 throw new SecurityException("Package name invalid:" + callingPackage);
6955 }
6956 RoleManager rm = mApp.getSystemService(RoleManager.class);
6957 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6958 if (!dialerRoleHolders.contains(callingPackage)) {
6959 throw new SecurityException("App must be the dialer role holder to"
6960 + " upload a call composer pic");
6961 }
6962
6963 Executors.newSingleThreadExecutor().execute(() -> {
6964 ByteArrayOutputStream output = new ByteArrayOutputStream(
6965 (int) TelephonyManager.getMaximumCallComposerPictureSize());
6966 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
6967 boolean readUntilEnd = false;
6968 int totalBytesRead = 0;
6969 byte[] buffer = new byte[16 * 1024];
6970 while (true) {
6971 int numRead;
6972 try {
6973 numRead = input.read(buffer);
6974 } catch (IOException e) {
6975 try {
6976 fd.checkError();
6977 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
6978 null);
6979 } catch (IOException e1) {
6980 // This means that the other side closed explicitly with an error. If this
6981 // happens, log and ignore.
6982 loge("Remote end of call composer picture pipe closed: " + e1);
6983 }
6984 break;
6985 }
6986 if (numRead == -1) {
6987 readUntilEnd = true;
6988 break;
6989 }
6990 totalBytesRead += numRead;
6991 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
6992 loge("Too many bytes read for call composer picture: " + totalBytesRead);
6993 try {
6994 input.close();
6995 } catch (IOException e) {
6996 // ignore
6997 }
6998 break;
6999 }
7000 output.write(buffer, 0, numRead);
7001 }
7002 // Generally, the remote end will close the file descriptors. The only case where we
7003 // close is above, where the picture size is too big.
7004
7005 try {
7006 fd.checkError();
7007 } catch (IOException e) {
7008 loge("Remote end for call composer closed with an error: " + e);
7009 return;
7010 }
7011
Hall Liuaa4211e2021-01-20 15:43:39 -08007012 if (!readUntilEnd) {
7013 loge("Did not finish reading entire image; aborting");
7014 return;
7015 }
Hall Liu82694d52020-12-11 18:22:04 -08007016
Hall Liuaa4211e2021-01-20 15:43:39 -08007017 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7018 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7019 new CallComposerPictureTransfer.Factory() {},
7020 imageData,
7021 (result) -> {
7022 if (result.first != null) {
7023 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7024 Bundle outputResult = new Bundle();
7025 outputResult.putParcelable(
7026 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7027 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7028 outputResult);
7029 } else {
7030 callback.send(result.second, null);
7031 }
7032 }
7033 );
Hall Liu82694d52020-12-11 18:22:04 -08007034 });
7035 }
7036
7037 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007038 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007039 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007040 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007044 ImsManager.getInstance(defaultPhone.getContext(),
7045 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007049 }
7050
7051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007052 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007053 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7055 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007056 return false;
7057 }
Svet Ganovb320e182015-04-16 12:30:10 -07007058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 final long identity = Binder.clearCallingIdentity();
7060 try {
7061 // Check the user preference and the system-level IMS setting. Even if the user has
7062 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7063 // In the long run, we may instead need to check if there exists a connection service
7064 // which can support video calling.
7065 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007066 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 return imsManager.isVtEnabledByPlatform()
7068 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7069 && imsManager.isVtEnabledByUser();
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007073 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007074
Andrew Leea1239f22015-03-02 17:44:07 -08007075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007076 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7077 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007079 mApp, subId, callingPackage, callingFeatureId,
7080 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 return false;
7082 }
7083
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 CarrierConfigManager configManager =
7087 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007088 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092 }
Andrew Leea1239f22015-03-02 17:44:07 -08007093 }
7094
7095 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007096 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007098 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 return false;
7100 }
7101
7102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 CarrierConfigManager configManager =
7105 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007106 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
7110 }
Andrew Leea1239f22015-03-02 17:44:07 -08007111 }
7112
Andrew Lee9431b832015-03-09 18:46:45 -07007113 @Override
7114 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007115 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007116 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007117 }
7118
7119 @Override
7120 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 final long identity = Binder.clearCallingIdentity();
7122 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007123 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
Andrew Lee9431b832015-03-09 18:46:45 -07007127 }
7128
Hall Liuf6668912018-10-31 17:05:23 -07007129 /**
7130 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7131 * support for the feature and device firmware support.
7132 *
7133 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7134 */
7135 @Override
7136 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007138 final Phone phone = getPhone(subscriptionId);
7139 if (phone == null) {
7140 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7141 return false;
7142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7146 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007147 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148 return isCarrierSupported && isDeviceSupported;
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151 }
Hall Liu98187582018-01-22 19:15:32 -08007152 }
7153
Hall Liuf6668912018-10-31 17:05:23 -07007154 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007155 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7156 * RTT setting, will return true if the device and carrier both support RTT.
7157 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007158 */
7159 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 final long identity = Binder.clearCallingIdentity();
7161 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007162 boolean isRttSupported = isRttSupported(subscriptionId);
7163 boolean isUserRttSettingOn = Settings.Secure.getInt(
7164 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7165 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7166 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7167 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007171 }
7172
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007173 @Deprecated
7174 @Override
7175 public String getDeviceId(String callingPackage) {
7176 return getDeviceIdWithFeature(callingPackage, null);
7177 }
7178
Sanket Padawe7310cc72015-01-14 09:53:20 -08007179 /**
7180 * Returns the unique device ID of phone, for example, the IMEI for
7181 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7182 *
7183 * <p>Requires Permission:
7184 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7185 */
7186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007187 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007188 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007189 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007190 return null;
7191 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007192 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007193 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007194 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007195 return null;
7196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 return phone.getDeviceId();
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007204 }
7205
Ping Sunc67b7c22016-03-02 19:16:45 +08007206 /**
7207 * {@hide}
7208 * Returns the IMS Registration Status on a particular subid
7209 *
7210 * @param subId
7211 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007212 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007213 Phone phone = getPhone(subId);
7214 if (phone != null) {
7215 return phone.isImsRegistered();
7216 } else {
7217 return false;
7218 }
7219 }
7220
Santos Cordon7a1885b2015-02-03 11:15:19 -08007221 @Override
7222 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7226 } finally {
7227 Binder.restoreCallingIdentity(identity);
7228 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007229 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007230
Tyler Gunnf70ed162019-04-03 15:28:53 -07007231 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007232 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007233 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007235 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007236 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7237 }
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
7246 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007247 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007248 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7249 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 Phone phone = getPhone(subscriptionId);
7253 if (phone == null) {
7254 return null;
7255 }
7256 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
7261
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007262 /**
7263 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007264 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007265 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 Phone phone = getPhone(subId);
7269 if (phone != null) {
7270 return phone.isWifiCallingEnabled();
7271 } else {
7272 return false;
7273 }
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007276 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007277 }
7278
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007279 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007280 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007281 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007282 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 Phone phone = getPhone(subId);
7286 if (phone != null) {
7287 return phone.isVideoEnabled();
7288 } else {
7289 return false;
7290 }
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007293 }
7294 }
7295
7296 /**
7297 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7298 * defined in {@link ImsRegistrationImplBase}.
7299 */
7300 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007301 final long identity = Binder.clearCallingIdentity();
7302 try {
7303 Phone phone = getPhone(subId);
7304 if (phone != null) {
7305 return phone.getImsRegistrationTech();
7306 } else {
7307 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7308 }
7309 } finally {
7310 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007311 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007312 }
7313
Stuart Scott8eef64f2015-04-08 15:13:54 -07007314 @Override
7315 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007316 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007317 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7318 return;
7319 }
7320
Svet Ganovcc087f82015-05-12 20:35:54 -07007321 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007322
Svet Ganovcc087f82015-05-12 20:35:54 -07007323 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007324 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7325 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007326 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007327 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007328 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007329 setAllowedNetworkTypesForReason(subId,
7330 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7331 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7332 setAllowedNetworkTypesForReason(subId,
7333 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7334 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7335 setAllowedNetworkTypesForReason(subId,
7336 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7337 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007338 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7339 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007340 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007341 // There has been issues when Sms raw table somehow stores orphan
7342 // fragments. They lead to garbled message when new fragments come
7343 // in and combined with those stale ones. In case this happens again,
7344 // user can reset all network settings which will clean up this table.
7345 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007346 // Clean up IMS settings as well here.
7347 int slotId = getSlotIndex(subId);
7348 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7349 ImsManager.getInstance(mApp, slotId).factoryReset();
7350 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007351
7352 // Erase modem config if erase modem on network setting is enabled.
7353 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7354 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7355 if (configValue != null && Boolean.parseBoolean(configValue)) {
7356 sendEraseModemConfig(getDefaultPhone());
7357 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007358 } finally {
7359 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007360 }
7361 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007362
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007363 private void cleanUpSmsRawTable(Context context) {
7364 ContentResolver resolver = context.getContentResolver();
7365 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7366 resolver.delete(uri, null, null);
7367 }
7368
Narayan Kamath1c496c22015-04-16 14:40:19 +01007369 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007370 public String getSimLocaleForSubscriber(int subId) {
7371 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7372 final Phone phone = getPhone(subId);
7373 if (phone == null) {
7374 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007375 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final long identity = Binder.clearCallingIdentity();
7378 try {
chen xu5d3637b2019-01-21 23:31:38 -08007379 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007380 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007381 if (info == null) {
7382 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7383 return null;
7384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 // Try and fetch the locale from the carrier properties or from the SIM language
7386 // preferences (EF-PL and EF-LI)...
7387 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007389 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7390 if (localeFromDefaultSim != null) {
7391 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7392 if (DBG) log("Using locale from subId: " + subId + " locale: "
7393 + localeFromDefaultSim);
7394 return localeFromDefaultSim.toLanguageTag();
7395 } else {
7396 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 }
7398 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 // The SIM language preferences only store a language (e.g. fr = French), not an
7401 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7402 // the SIM and carrier preferences does not include a country we add the country
7403 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007404 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007406 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 return mccLocale.toLanguageTag();
7408 }
7409
7410 if (DBG) log("No locale found - returning null");
7411 return null;
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007415 }
7416
7417 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007419 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007420 }
7421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 /**
7423 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7424 */
7425 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007426 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007427 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007428 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007429
Chenjie Yu1ba97252018-01-11 18:16:20 -08007430 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007431 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007432
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007433 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007434 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7435 * representing the state of the modem.
7436 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007437 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7438 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007439 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007440 */
7441 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007442 public void requestModemActivityInfo(ResultReceiver result) {
7443 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007444 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007448 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 } finally {
7450 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007451 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007452 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007453
Siddharth Rayb8114062018-06-17 15:02:38 -07007454 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7455 // less than total activity duration.
7456 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7457 if (info == null) {
7458 return false;
7459 }
7460 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007461 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7462 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7463
Siddharth Rayb8114062018-06-17 15:02:38 -07007464 return (info.isValid()
7465 && (info.getSleepTimeMillis() <= activityDurationMs)
7466 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007467 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007468 && (totalTxTimeMs <= activityDurationMs));
7469 }
7470
Jack Yu85bd38a2015-11-09 11:34:32 -08007471 /**
7472 * {@hide}
7473 * Returns the service state information on specified subscription.
7474 */
7475 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007476 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7477 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007480 return null;
7481 }
7482
Hall Liuf19c44f2018-11-27 14:38:17 -08007483 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7484 LocationAccessPolicy.checkLocationPermission(mApp,
7485 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7486 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007487 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007488 .setCallingPid(Binder.getCallingPid())
7489 .setCallingUid(Binder.getCallingUid())
7490 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007491 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007492 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007493 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7494 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007495 .build());
7496
7497 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7498 LocationAccessPolicy.checkLocationPermission(mApp,
7499 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7500 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007501 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007502 .setCallingPid(Binder.getCallingPid())
7503 .setCallingUid(Binder.getCallingUid())
7504 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007505 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007506 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007507 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7508 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007509 .build());
7510 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7511 boolean hasFinePermission =
7512 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7513 boolean hasCoarsePermission =
7514 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7515
Jack Yu479f40e2020-10-27 21:29:25 -07007516 final Phone phone = getPhone(subId);
7517 if (phone == null) {
7518 return null;
7519 }
7520
Jordan Liu0f2bc442020-11-18 16:47:37 -08007521 final long identity = Binder.clearCallingIdentity();
7522
Jack Yu479f40e2020-10-27 21:29:25 -07007523 boolean isCallingPackageDataService = phone.getDataServicePackages()
7524 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007526 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7527 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7528 Rlog.d(LOG_TAG,
7529 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7530 return null;
7531 }
7532
Hall Liuf19c44f2018-11-27 14:38:17 -08007533 ServiceState ss = phone.getServiceState();
7534
7535 // Scrub out the location info in ServiceState depending on what level of access
7536 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007537 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007538 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7539 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007543 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007544
7545 /**
7546 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7547 *
7548 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7549 * voicemail ringtone.
7550 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7551 * PhoneAccount.
7552 */
7553 @Override
7554 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7558 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007559 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7563 } finally {
7564 Binder.restoreCallingIdentity(identity);
7565 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007566 }
7567
7568 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007569 * Sets the per-account voicemail ringtone.
7570 *
7571 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7572 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7573 *
7574 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7575 * voicemail ringtone.
7576 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7577 * PhoneAccount.
7578 */
7579 @Override
7580 public void setVoicemailRingtoneUri(String callingPackage,
7581 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007582 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007584 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7585 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7587 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7588 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590
7591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7594 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007595 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 }
7597 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7598 } finally {
7599 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007600 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007601 }
7602
7603 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007604 * Returns whether vibration is set for voicemail notification in Phone settings.
7605 *
7606 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7607 * voicemail vibration setting.
7608 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7609 */
7610 @Override
7611 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 final long identity = Binder.clearCallingIdentity();
7613 try {
7614 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7615 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007616 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7620 } finally {
7621 Binder.restoreCallingIdentity(identity);
7622 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007623 }
7624
Youhan Wange64578a2016-05-02 15:32:42 -07007625 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007626 * Sets the per-account voicemail vibration.
7627 *
7628 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7629 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7630 *
7631 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7632 * voicemail vibration setting.
7633 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7634 * specific PhoneAccount.
7635 */
7636 @Override
7637 public void setVoicemailVibrationEnabled(String callingPackage,
7638 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007639 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007641 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7642 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7644 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7645 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007646 }
7647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7651 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007652 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 }
7654 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007657 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007658 }
7659
7660 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007661 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7662 *
7663 * @throws SecurityException if the caller does not have the required permission
7664 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007665 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007666 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007667 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007668 }
7669
7670 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007671 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7672 * permission.
7673 *
7674 * @throws SecurityException if the caller does not have the required permission
7675 */
7676 private void enforceSendSmsPermission() {
7677 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7678 }
7679
7680 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007681 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007682 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007683 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007684 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007685 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007689 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 if (componentName == null) {
7691 throw new SecurityException(
7692 "Caller not current active visual voicemail package[null]");
7693 }
7694 String vvmPackage = componentName.getPackageName();
7695 if (!callingPackage.equals(vvmPackage)) {
7696 throw new SecurityException("Caller not current active visual voicemail package["
7697 + vvmPackage + "]");
7698 }
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007701 }
7702 }
7703
7704 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007705 * Return the application ID for the app type.
7706 *
7707 * @param subId the subscription ID that this request applies to.
7708 * @param appType the uicc app type.
7709 * @return Application ID for specificied app type, or null if no uicc.
7710 */
7711 @Override
7712 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007713 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007714 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715
7716 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007717 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 if (phone == null) {
7719 return null;
7720 }
7721 String aid = null;
7722 try {
7723 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7724 .getApplicationByType(appType).getAid();
7725 } catch (Exception e) {
7726 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7727 }
7728 return aid;
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007731 }
Youhan Wange64578a2016-05-02 15:32:42 -07007732 }
7733
Youhan Wang4001d252016-05-11 10:29:41 -07007734 /**
7735 * Return the Electronic Serial Number.
7736 *
7737 * @param subId the subscription ID that this request applies to.
7738 * @return ESN or null if error.
7739 */
7740 @Override
7741 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007742 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007743 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744
7745 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007746 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 if (phone == null) {
7748 return null;
7749 }
7750 String esn = null;
7751 try {
7752 esn = phone.getEsn();
7753 } catch (Exception e) {
7754 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7755 }
7756 return esn;
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007759 }
Youhan Wang4001d252016-05-11 10:29:41 -07007760 }
7761
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007762 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007763 * Return the Preferred Roaming List Version.
7764 *
7765 * @param subId the subscription ID that this request applies to.
7766 * @return PRLVersion or null if error.
7767 */
7768 @Override
7769 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007770 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007771 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772
7773 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007774 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 if (phone == null) {
7776 return null;
7777 }
7778 String cdmaPrlVersion = null;
7779 try {
7780 cdmaPrlVersion = phone.getCdmaPrlVersion();
7781 } catch (Exception e) {
7782 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7783 }
7784 return cdmaPrlVersion;
7785 } finally {
7786 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007787 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007788 }
7789
7790 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007791 * Get snapshot of Telephony histograms
7792 * @return List of Telephony histograms
7793 * @hide
7794 */
7795 @Override
7796 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7798 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 return RIL.getTelephonyRILTimingHistograms();
7803 } finally {
7804 Binder.restoreCallingIdentity(identity);
7805 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007806 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007807
7808 /**
7809 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007810 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7811 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007812 * Require system privileges. In the future we may add this to carrier APIs.
7813 *
Michele Berionne482f8202018-11-27 18:57:59 -08007814 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007815 */
7816 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007817 @TelephonyManager.SetCarrierRestrictionResult
7818 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007819 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007821
Michele Berionne482f8202018-11-27 18:57:59 -08007822 if (carrierRestrictionRules == null) {
7823 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007824 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 final long identity = Binder.clearCallingIdentity();
7827 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007828 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007829 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007833 }
7834
7835 /**
7836 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007837 * Get the allowed carrier list and the excluded carrier list, including the priority between
7838 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007839 * Require system privileges. In the future we may add this to carrier APIs.
7840 *
Michele Berionne482f8202018-11-27 18:57:59 -08007841 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007842 */
7843 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007844 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007845 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847
7848 final long identity = Binder.clearCallingIdentity();
7849 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007850 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7851 if (response instanceof CarrierRestrictionRules) {
7852 return (CarrierRestrictionRules) response;
7853 }
7854 // Response is an Exception of some kind,
7855 // which is signalled to the user as a NULL retval
7856 return null;
7857 } catch (Exception e) {
7858 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7859 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007863 }
7864
fionaxu59545b42016-05-25 15:53:37 -07007865 /**
fionaxu59545b42016-05-25 15:53:37 -07007866 * Action set from carrier signalling broadcast receivers to enable/disable radio
7867 * @param subId the subscription ID that this action applies to.
7868 * @param enabled control enable or disable radio.
7869 * {@hide}
7870 */
7871 @Override
7872 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7873 enforceModifyPermission();
7874 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875
7876 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007877 if (phone == null) {
7878 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7879 return;
7880 }
7881 try {
7882 phone.carrierActionSetRadioEnabled(enabled);
7883 } catch (Exception e) {
7884 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 } finally {
7886 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007887 }
7888 }
7889
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007890 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007891 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7892 * network status based on which carrier apps could apply actions accordingly,
7893 * enable/disable default url handler for example.
7894 *
7895 * @param subId the subscription ID that this action applies to.
7896 * @param report control start/stop reporting the default network status.
7897 * {@hide}
7898 */
7899 @Override
7900 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7901 enforceModifyPermission();
7902 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903
7904 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007905 if (phone == null) {
7906 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7907 return;
7908 }
7909 try {
7910 phone.carrierActionReportDefaultNetworkStatus(report);
7911 } catch (Exception e) {
7912 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 } finally {
7914 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007915 }
7916 }
7917
7918 /**
fionaxud9622282017-07-17 17:51:30 -07007919 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7920 * @param subId the subscription ID that this action applies to.
7921 * {@hide}
7922 */
7923 @Override
7924 public void carrierActionResetAll(int subId) {
7925 enforceModifyPermission();
7926 final Phone phone = getPhone(subId);
7927 if (phone == null) {
7928 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7929 return;
7930 }
7931 try {
7932 phone.carrierActionResetAll();
7933 } catch (Exception e) {
7934 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7935 }
7936 }
7937
7938 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007939 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7940 * bug report is being generated.
7941 */
7942 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007943 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007944 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7945 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007946 writer.println("Permission Denial: can't dump Phone from pid="
7947 + Binder.getCallingPid()
7948 + ", uid=" + Binder.getCallingUid()
7949 + "without permission "
7950 + android.Manifest.permission.DUMP);
7951 return;
7952 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007953 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007954 }
Jack Yueb89b242016-06-22 13:27:47 -07007955
Brad Ebingerdac2f002018-04-03 15:17:52 -07007956 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007957 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7958 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7959 @NonNull String[] args) {
7960 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7961 this, in.getFileDescriptor(), out.getFileDescriptor(),
7962 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007963 }
7964
Jack Yueb89b242016-06-22 13:27:47 -07007965 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007966 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007967 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007968 * @param reason the reason the data enable change is taking place
7969 * @param enabled True if enabling the data, otherwise disabling.
7970 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007971 */
7972 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007973 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007974 boolean enabled) {
7975 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7976 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7977 try {
7978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007979 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007980 } catch (SecurityException se) {
7981 enforceModifyPermission();
7982 }
7983 } else {
7984 enforceModifyPermission();
7985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986
7987 final long identity = Binder.clearCallingIdentity();
7988 try {
7989 Phone phone = getPhone(subId);
7990 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007991 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7992 phone.carrierActionSetMeteredApnsEnabled(enabled);
7993 } else {
7994 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 }
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007999 }
8000 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008001
8002 /**
8003 * Get Client request stats
8004 * @return List of Client Request Stats
8005 * @hide
8006 */
8007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008008 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8009 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008011 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008012 return null;
8013 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008014 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016 final long identity = Binder.clearCallingIdentity();
8017 try {
8018 if (phone != null) {
8019 return phone.getClientRequestStats();
8020 }
8021
8022 return null;
8023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008026 }
8027
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008028 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008029 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008030 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008031 }
Jack Yueb4124c2017-02-16 15:32:43 -08008032
8033 /**
Grace Chen70990072017-03-24 17:21:30 -07008034 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008035 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008036 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008037 * @param state State of SIM (power down, power up, pass through)
8038 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8039 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8040 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008041 *
8042 **/
8043 @Override
Grace Chen70990072017-03-24 17:21:30 -07008044 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008045 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008046 Phone phone = PhoneFactory.getPhone(slotIndex);
8047
vagdeviaf9a5b92018-08-15 16:01:53 -07008048 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008053 phone.setSimPowerState(state, null, workSource);
8054 }
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
8057 }
8058 }
8059
8060 /**
8061 * Set SIM card power state.
8062 *
8063 * @param slotIndex SIM slot id.
8064 * @param state State of SIM (power down, power up, pass through)
8065 * @param callback callback to trigger after success or failure
8066 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8067 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8068 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8069 *
8070 **/
8071 @Override
8072 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8073 IIntegerConsumer callback) {
8074 enforceModifyPermission();
8075 Phone phone = PhoneFactory.getPhone(slotIndex);
8076
8077 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 if (phone != null) {
8082 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8083 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 }
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008087 }
8088 }
Shuo Qiandd210312017-04-12 22:11:33 +00008089
Tyler Gunn65d45c22017-06-05 11:22:26 -07008090 private boolean isUssdApiAllowed(int subId) {
8091 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008092 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008093 if (configManager == null) {
8094 return false;
8095 }
8096 PersistableBundle pb = configManager.getConfigForSubId(subId);
8097 if (pb == null) {
8098 return false;
8099 }
8100 return pb.getBoolean(
8101 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8102 }
8103
Shuo Qiandd210312017-04-12 22:11:33 +00008104 /**
8105 * Check if phone is in emergency callback mode
8106 * @return true if phone is in emergency callback mode
8107 * @param subId sub id
8108 */
goneil9c5f4872017-12-05 14:07:56 -08008109 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008110 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008111 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008112 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
8116 if (phone != null) {
8117 return phone.isInEcm();
8118 } else {
8119 return false;
8120 }
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008123 }
8124 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008125
8126 /**
8127 * Get the current signal strength information for the given subscription.
8128 * Because this information is not updated when the device is in a low power state
8129 * it should not be relied-upon to be current.
8130 * @param subId Subscription index
8131 * @return the most recent cached signal strength info from the modem
8132 */
8133 @Override
8134 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 final long identity = Binder.clearCallingIdentity();
8136 try {
8137 Phone p = getPhone(subId);
8138 if (p == null) {
8139 return null;
8140 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 return p.getSignalStrength();
8143 } finally {
8144 Binder.restoreCallingIdentity(identity);
8145 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008146 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008147
Pengquan Meng77b7f132018-08-22 14:49:57 -07008148 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008149 * Get the current modem radio state for the given slot.
8150 * @param slotIndex slot index.
8151 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008152 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008153 * @return the current radio power state from the modem
8154 */
8155 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008156 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008157 Phone phone = PhoneFactory.getPhone(slotIndex);
8158 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8160 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008161 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8162 }
8163
8164 final long identity = Binder.clearCallingIdentity();
8165 try {
8166 return phone.getRadioPowerState();
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
8169 }
8170 }
8171 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8172 }
8173
8174 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008175 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8176 *
8177 * <p>Requires one of the following permissions:
8178 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8179 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8180 * privileges.
8181 *
8182 * @param subId subscription id
8183 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8184 * {@code false}.
8185 */
8186 @Override
8187 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008188 try {
8189 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8190 null);
8191 } catch (Exception e) {
8192 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8193 mApp, subId, "isDataRoamingEnabled");
8194 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008195
Pengquan Menga1bb6272018-09-06 09:59:22 -07008196 boolean isEnabled = false;
8197 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008198 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008199 Phone phone = getPhone(subId);
8200 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008203 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008204 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008205 }
8206
8207
8208 /**
8209 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8210 *
8211 * <p> Requires permission:
8212 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8213 * privileges.
8214 *
8215 * @param subId subscription id
8216 * @param isEnabled {@code true} means enable, {@code false} means disable.
8217 */
8218 @Override
8219 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8221 mApp, subId, "setDataRoamingEnabled");
8222
Pengquan Menga1bb6272018-09-06 09:59:22 -07008223 final long identity = Binder.clearCallingIdentity();
8224 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008225 Phone phone = getPhone(subId);
8226 if (phone != null) {
8227 phone.setDataRoamingEnabled(isEnabled);
8228 }
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008231 }
8232 }
8233
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008234 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008235 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008236 TelephonyPermissions
8237 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008238 mApp, subId, "isManualNetworkSelectionAllowed");
8239
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008240 boolean isAllowed = true;
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008243 Phone phone = getPhone(subId);
8244 if (phone != null) {
8245 isAllowed = phone.isCspPlmnEnabled();
8246 }
8247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
8250 return isAllowed;
8251 }
8252
8253 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008254 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008255 // Verify that tha callingPackage belongs to the calling UID
8256 mApp.getSystemService(AppOpsManager.class)
8257 .checkPackage(Binder.getCallingUid(), callingPackage);
8258
Jordan Liu1e142fc2019-04-22 15:10:43 -07008259 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008260 try {
8261 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008262 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008263 } catch (SecurityException e) {
8264 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8265 // has carrier privileges on an active UICC
8266 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8267 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008268 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008269 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008270 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008271
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008274 UiccController uiccController = UiccController.getInstance();
8275 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008276 if (hasReadPermission) {
8277 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008278 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008279
8280 // Remove private info if the caller doesn't have access
8281 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8282 for (UiccCardInfo cardInfo : cardInfos) {
8283 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8284 // is available
8285 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8286 if (card == null || card.getUiccProfile() == null) {
8287 // assume no access if the card or profile is unavailable
8288 filteredInfos.add(cardInfo.getUnprivileged());
8289 continue;
8290 }
8291 UiccProfile profile = card.getUiccProfile();
8292 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8293 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8294 filteredInfos.add(cardInfo);
8295 } else {
8296 filteredInfos.add(cardInfo.getUnprivileged());
8297 }
8298 }
8299 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
8303 }
8304
8305 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008306 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008307 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8312 if (slots == null) {
8313 Rlog.i(LOG_TAG, "slots is null.");
8314 return null;
8315 }
8316
8317 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8318 for (int i = 0; i < slots.length; i++) {
8319 UiccSlot slot = slots[i];
8320 if (slot == null) {
8321 continue;
8322 }
8323
Jordan Liu7be7e652019-05-06 18:55:02 +00008324 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 UiccCard card = slot.getUiccCard();
8326 if (card != null) {
8327 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008328 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008329 cardId = slot.getEid();
8330 if (TextUtils.isEmpty(cardId)) {
8331 cardId = slot.getIccId();
8332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 }
8334
Jordan Liu857451f2019-05-09 16:35:35 -07008335 if (cardId != null) {
8336 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8337 // if cardId is an EID, it's all digits so this is fine
8338 cardId = IccUtils.stripTrailingFs(cardId);
8339 }
8340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 int cardState = 0;
8342 switch (slot.getCardState()) {
8343 case CARDSTATE_ABSENT:
8344 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8345 break;
8346 case CARDSTATE_PRESENT:
8347 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8348 break;
8349 case CARDSTATE_ERROR:
8350 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8351 break;
8352 case CARDSTATE_RESTRICTED:
8353 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8354 break;
8355 default:
8356 break;
8357
8358 }
8359
8360 infos[i] = new UiccSlotInfo(
8361 slot.isActive(),
8362 slot.isEuicc(),
8363 cardId,
8364 cardState,
8365 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008366 slot.isExtendedApduSupported(),
8367 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 }
8369 return infos;
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008373 }
8374
8375 @Override
8376 public boolean switchSlots(int[] physicalSlots) {
8377 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378
8379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008385 }
Jack Yu4c988042018-02-27 15:30:01 -08008386
8387 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008388 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 return UiccController.getInstance().getCardIdForDefaultEuicc();
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
8395 }
8396
Pengquan Meng85728fb2018-03-12 16:31:21 -07008397 /**
goneil47ffb6e2018-04-06 15:40:58 -07008398 * A test API to reload the UICC profile.
8399 *
8400 * <p>Requires that the calling app has permission
8401 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8402 * @hide
8403 */
8404 @Override
8405 public void refreshUiccProfile(int subId) {
8406 enforceModifyPermission();
8407
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
8410 Phone phone = getPhone(subId);
8411 if (phone == null) {
8412 return;
8413 }
8414 UiccCard uiccCard = phone.getUiccCard();
8415 if (uiccCard == null) {
8416 return;
8417 }
8418 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8419 if (uiccProfile == null) {
8420 return;
8421 }
8422 uiccProfile.refresh();
8423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
8426 }
8427
8428 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008429 * Returns false if the mobile data is disabled by default, otherwise return true.
8430 */
8431 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008432 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008433 }
8434
8435 /**
8436 * Returns true if the data roaming is enabled by default, i.e the system property
8437 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8438 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8439 */
8440 private boolean getDefaultDataRoamingEnabled(int subId) {
8441 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008442 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008443 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008444 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8445 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8446 return isDataRoamingEnabled;
8447 }
8448
8449 /**
8450 * Returns the default network type for the given {@code subId}, if the default network type is
8451 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8452 */
8453 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008454 List<Integer> list = TelephonyProperties.default_network();
8455 int phoneId = mSubscriptionController.getPhoneId(subId);
8456 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8457 return list.get(phoneId);
8458 }
8459 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008460 }
fionaxua13278b2018-03-21 00:08:13 -07008461
8462 @Override
8463 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008464 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008465 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 final Phone phone = getPhone(subId);
8470 if (phone == null) {
8471 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8472 return;
8473 }
chen xueaba88a2019-03-15 13:15:10 -07008474 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8475 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008476 if (carrierPrivilegeRules == null) {
8477 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8478 } else {
8479 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 } finally {
8482 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008483 }
fionaxua13278b2018-03-21 00:08:13 -07008484 }
8485
8486 @Override
8487 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008488 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 final Phone phone = getPhone(subId);
8493 if (phone == null) {
8494 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8495 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8496 }
8497 return phone.getCarrierIdListVersion();
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008500 }
fionaxua13278b2018-03-21 00:08:13 -07008501 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008502
8503 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008504 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8505 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008507 mApp, subId, callingPackage, callingFeatureId,
8508 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008509 return -1;
8510 }
8511
8512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008519
8520 @Override
8521 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008522 TelephonyPermissions
8523 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008524 mApp, subId, "getCdmaRoamingMode");
8525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
8532 }
8533
8534 @Override
8535 public boolean setCdmaRoamingMode(int subId, int mode) {
8536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8537 mApp, subId, "setCdmaRoamingMode");
8538
8539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
8547 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008548 public int getCdmaSubscriptionMode(int subId) {
8549 TelephonyPermissions
8550 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8551 mApp, subId, "getCdmaSubscriptionMode");
8552
8553 final long identity = Binder.clearCallingIdentity();
8554 try {
8555 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 }
8560
8561 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008562 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8564 mApp, subId, "setCdmaSubscriptionMode");
8565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008573
sqianc5eccab2018-10-19 18:46:41 -07008574 @Override
sqian8c685422019-02-22 15:55:18 -08008575 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008576 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008578 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8579 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008580 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8581 }
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
sqian854d44b2018-12-12 16:48:18 -08008584 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8585 for (Phone phone: PhoneFactory.getPhones()) {
8586 if (phone.getEmergencyNumberTracker() != null
8587 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8588 emergencyNumberListInternal.put(
8589 phone.getSubId(),
8590 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8591 }
sqian11b7a0e2018-12-05 18:48:28 -08008592 }
sqian854d44b2018-12-12 16:48:18 -08008593 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
sqianc5eccab2018-10-19 18:46:41 -07008597 }
8598
8599 @Override
sqian8c685422019-02-22 15:55:18 -08008600 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008601 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008602 if (!exactMatch) {
8603 TelephonyPermissions
8604 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008605 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008606 }
8607 final long identity = Binder.clearCallingIdentity();
8608 try {
sqian854d44b2018-12-12 16:48:18 -08008609 for (Phone phone: PhoneFactory.getPhones()) {
8610 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008611 && phone.getEmergencyNumberTracker()
8612 .isEmergencyNumber(number, exactMatch)) {
8613 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008614 }
sqian11b7a0e2018-12-05 18:48:28 -08008615 }
8616 return false;
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621
sqianf4ca7ed2019-01-15 18:32:07 -08008622 /**
8623 * Update emergency number list for test mode.
8624 */
8625 @Override
8626 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8628 "updateEmergencyNumberListTestMode");
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 for (Phone phone: PhoneFactory.getPhones()) {
8633 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8634 if (tracker != null) {
8635 tracker.executeEmergencyNumberTestModeCommand(action, num);
8636 }
8637 }
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
8643 /**
8644 * Get the full emergency number list for test mode.
8645 */
8646 @Override
8647 public List<String> getEmergencyNumberListTestMode() {
8648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8649 "getEmergencyNumberListTestMode");
8650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 Set<String> emergencyNumbers = new HashSet<>();
8654 for (Phone phone: PhoneFactory.getPhones()) {
8655 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8656 if (tracker != null) {
8657 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8658 emergencyNumbers.add(num.getNumber());
8659 }
8660 }
8661 }
8662 return new ArrayList<>(emergencyNumbers);
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
8665 }
8666 }
8667
chen xud6b45bd2018-10-30 22:27:10 -07008668 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008669 public int getEmergencyNumberDbVersion(int subId) {
8670 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8671
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 final Phone phone = getPhone(subId);
8675 if (phone == null) {
8676 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8677 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8678 }
8679 return phone.getEmergencyNumberDbVersion();
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 @Override
8686 public void notifyOtaEmergencyNumberDbInstalled() {
8687 enforceModifyPermission();
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 for (Phone phone: PhoneFactory.getPhones()) {
8692 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8693 if (tracker != null) {
8694 tracker.updateOtaEmergencyNumberDatabase();
8695 }
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
8701
8702 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008703 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008704 enforceActiveEmergencySessionPermission();
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 for (Phone phone: PhoneFactory.getPhones()) {
8709 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8710 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008711 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8712 }
8713 }
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
8719 @Override
8720 public void resetOtaEmergencyNumberDbFilePath() {
8721 enforceActiveEmergencySessionPermission();
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 for (Phone phone: PhoneFactory.getPhones()) {
8726 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8727 if (tracker != null) {
8728 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008729 }
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
8736 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008737 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8738 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8739 Phone phone = getPhone(subId);
8740 if (phone == null) {
8741 return null;
8742 }
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 UiccProfile profile = UiccController.getInstance()
8746 .getUiccProfileForPhone(phone.getPhoneId());
8747 if (profile != null) {
8748 return profile.getCertsFromCarrierPrivilegeAccessRules();
8749 }
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 return null;
8754 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008755
8756 /**
8757 * Enable or disable a modem stack.
8758 */
8759 @Override
8760 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8761 enforceModifyPermission();
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 Phone phone = PhoneFactory.getPhone(slotIndex);
8766 if (phone == null) {
8767 return false;
8768 } else {
8769 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
Michelecea4cf22018-12-21 15:00:11 -08008775
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008776 /**
8777 * Whether a modem stack is enabled or not.
8778 */
8779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008780 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8781 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008782 Phone phone = PhoneFactory.getPhone(slotIndex);
8783 if (phone == null) return false;
8784
8785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008786 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8787 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008788 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8789 }
8790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008793 try {
8794 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8795 } catch (NoSuchElementException ex) {
8796 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8797 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008798 } finally {
8799 Binder.restoreCallingIdentity(identity);
8800 }
8801 }
8802
Michelecea4cf22018-12-21 15:00:11 -08008803 @Override
Michele0ea7d782019-03-19 14:58:42 -07008804 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008805 enforceModifyPermission();
8806
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008810 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008811 .commit();
8812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
8817 @Override
Michele0ea7d782019-03-19 14:58:42 -07008818 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008819 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008821 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8822 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008823 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008824 }
Michelecea4cf22018-12-21 15:00:11 -08008825
8826 final long identity = Binder.clearCallingIdentity();
8827 try {
Michele0ea7d782019-03-19 14:58:42 -07008828 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008833
Michele0ea7d782019-03-19 14:58:42 -07008834 @TelephonyManager.IsMultiSimSupportedResult
8835 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008836 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8837 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8838 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008839 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8840 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008841 }
8842 // Check if the hardware supports multisim functionality. If usage of multisim is not
8843 // supported by the modem, indicate that it is restricted.
8844 PhoneCapability staticCapability =
8845 mPhoneConfigurationManager.getStaticPhoneCapability();
8846 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008847 loge("isMultiSimSupportedInternal: no static configuration available");
8848 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008849 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008850 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008851 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8852 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008853 }
8854 // Check if support of multiple SIMs is restricted by carrier
8855 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008856 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008857 }
8858
Michele0ea7d782019-03-19 14:58:42 -07008859 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008860 }
8861
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008862 /**
8863 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008864 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8865 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8866 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008867 * @param numOfSims number of active sims we want to switch to
8868 */
8869 @Override
8870 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008871 if (numOfSims == 1) {
8872 enforceModifyPermission();
8873 } else {
8874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8875 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8876 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008877 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008878
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008879 try {
Michele30b57b22019-03-01 12:01:14 -08008880 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008881 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008882 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8883 return;
8884 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008885 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
8888 }
8889 }
8890
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008891 @Override
8892 public boolean isApplicationOnUicc(int subId, int appType) {
8893 enforceReadPrivilegedPermission("isApplicationOnUicc");
8894 Phone phone = getPhone(subId);
8895 if (phone == null) {
8896 return false;
8897 }
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 UiccCard uiccCard = phone.getUiccCard();
8901 if (uiccCard == null) {
8902 return false;
8903 }
8904 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8905 if (uiccProfile == null) {
8906 return false;
8907 }
8908 if (TelephonyManager.APPTYPE_SIM <= appType
8909 && appType <= TelephonyManager.APPTYPE_ISIM) {
8910 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8911 }
8912 return false;
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008918 /**
chen xub4baa772019-04-03 10:23:41 -07008919 * Get whether making changes to modem configurations will trigger reboot.
8920 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008921 */
8922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008923 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8924 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008926 mApp, subId, callingPackage, callingFeatureId,
8927 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008928 return false;
8929 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
8936 }
8937
Nathan Harold29f5f052019-02-15 13:41:57 -08008938 private void updateModemStateMetrics() {
8939 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8940 // TODO: check the state for each modem if the api is ready.
8941 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8942 }
8943
Pengquan Meng3889a572019-01-23 11:16:29 -08008944 @Override
8945 public int[] getSlotsMapping() {
8946 enforceReadPrivilegedPermission("getSlotsMapping");
8947
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8951 // All logical slots should have a mapping to a physical slot.
8952 int[] logicalSlotsMapping = new int[phoneCount];
8953 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8954 for (int i = 0; i < slotInfos.length; i++) {
8955 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8956 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8957 }
8958 }
8959 return logicalSlotsMapping;
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
8963 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008964
8965 /**
8966 * Get the IRadio HAL Version
8967 */
8968 @Override
8969 public int getRadioHalVersion() {
8970 Phone phone = getDefaultPhone();
8971 if (phone == null) return -1;
8972 HalVersion hv = phone.getHalVersion();
8973 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8974 return hv.major * 100 + hv.minor;
8975 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008976
8977 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008978 * Get the current calling package name.
8979 * @return the current calling package name
8980 */
8981 @Override
8982 public String getCurrentPackageName() {
8983 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8984 }
8985
8986 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008987 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8988 * corresponding network requests on a subId.
8989 *
8990 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008991 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008992 * 2) APN is un-metered for this subscription, or
8993 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008994 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008995 *
8996 * @return whether data is allowed for a apn type.
8997 *
8998 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008999 */
9000 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009001 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009002 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9003 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009004
9005 // Now that all security checks passes, perform the operation as ourselves.
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subId);
9009 if (phone == null) return false;
9010
Jack Yu41407ee2019-05-13 16:54:09 -07009011 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009012 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
9018 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009019 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009020 enforceReadPrivilegedPermission("isApnMetered");
9021
9022 // Now that all security checks passes, perform the operation as ourselves.
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 Phone phone = getPhone(subId);
9026 if (phone == null) return true; // By default return true.
9027
Jack Yu41407ee2019-05-13 16:54:09 -07009028 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009029 } finally {
9030 Binder.restoreCallingIdentity(identity);
9031 }
9032 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009033
9034 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009035 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9036 int subscriptionId, IBooleanConsumer resultCallback) {
9037 enforceModifyPermission();
9038 long token = Binder.clearCallingIdentity();
9039 try {
9040 Phone phone = getPhone(subscriptionId);
9041 if (phone == null) {
9042 try {
9043 if (resultCallback != null) {
9044 resultCallback.accept(false);
9045 }
9046 } catch (RemoteException e) {
9047 // ignore
9048 }
9049 return;
9050 }
9051 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9052 Pair.create(specifiers, (x) -> {
9053 try {
9054 if (resultCallback != null) {
9055 resultCallback.accept(x);
9056 }
9057 } catch (RemoteException e) {
9058 // ignore
9059 }
9060 });
9061 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9062 } finally {
9063 Binder.restoreCallingIdentity(token);
9064 }
9065 }
9066
9067 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009068 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9069 TelephonyPermissions
9070 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9071 mApp, subId, "getSystemSelectionChannels");
9072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 List<RadioAccessSpecifier> specifiers =
9076 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9077 null, subId, workSource);
9078 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9079 return specifiers;
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009086 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009087 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009088 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9089 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9090 if (iccRecords == null) {
9091 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9092 return false;
9093 }
9094 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9095 }
9096
9097 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009098 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9099 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009100 if (callingPackage == null) {
9101 callingPackage = getCurrentPackageName();
9102 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009103 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9104 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009105 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9106 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009107 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9108 }
9109 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9110 Intent intent = new Intent();
9111 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9112 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9113 // Bring up choose default SMS subscription dialog right now
9114 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9115 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9116 mApp.startActivity(intent);
9117 }
chen xud5ca2d52019-05-28 15:20:57 -07009118
9119 @Override
9120 public String getMmsUAProfUrl(int subId) {
9121 //TODO investigate if this API should require proper permission check in R b/133791609
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009124 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9125 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9126 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9127 return carrierUAProfUrl;
9128 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009129 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9130 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
9134 }
9135
9136 @Override
9137 public String getMmsUserAgent(int subId) {
9138 //TODO investigate if this API should require proper permission check in R b/133791609
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009141 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9142 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9143 if (!TextUtils.isEmpty(carrierUserAgent)) {
9144 return carrierUserAgent;
9145 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009146 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9147 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
Jack Yub07d4972019-05-28 16:12:25 -07009152
9153 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009154 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9155 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009156
Jack Yub07d4972019-05-28 16:12:25 -07009157 final long identity = Binder.clearCallingIdentity();
9158 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009159 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009160 if (phone == null) return false;
9161
Hall Liua62f5da2020-09-25 10:42:19 -07009162 switch (policy) {
9163 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9164 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9165 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9166 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9167 default:
9168 throw new IllegalArgumentException(policy + " is not a valid policy");
9169 }
Jack Yub07d4972019-05-28 16:12:25 -07009170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009176 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9177 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009178 enforceModifyPermission();
9179
changbettyd5c246e2019-12-24 15:40:37 +08009180 final long identity = Binder.clearCallingIdentity();
9181 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009182 Phone phone = getPhone(subscriptionId);
9183 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009184
Hall Liua62f5da2020-09-25 10:42:19 -07009185 switch (policy) {
9186 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9187 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9188 break;
9189 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9190 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9191 break;
9192 default:
9193 throw new IllegalArgumentException(policy + " is not a valid policy");
9194 }
changbettyd5c246e2019-12-24 15:40:37 +08009195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009200 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009201 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009202 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9203 * otherwise.
9204 */
9205 @Override
9206 public void setCepEnabled(boolean isCepEnabled) {
9207 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9208
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9212 for (Phone phone : PhoneFactory.getPhones()) {
9213 Phone defaultPhone = phone.getImsPhone();
9214 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9215 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9216 ImsPhoneCallTracker imsPhoneCallTracker =
9217 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9218 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9219 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9220 + imsPhone.getMsisdn());
9221 }
9222 }
9223 } finally {
9224 Binder.restoreCallingIdentity(identity);
9225 }
9226 }
allenwtsu46dcc572020-01-08 18:24:03 +08009227
9228 /**
9229 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9230 *
9231 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9232 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9233 * before being read.
9234 */
9235 @Override
9236 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9237 isCompressed) {
9238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9239 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009240 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9241 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9242 }
9243 if (!isImsAvailableOnDevice()) {
9244 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9245 "IMS not available on device.");
9246 }
9247
9248 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009249 try {
Hui Wang761a6682020-10-31 05:12:53 +00009250 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009253 }
9254 }
zoey chene02881a2019-12-30 16:11:23 +08009255
9256 @Override
9257 public boolean isIccLockEnabled(int subId) {
9258 enforceReadPrivilegedPermission("isIccLockEnabled");
9259
9260 // Now that all security checks passes, perform the operation as ourselves.
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 Phone phone = getPhone(subId);
9264 if (phone != null && phone.getIccCard() != null) {
9265 return phone.getIccCard().getIccLockEnabled();
9266 } else {
9267 return false;
9268 }
9269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
9274 /**
9275 * Set the ICC pin lock enabled or disabled.
9276 *
9277 * @return an integer representing the status of IccLock enabled or disabled in the following
9278 * three cases:
9279 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9280 * successfully.
9281 * - Positive number and zero for remaining password attempts.
9282 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9283 *
9284 */
9285 @Override
9286 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9287 enforceModifyPermission();
9288
9289 Phone phone = getPhone(subId);
9290 if (phone == null) {
9291 return 0;
9292 }
9293 // Now that all security checks passes, perform the operation as ourselves.
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9297 new Pair<Boolean, String>(enabled, password), phone, null);
9298 return attemptsRemaining;
9299
9300 } catch (Exception e) {
9301 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 return 0;
9306 }
9307
9308 /**
9309 * Change the ICC password used in ICC pin lock.
9310 *
9311 * @return an integer representing the status of IccLock changed in the following three cases:
9312 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9313 * - Positive number and zero for remaining password attempts.
9314 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9315 *
9316 */
9317 @Override
9318 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9319 enforceModifyPermission();
9320
9321 Phone phone = getPhone(subId);
9322 if (phone == null) {
9323 return 0;
9324 }
9325 // Now that all security checks passes, perform the operation as ourselves.
9326 final long identity = Binder.clearCallingIdentity();
9327 try {
9328 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9329 new Pair<String, String>(oldPassword, newPassword), phone, null);
9330 return attemptsRemaining;
9331
9332 } catch (Exception e) {
9333 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 return 0;
9338 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009339
9340 /**
9341 * Request for receiving user activity notification
9342 */
9343 @Override
9344 public void requestUserActivityNotification() {
9345 if (!mNotifyUserActivity.get()
9346 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9347 mNotifyUserActivity.set(true);
9348 }
9349 }
9350
9351 /**
9352 * Called when userActivity is signalled in the power manager.
9353 * This is safe to call from any thread, with any window manager locks held or not.
9354 */
9355 @Override
9356 public void userActivity() {
9357 // ***************************************
9358 // * Inherited from PhoneWindowManager *
9359 // ***************************************
9360 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9361 // WITH ITS LOCKS HELD.
9362 //
9363 // This code must be VERY careful about the locks
9364 // it acquires.
9365 // In fact, the current code acquires way too many,
9366 // and probably has lurking deadlocks.
9367
9368 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9369 throw new SecurityException("Only the OS may call notifyUserActivity()");
9370 }
9371
9372 if (mNotifyUserActivity.getAndSet(false)) {
9373 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9374 USER_ACTIVITY_NOTIFICATION_DELAY);
9375 }
9376 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009377
9378 @Override
9379 public boolean canConnectTo5GInDsdsMode() {
9380 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9381 }
Jack Yud10cdd42020-09-28 20:28:01 -07009382
9383 @Override
9384 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9385 String callingFeatureId) {
9386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9387 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9388 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9389 }
9390
9391 Phone phone = getPhone(subId);
9392 if (phone == null) {
9393 throw new RuntimeException("phone is not available");
9394 }
9395 // Now that all security checks passes, perform the operation as ourselves.
9396 final long identity = Binder.clearCallingIdentity();
9397 try {
9398 return phone.getEquivalentHomePlmns();
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
Daniel Bright59e67312020-11-13 11:49:37 -08009403
9404 @Override
9405 public boolean isRadioInterfaceCapabilitySupported(
9406 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9407 RadioInterfaceCapabilities radioInterfaceCapabilities =
9408 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9409 if (radioInterfaceCapabilities == null) {
9410 throw new RuntimeException("radio interface capabilities are not available");
9411 } else {
9412 return radioInterfaceCapabilities.isSupported(capability);
9413 }
9414 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009415
Hui Wang641e81c2020-10-12 12:14:23 -07009416 @Override
9417 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9418 UaSecurityProtocolIdentifier securityProtocol,
9419 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9420 throws RemoteException {
9421 enforceModifyPermission();
9422 if (DBG) {
9423 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9424 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9425 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9426 }
9427
9428 if (!SubscriptionManager.isValidSubscriptionId(subId)
9429 || appType < TelephonyManager.APPTYPE_UNKNOWN
9430 || appType > TelephonyManager.APPTYPE_ISIM
9431 || nafUrl == null || securityProtocol == null || callback == null) {
9432 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9433 if (callback != null) {
9434 try {
9435 callback.onAuthenticationFailure(
9436 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9437 } catch (RemoteException exception) {
9438 log("Fail to notify onAuthenticationFailure due to " + exception);
9439 }
9440 return;
9441 }
9442 }
9443
9444 final long token = Binder.clearCallingIdentity();
9445 try {
9446 getGbaManager(subId).bootstrapAuthenticationRequest(
9447 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9448 forceBootStrapping, callback));
9449 } finally {
9450 Binder.restoreCallingIdentity(token);
9451 }
9452 }
9453
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009454 /**
9455 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9456 * requested radio power state will actually be set. See {@link
9457 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9458 *
9459 * @param subId the subscription ID of the phone requesting to set the radio power state.
9460 * @param enable {@code true} if trying to turn radio on.
9461 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9462 * false}.
9463 */
9464 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9465 Phone phone = getPhone(subId);
9466 if (phone != null) {
9467 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9468 return true;
9469 }
9470 return false;
9471 }
9472
9473 private int handleDataThrottlingRequest(int subId,
9474 DataThrottlingRequest dataThrottlingRequest) {
9475 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9476 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9477 if (!setRadioPowerForThermal(subId, true)) {
9478 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9479 }
9480
9481 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9482
9483 int thermalMitigationResult =
9484 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9485 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9486 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9487 }
9488 return thermalMitigationResult;
9489 }
9490
9491 /**
9492 * Thermal mitigation request to control functionalities at modem.
9493 *
9494 * @param subId the id of the subscription.
9495 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9496 *
9497 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9498 */
9499 @Override
9500 @ThermalMitigationResult
9501 public int sendThermalMitigationRequest(
9502 int subId,
9503 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9504 enforceModifyPermission();
9505
9506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9507 final long identity = Binder.clearCallingIdentity();
9508
9509 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9510 try {
9511 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9512 switch (thermalMitigationAction) {
9513 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9514 thermalMitigationResult =
9515 handleDataThrottlingRequest(subId,
9516 thermalMitigationRequest.getDataThrottlingRequest());
9517 break;
9518 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9519 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9520 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9521 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9522 }
9523
9524 // Ensure that radio is on. If not able to power on due to phone being
9525 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9526 if (!setRadioPowerForThermal(subId, true)) {
9527 thermalMitigationResult =
9528 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9529 break;
9530 }
9531
9532 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9533 false);
9534 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9535 break;
9536 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9537 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9538 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9539 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9540 }
9541
9542 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9543 if (registry != null) {
9544 TelephonyConnectionService service =
9545 registry.getTelephonyConnectionService();
9546 Phone phone = getPhone(subId);
9547 if (phone == null) {
9548 thermalMitigationResult =
9549 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9550 break;
9551 }
9552
9553 if (PhoneConstantConversions.convertCallState(phone.getState())
9554 != TelephonyManager.CALL_STATE_IDLE
9555 || phone.isInEmergencySmsMode() || phone.isInEcm()
9556 || (service != null && service.isEmergencyCallPending())) {
9557 String errorMessage = "Phone state is not valid. call state = "
9558 + PhoneConstantConversions.convertCallState(phone.getState())
9559 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9560 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9561 errorMessage += service == null
9562 ? " TelephonyConnectionService is null"
9563 : " isEmergencyCallPending = "
9564 + service.isEmergencyCallPending();
9565 Log.e(LOG_TAG, errorMessage);
9566 thermalMitigationResult =
9567 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9568 break;
9569 }
9570 } else {
9571 thermalMitigationResult =
9572 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9573 break;
9574 }
9575
9576 // Turn radio off. If not able to power off due to phone being unavailable,
9577 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9578 if (!setRadioPowerForThermal(subId, false)) {
9579 thermalMitigationResult =
9580 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9581 break;
9582 }
9583 thermalMitigationResult =
9584 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9585 break;
9586 default:
9587 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9588 + "not exist. Requested action: " + thermalMitigationAction);
9589 }
9590 } catch (IllegalArgumentException e) {
9591 throw e;
9592 } catch (Exception e) {
9593 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9594 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
9597 }
9598
9599 if (DBG) {
9600 log("thermalMitigationRequest returning with thermalMitigationResult: "
9601 + thermalMitigationResult);
9602 }
9603
9604 return thermalMitigationResult;
9605 }
Hui Wang641e81c2020-10-12 12:14:23 -07009606
9607 /**
9608 * Set the GbaService Package Name that Telephony will bind to.
9609 *
9610 * @param subId The sim that the GbaService is associated with.
9611 * @param packageName The name of the package to be replaced with.
9612 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9613 */
9614 @Override
9615 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9616 enforceModifyPermission();
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 return getGbaManager(subId).overrideServicePackage(packageName);
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
9626 /**
9627 * Return the package name of the currently bound GbaService.
9628 *
9629 * @param subId The sim that the GbaService is associated with.
9630 * @return the package name of the GbaService configuration, null if GBA is not supported.
9631 */
9632 @Override
9633 public String getBoundGbaService(int subId) {
9634 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9635
9636 final long identity = Binder.clearCallingIdentity();
9637 try {
9638 return getGbaManager(subId).getServicePackage();
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
9644 /**
9645 * Set the release time for telephony to unbind GbaService.
9646 *
9647 * @param subId The sim that the GbaService is associated with.
9648 * @param interval The release time to unbind GbaService by millisecond.
9649 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9650 */
9651 @Override
9652 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9653 enforceModifyPermission();
9654
9655 final long identity = Binder.clearCallingIdentity();
9656 try {
9657 return getGbaManager(subId).overrideReleaseTime(interval);
9658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
9662
9663 /**
9664 * Return the release time for telephony to unbind GbaService.
9665 *
9666 * @param subId The sim that the GbaService is associated with.
9667 * @return The release time to unbind GbaService by millisecond.
9668 */
9669 @Override
9670 public int getGbaReleaseTime(int subId) {
9671 enforceReadPrivilegedPermission("getGbaReleaseTime");
9672
9673 final long identity = Binder.clearCallingIdentity();
9674 try {
9675 return getGbaManager(subId).getReleaseTime();
9676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680
9681 private GbaManager getGbaManager(int subId) {
9682 GbaManager instance = GbaManager.getInstance(subId);
9683 if (instance == null) {
9684 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9685 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9686 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9687 }
9688 return instance;
9689 }
Hui Wang761a6682020-10-31 05:12:53 +00009690
9691 /**
9692 * indicate whether the device and the carrier can support
9693 * RCS VoLTE single registration.
9694 */
9695 @Override
9696 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9697 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9698
9699 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9700 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9701 }
9702
9703 final long identity = Binder.clearCallingIdentity();
9704 try {
9705 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9706 if (rpm != null) {
9707 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9708 }
9709 return false;
9710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
9714
9715 /**
9716 * Register RCS provisioning callback.
9717 */
9718 @Override
9719 public void registerRcsProvisioningChangedCallback(int subId,
9720 IRcsConfigCallback callback) {
9721 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9722
9723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9725 }
9726 if (!isImsAvailableOnDevice()) {
9727 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9728 "IMS not available on device.");
9729 }
9730
9731 final long identity = Binder.clearCallingIdentity();
9732 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009733 if (!RcsProvisioningMonitor.getInstance()
9734 .registerRcsProvisioningChangedCallback(subId, callback)) {
9735 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9736 "Service not available for the subscription.");
9737 }
Hui Wang761a6682020-10-31 05:12:53 +00009738 } finally {
9739 Binder.restoreCallingIdentity(identity);
9740 }
9741 }
9742
9743 /**
9744 * Unregister RCS provisioning callback.
9745 */
9746 @Override
9747 public void unregisterRcsProvisioningChangedCallback(int subId,
9748 IRcsConfigCallback callback) {
9749 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9750
9751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9753 }
9754 if (!isImsAvailableOnDevice()) {
9755 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9756 "IMS not available on device.");
9757 }
9758
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009761 RcsProvisioningMonitor.getInstance()
9762 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767
9768 /**
9769 * trigger RCS reconfiguration.
9770 */
9771 public void triggerRcsReconfiguration(int subId) {
9772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9773 mApp, subId, "triggerRcsReconfiguration");
9774
9775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9777 }
9778 if (!isImsAvailableOnDevice()) {
9779 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9780 "IMS not available on device.");
9781 }
9782
9783 final long identity = Binder.clearCallingIdentity();
9784 try {
9785 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9786 } finally {
9787 Binder.restoreCallingIdentity(identity);
9788 }
9789 }
9790
9791 /**
9792 * Provide the client configuration parameters of the RCS application.
9793 */
9794 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9796 mApp, subId, "setRcsClientConfiguration");
9797
9798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9799 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9800 }
9801 if (!isImsAvailableOnDevice()) {
9802 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9803 "IMS not available on device.");
9804 }
9805
9806 final long identity = Binder.clearCallingIdentity();
9807
9808 try {
9809 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9810 if (configBinder == null) {
9811 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9812 } else {
9813 configBinder.setRcsClientConfiguration(rcc);
9814 }
9815 } catch (RemoteException e) {
9816 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9817 } finally {
9818 Binder.restoreCallingIdentity(identity);
9819 }
9820 }
9821
9822 /**
9823 * Overrides the config of RCS VoLTE single registration enabled for the device.
9824 */
9825 @Override
9826 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9828 "setDeviceSingleRegistrationEnabledOverride");
9829 enforceModifyPermission();
9830
9831 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9832 : Boolean.parseBoolean(enabledStr);
9833 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9834 }
9835
9836 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009837 * Sends a device to device communication message. Only usable via shell.
9838 * @param message message to send.
9839 * @param value message value.
9840 */
9841 @Override
9842 public void sendDeviceToDeviceMessage(int message, int value) {
9843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9844 "setCarrierSingleRegistrationEnabledOverride");
9845 enforceModifyPermission();
9846
9847 final long identity = Binder.clearCallingIdentity();
9848 try {
9849 TelephonyConnectionService service =
9850 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9851 if (service == null) {
9852 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9853 return;
9854 }
9855 service.sendTestDeviceToDeviceMessage(message, value);
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
9860
9861
9862 /**
Hui Wang761a6682020-10-31 05:12:53 +00009863 * Gets the config of RCS VoLTE single registration enabled for the device.
9864 */
9865 @Override
9866 public boolean getDeviceSingleRegistrationEnabled() {
9867 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9868 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9869 }
9870
9871 /**
9872 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9873 */
9874 @Override
9875 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9877 "setCarrierSingleRegistrationEnabledOverride");
9878 enforceModifyPermission();
9879
9880 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9881 : Boolean.parseBoolean(enabledStr);
9882 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9883 subId, enabled);
9884 }
9885
9886 /**
9887 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9888 */
9889 @Override
9890 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9891 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9892 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9893 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009894
9895 /**
9896 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9897 * their mobile plan.
9898 */
9899 @Override
9900 public String getMobileProvisioningUrl() {
9901 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9902 final long identity = Binder.clearCallingIdentity();
9903 try {
9904 return getDefaultPhone().getMobileProvisioningUrl();
9905 } finally {
9906 Binder.restoreCallingIdentity(identity);
9907 }
9908 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009909
9910 @Override
9911 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9912 String callingPackage) {
9913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9914 mApp, subId, "setSignalStrengthUpdateRequest");
9915
9916 final int callingUid = Binder.getCallingUid();
9917 // Verify that tha callingPackage belongs to the calling UID
9918 mApp.getSystemService(AppOpsManager.class)
9919 .checkPackage(callingUid, callingPackage);
9920
9921 validateSignalStrengthUpdateRequest(request, callingUid);
9922
9923 final long identity = Binder.clearCallingIdentity();
9924 try {
9925 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9926 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9927
9928 if (result instanceof IllegalStateException) {
9929 throw (IllegalStateException) result;
9930 }
9931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934 }
9935
9936 @Override
9937 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9938 String callingPackage) {
9939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9940 mApp, subId, "clearSignalStrengthUpdateRequest");
9941
9942 final int callingUid = Binder.getCallingUid();
9943 // Verify that tha callingPackage belongs to the calling UID
9944 mApp.getSystemService(AppOpsManager.class)
9945 .checkPackage(callingUid, callingPackage);
9946
9947 final long identity = Binder.clearCallingIdentity();
9948 try {
9949 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9950 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9951
9952 if (result instanceof IllegalStateException) {
9953 throw (IllegalStateException) result;
9954 }
9955 } finally {
9956 Binder.restoreCallingIdentity(identity);
9957 }
9958 }
9959
9960 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9961 int callingUid) {
9962 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9963 // phone/system process do not have further restriction on request
9964 return;
9965 }
9966
9967 // Applications has restrictions on how to use the request:
9968 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9969 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9970 // This is not system caller which has been checked above
9971 throw new IllegalArgumentException(
9972 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9973 }
9974
9975 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9976 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9977 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9978 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9979 || info.isEnabled()) {
9980 throw new IllegalArgumentException(
9981 "Only system can set hide fields in SignalThresholdInfo");
9982 }
9983
9984 // Thresholds length for each RAN need in range. This has been validated in
9985 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9986 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9987 final int[] thresholds = info.getThresholds();
9988 Objects.requireNonNull(thresholds);
9989 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9990 || thresholds.length
9991 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9992 throw new IllegalArgumentException(
9993 "thresholds length is out of range: " + thresholds.length);
9994 }
9995 }
9996 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009997
9998 /**
9999 * Gets the current phone capability.
10000 *
10001 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10002 * @return the PhoneCapability which describes the data connection capability of modem.
10003 * It's used to evaluate possible phone config change, for example from single
10004 * SIM device to multi-SIM device.
10005 */
10006 @Override
10007 public PhoneCapability getPhoneCapability() {
10008 enforceReadPrivilegedPermission("getPhoneCapability");
10009 final long identity = Binder.clearCallingIdentity();
10010 try {
10011 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10012 } finally {
10013 Binder.restoreCallingIdentity(identity);
10014 }
10015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010016}