blob: b790e39b2ee7ffb1806322f2cf8fe5976148cc00 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700113import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700116import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800117import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000119import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700120import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800122import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800124import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700127import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800129import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Andrew Lee312e8172014-10-23 17:01:36 -0700131import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800132import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800133import com.android.ims.rcs.uce.eab.EabUtil;
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;
Michele Berionne5e411512020-11-13 02:36:59 +0000330 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800332 // Parameters of select command.
333 private static final int SELECT_COMMAND = 0xA4;
334 private static final int SELECT_P1 = 0x04;
335 private static final int SELECT_P2 = 0;
336 private static final int SELECT_P3 = 0x10;
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 /** The singleton instance. */
339 private static PhoneInterfaceManager sInstance;
340
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800343 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700344 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800345 private AppOpsManager mAppOps;
346 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800347 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800348 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700349 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 /** User Activity */
352 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
354
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700355 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
356
Derek Tan97ebb422014-09-05 16:55:38 -0700357 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
358 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800359 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800360 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700361
Michelecea4cf22018-12-21 15:00:11 -0800362 // String to store multi SIM allowed
363 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
364
Derek Tan740e1672017-06-27 14:56:27 -0700365 // The AID of ISD-R.
366 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
367
yinxub1bed742017-04-17 11:45:04 -0700368 private NetworkScanRequestTracker mNetworkScanRequestTracker;
369
David Kelly5e06a7f2018-03-12 14:10:59 +0000370 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
371 private static final int MANUFACTURER_CODE_LENGTH = 8;
372
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800373 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
374
Derek Tan89e89d42014-07-08 17:00:10 -0700375 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700376 * Experiment flag to enable erase modem config on reset network, default value is false
377 */
378 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
379 "reset_network_erase_modem_config_enabled";
380
381 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700382 * A request object to use for transmitting data to an ICC.
383 */
384 private static final class IccAPDUArgument {
385 public int channel, cla, command, p1, p2, p3;
386 public String data;
387
388 public IccAPDUArgument(int channel, int cla, int command,
389 int p1, int p2, int p3, String data) {
390 this.channel = channel;
391 this.cla = cla;
392 this.command = command;
393 this.p1 = p1;
394 this.p2 = p2;
395 this.p3 = p3;
396 this.data = data;
397 }
398 }
399
400 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class ManualNetworkSelectionArgument {
404 public OperatorInfo operatorInfo;
405 public boolean persistSelection;
406
407 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
408 this.operatorInfo = operatorInfo;
409 this.persistSelection = persistSelection;
410 }
411 }
412
413 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
415 * request after sending. The main thread will notify the request when it is complete.
416 */
417 private static final class MainThreadRequest {
418 /** The argument to use for the request */
419 public Object argument;
420 /** The result of the request that is run on the main thread */
421 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800422 // The subscriber id that this request applies to. Defaults to
423 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
424 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425
Nathan Harold92bed182018-10-12 18:16:49 -0700426 // In cases where subId is unavailable, the caller needs to specify the phone.
427 public Phone phone;
428
vagdeviaf9a5b92018-08-15 16:01:53 -0700429 public WorkSource workSource;
430
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 public MainThreadRequest(Object argument) {
432 this.argument = argument;
433 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800434
Nathan Harold92bed182018-10-12 18:16:49 -0700435 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
436 this.argument = argument;
437 if (phone != null) {
438 this.phone = phone;
439 }
440 this.workSource = workSource;
441 }
442
vagdeviaf9a5b92018-08-15 16:01:53 -0700443 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 if (subId != null) {
446 this.subId = subId;
447 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 }
451
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800452 private static final class IncomingThirdPartyCallArgs {
453 public final ComponentName component;
454 public final String callId;
455 public final String callerDisplayName;
456
457 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
458 String callerDisplayName) {
459 this.component = component;
460 this.callId = callId;
461 this.callerDisplayName = callerDisplayName;
462 }
463 }
464
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 /**
466 * A handler that processes messages on the main thread in the phone process. Since many
467 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
468 * inbound binder threads to the main thread in the phone process. The Binder thread
469 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
470 * on, which will be notified when the operation completes and will contain the result of the
471 * request.
472 *
473 * <p>If a MainThreadRequest object is provided in the msg.obj field,
474 * note that request.result must be set to something non-null for the calling thread to
475 * unblock.
476 */
477 private final class MainThreadHandler extends Handler {
478 @Override
479 public void handleMessage(Message msg) {
480 MainThreadRequest request;
481 Message onCompleted;
482 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800485 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
487 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 case CMD_HANDLE_USSD_REQUEST: {
489 request = (MainThreadRequest) msg.obj;
490 final Phone phone = getPhoneFromRequest(request);
491 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
492 String ussdRequest = ussdObject.first;
493 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700494
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 if (!isUssdApiAllowed(request.subId)) {
496 // Carrier does not support use of this API, return failure.
497 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
498 UssdResponse response = new UssdResponse(ussdRequest, null);
499 Bundle returnData = new Bundle();
500 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
501 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700502
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 request.result = true;
504 notifyRequester(request);
505 return;
506 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700507
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 try {
509 request.result = phone != null
510 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
511 } catch (CallStateException cse) {
512 request.result = false;
513 }
514 // Wake up the requesting thread
515 notifyRequester(request);
516 break;
pkanwar32d516d2016-10-14 19:37:38 -0700517 }
518
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700521 final Phone phone = getPhoneFromRequest(request);
522 request.result = phone != null ?
523 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
524 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800533 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 if (uiccCard == null) {
535 loge("iccTransmitApduLogicalChannel: No UICC");
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
540 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 iccArgument.channel, iccArgument.cla, iccArgument.command,
543 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 break;
547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
555 if (ar.result == null) {
556 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800557 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800559 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 } else {
561 loge("iccTransmitApduLogicalChannel: Unknown exception");
562 }
563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
568 request = (MainThreadRequest) msg.obj;
569 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800570 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 if (uiccCard == null) {
572 loge("iccTransmitApduBasicChannel: No UICC");
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 } else {
576 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
577 request);
578 uiccCard.iccTransmitApduBasicChannel(
579 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
580 iccArgument.p3, iccArgument.data, onCompleted);
581 }
582 break;
583
584 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
587 if (ar.exception == null && ar.result != null) {
588 request.result = ar.result;
589 } else {
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
591 if (ar.result == null) {
592 loge("iccTransmitApduBasicChannel: Empty response");
593 } else if (ar.exception instanceof CommandException) {
594 loge("iccTransmitApduBasicChannel: CommandException: " +
595 ar.exception);
596 } else {
597 loge("iccTransmitApduBasicChannel: Unknown exception");
598 }
599 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 break;
602
603 case CMD_EXCHANGE_SIM_IO:
604 request = (MainThreadRequest) msg.obj;
605 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800606 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 if (uiccCard == null) {
608 loge("iccExchangeSimIO: No UICC");
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 } else {
612 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
613 request);
614 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
615 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
616 iccArgument.data, onCompleted);
617 }
618 break;
619
620 case EVENT_EXCHANGE_SIM_IO_DONE:
621 ar = (AsyncResult) msg.obj;
622 request = (MainThreadRequest) ar.userObj;
623 if (ar.exception == null && ar.result != null) {
624 request.result = ar.result;
625 } else {
626 request.result = new IccIoResult(0x6f, 0, (byte[])null);
627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 break;
630
Derek Tan4d5e5c12014-02-04 11:54:58 -0800631 case CMD_SEND_ENVELOPE:
632 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800633 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 if (uiccCard == null) {
635 loge("sendEnvelopeWithStatus: No UICC");
636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
640 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
641 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 break;
643
644 case EVENT_SEND_ENVELOPE_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800649 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700650 request.result = new IccIoResult(0x6F, 0, (byte[])null);
651 if (ar.result == null) {
652 loge("sendEnvelopeWithStatus: Empty response");
653 } else if (ar.exception instanceof CommandException) {
654 loge("sendEnvelopeWithStatus: CommandException: " +
655 ar.exception);
656 } else {
657 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
658 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 case CMD_OPEN_CHANNEL:
664 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800665 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800666 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 if (uiccCard == null) {
668 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800669 request.result = new IccOpenLogicalChannelResponse(-1,
670 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800674 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
675 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case EVENT_OPEN_CHANNEL_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 int[] result = (int[]) ar.result;
685 int channelId = result[0];
686 byte[] selectResponse = null;
687 if (result.length > 1) {
688 selectResponse = new byte[result.length - 1];
689 for (int i = 1; i < result.length; ++i) {
690 selectResponse[i - 1] = (byte) result[i];
691 }
692 }
693 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 if (ar.result == null) {
697 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 if (ar.exception != null) {
700 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
701 }
702
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700704 if (ar.exception instanceof CommandException) {
705 CommandException.Error error =
706 ((CommandException) (ar.exception)).getCommandError();
707 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700709 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 }
712 }
713 openChannelResp = new IccOpenLogicalChannelResponse(
714 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700716 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
720 case CMD_CLOSE_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800722 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 if (uiccCard == null) {
724 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900725 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
729 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
730 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 break;
732
733 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800734 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
735 break;
736
737 case CMD_NV_READ_ITEM:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800740 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
741 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800742 break;
743
744 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800747 if (ar.exception == null && ar.result != null) {
748 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800750 request.result = "";
751 if (ar.result == null) {
752 loge("nvReadItem: Empty response");
753 } else if (ar.exception instanceof CommandException) {
754 loge("nvReadItem: CommandException: " +
755 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800757 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 }
759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
Jake Hambye994d462014-02-03 13:10:13 -0800763 case CMD_NV_WRITE_ITEM:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
766 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800767 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700768 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800769 break;
770
771 case EVENT_NV_WRITE_ITEM_DONE:
772 handleNullReturnEvent(msg, "nvWriteItem");
773 break;
774
775 case CMD_NV_WRITE_CDMA_PRL:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800778 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800779 break;
780
781 case EVENT_NV_WRITE_CDMA_PRL_DONE:
782 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
783 break;
784
chen xu6dac5ab2018-10-26 17:39:23 -0700785 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800786 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700787 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800788 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
chen xu6dac5ab2018-10-26 17:39:23 -0700791 case EVENT_RESET_MODEM_CONFIG_DONE:
792 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
Sooraj Sasindran37444802020-08-11 10:40:43 -0700795 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
798 request);
799 Phone phone = getPhoneFromRequest(request);
800 if (phone != null) {
801 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
802 } else {
803 loge("isNRDualConnectivityEnabled: No phone object");
804 request.result = false;
805 notifyRequester(request);
806 }
807 break;
808 }
809
810 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
811 ar = (AsyncResult) msg.obj;
812 request = (MainThreadRequest) ar.userObj;
813 if (ar.exception == null && ar.result != null) {
814 request.result = ar.result;
815 } else {
816 // request.result must be set to something non-null
817 // for the calling thread to unblock
818 if (request.result != null) {
819 request.result = ar.result;
820 } else {
821 request.result = false;
822 }
823 if (ar.result == null) {
824 loge("isNRDualConnectivityEnabled: Empty response");
825 } else if (ar.exception instanceof CommandException) {
826 loge("isNRDualConnectivityEnabled: CommandException: "
827 + ar.exception);
828 } else {
829 loge("isNRDualConnectivityEnabled: Unknown exception");
830 }
831 }
832 notifyRequester(request);
833 break;
834
835 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
838 Phone phone = getPhoneFromRequest(request);
839 if (phone != null) {
840 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
841 request.workSource);
842 } else {
843 loge("enableNrDualConnectivity: No phone object");
844 request.result =
845 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
846 notifyRequester(request);
847 }
848 break;
849 }
850
851 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result =
856 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
857 } else {
858 request.result =
859 TelephonyManager
860 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
861 if (ar.exception instanceof CommandException) {
862 CommandException.Error error =
863 ((CommandException) (ar.exception)).getCommandError();
864 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
865 request.result =
866 TelephonyManager
867 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
868 }
869 loge("enableNrDualConnectivity" + ": CommandException: "
870 + ar.exception);
871 } else {
872 loge("enableNrDualConnectivity" + ": Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877 }
878
SongFerngWang3ef3e072020-12-21 16:41:52 +0800879 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800881 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
882 request);
883 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800884 break;
885
SongFerngWang3ef3e072020-12-21 16:41:52 +0800886 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result; // Integer
891 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530892 // request.result must be set to something non-null
893 // for the calling thread to unblock
894 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800896 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800898 loge("getAllowedNetworkTypesBitmask: CommandException: "
899 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 }
903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 break;
906
SongFerngWang3ef3e072020-12-21 16:41:52 +0800907 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
910 request);
911 Pair<Integer, Long> reasonWithNetworkTypes =
912 (Pair<Integer, Long>) request.argument;
913 getPhoneFromRequest(request).setAllowedNetworkTypes(
914 reasonWithNetworkTypes.first,
915 reasonWithNetworkTypes.second,
916 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 break;
918
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
920 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 break;
922
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000923 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
924 request = (MainThreadRequest)msg.obj;
925 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000927 break;
928
929 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
930 ar = (AsyncResult)msg.obj;
931 request = (MainThreadRequest)ar.userObj;
932 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000934 break;
935
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800936 case CMD_SET_VOICEMAIL_NUMBER:
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
939 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800940 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
941 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800942 break;
943
944 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
945 handleNullReturnEvent(msg, "setVoicemailNumber");
946 break;
947
Stuart Scott54788802015-03-30 13:18:01 -0700948 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
951 request);
952 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
953 break;
954
955 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
956 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
957 break;
958
Shishir Agrawal302c8692015-06-19 13:49:39 -0700959 case CMD_PERFORM_NETWORK_SCAN:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
962 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
963 break;
964
Hall Liu27d24262020-09-18 19:04:59 -0700965 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700968 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
969 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
970 request.argument;
971 int callForwardingReason = args.first;
972 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800973 break;
Hall Liu27d24262020-09-18 19:04:59 -0700974 }
975 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700978 TelephonyManager.CallForwardingInfoCallback callback =
979 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
980 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800981 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700982 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800983 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
984 for (CallForwardInfo callForwardInfo : callForwardInfos) {
985 // Service Class is a bit mask per 3gpp 27.007. Search for
986 // any service for voice call.
987 if ((callForwardInfo.serviceClass
988 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700989 callForwardingInfo = new CallForwardingInfo(true,
990 callForwardInfo.reason,
991 callForwardInfo.number,
992 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800993 break;
994 }
995 }
996 // Didn't find a call forward info for voice call.
997 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700998 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
999 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001000 }
Hall Liu27d24262020-09-18 19:04:59 -07001001 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001002 } else {
1003 if (ar.result == null) {
1004 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1005 }
1006 if (ar.exception != null) {
1007 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1008 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001009 int errorCode = TelephonyManager
1010 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001011 if (ar.exception instanceof CommandException) {
1012 CommandException.Error error =
1013 ((CommandException) (ar.exception)).getCommandError();
1014 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001015 errorCode = TelephonyManager
1016 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001020 }
1021 }
Hall Liu27d24262020-09-18 19:04:59 -07001022 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 }
Shuo Qian4a594052020-01-23 11:59:30 -08001024 break;
Hall Liu27d24262020-09-18 19:04:59 -07001025 }
Shuo Qian4a594052020-01-23 11:59:30 -08001026
Hall Liu27d24262020-09-18 19:04:59 -07001027 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001030 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001031 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001032 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1033 request.argument).first;
1034 request.phone.setCallForwardingOption(
1035 callForwardingInfoToSet.isEnabled()
1036 ? CommandsInterface.CF_ACTION_ENABLE
1037 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001038 callForwardingInfoToSet.getReason(),
1039 callForwardingInfoToSet.getNumber(),
1040 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1041 break;
Hall Liu27d24262020-09-18 19:04:59 -07001042 }
Shuo Qian4a594052020-01-23 11:59:30 -08001043
Hall Liu27d24262020-09-18 19:04:59 -07001044 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001047 Consumer<Integer> callback =
1048 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1049 request.argument).second;
1050 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001051 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001052 int errorCode = TelephonyManager.CallForwardingInfoCallback
1053 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001054 if (ar.exception instanceof CommandException) {
1055 CommandException.Error error =
1056 ((CommandException) (ar.exception)).getCommandError();
1057 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001058 errorCode = TelephonyManager.CallForwardingInfoCallback
1059 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001061 errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001063 }
1064 }
1065 callback.accept(errorCode);
1066 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001067 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001068 }
Shuo Qian4a594052020-01-23 11:59:30 -08001069 break;
Hall Liu27d24262020-09-18 19:04:59 -07001070 }
Shuo Qian4a594052020-01-23 11:59:30 -08001071
Hall Liu27d24262020-09-18 19:04:59 -07001072 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001073 request = (MainThreadRequest) msg.obj;
1074 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1075 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1076 break;
Hall Liu27d24262020-09-18 19:04:59 -07001077 }
Shuo Qian4a594052020-01-23 11:59:30 -08001078
Hall Liu27d24262020-09-18 19:04:59 -07001079 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001082 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001083 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1084 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001085 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001086 // Service Class is a bit mask per 3gpp 27.007.
1087 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001088 if (callForwardResults.length > 1
1089 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001090 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001091 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001092 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1093 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001095 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001096 }
1097 } else {
1098 if (ar.result == null) {
1099 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1100 }
1101 if (ar.exception != null) {
1102 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1103 }
1104 if (ar.exception instanceof CommandException) {
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 callForwardingStatus =
1109 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1110 }
1111 }
1112 }
Hall Liu27d24262020-09-18 19:04:59 -07001113 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 break;
Hall Liu27d24262020-09-18 19:04:59 -07001115 }
Shuo Qian4a594052020-01-23 11:59:30 -08001116
Hall Liu27d24262020-09-18 19:04:59 -07001117 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001118 request = (MainThreadRequest) msg.obj;
1119 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001120 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1121 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001122 break;
Hall Liu27d24262020-09-18 19:04:59 -07001123 }
Shuo Qian4a594052020-01-23 11:59:30 -08001124
Hall Liu27d24262020-09-18 19:04:59 -07001125 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001128 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1129 Consumer<Integer> callback =
1130 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1131 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001132 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001133 if (ar.exception instanceof CommandException) {
1134 CommandException.Error error =
1135 ((CommandException) (ar.exception)).getCommandError();
1136 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1137 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1138 } else {
1139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1140 }
1141 } else {
1142 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1143 }
1144 } else {
1145 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1146 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001147 }
Shuo Qian4a594052020-01-23 11:59:30 -08001148 break;
Hall Liu27d24262020-09-18 19:04:59 -07001149 }
Shuo Qian4a594052020-01-23 11:59:30 -08001150
Shishir Agrawal302c8692015-06-19 13:49:39 -07001151 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 CellNetworkScanResult cellScanResult;
1155 if (ar.exception == null && ar.result != null) {
1156 cellScanResult = new CellNetworkScanResult(
1157 CellNetworkScanResult.STATUS_SUCCESS,
1158 (List<OperatorInfo>) ar.result);
1159 } else {
1160 if (ar.result == null) {
1161 loge("getCellNetworkScanResults: Empty response");
1162 }
1163 if (ar.exception != null) {
1164 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1165 }
1166 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1167 if (ar.exception instanceof CommandException) {
1168 CommandException.Error error =
1169 ((CommandException) (ar.exception)).getCommandError();
1170 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1171 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1172 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1173 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1174 }
1175 }
1176 cellScanResult = new CellNetworkScanResult(errorCode, null);
1177 }
1178 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001179 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 break;
1181
1182 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1183 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001184 ManualNetworkSelectionArgument selArg =
1185 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001186 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1187 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001188 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1189 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001190 break;
1191
1192 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
1195 if (ar.exception == null) {
1196 request.result = true;
1197 } else {
1198 request.result = false;
1199 loge("setNetworkSelectionModeManual " + ar.exception);
1200 }
1201 notifyRequester(request);
1202 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 break;
1204
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001205 case CMD_GET_MODEM_ACTIVITY_INFO:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001208 if (defaultPhone != null) {
1209 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001210 } else {
1211 ResultReceiver result = (ResultReceiver) request.argument;
1212 Bundle bundle = new Bundle();
1213 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001214 new ModemActivityInfo(0, 0, 0,
1215 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001216 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001217 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001218 break;
1219
Hall Liud0f208c2020-10-14 16:54:44 -07001220 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001221 ar = (AsyncResult) msg.obj;
1222 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001223 ResultReceiver result = (ResultReceiver) request.argument;
1224
Hall Liud0f208c2020-10-14 16:54:44 -07001225 ModemActivityInfo ret = null;
1226 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001228 // Update the last modem activity info and the result of the request.
1229 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1230 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001231 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 int[] txTimeMs = info.getTransmitTimeMillis();
1233 int[] lastModemTxTimeMs = mLastModemActivityInfo
1234 .getTransmitTimeMillis();
1235 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1236 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1237 }
Hall Liu49656c02020-10-09 19:00:11 -07001238 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001239 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1240 + mLastModemActivityInfo.getSleepTimeMillis());
1241 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1242 + mLastModemActivityInfo.getIdleTimeMillis());
1243 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1244 mLastModemActivityInfo.setReceiveTimeMillis(
1245 info.getReceiveTimeMillis()
1246 + mLastModemActivityInfo.getReceiveTimeMillis());
1247 }
Hall Liu49656c02020-10-09 19:00:11 -07001248 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001249 mLastModemActivityInfo.getSleepTimeMillis(),
1250 mLastModemActivityInfo.getIdleTimeMillis(),
1251 mLastModemActivityInfo.getTransmitTimeMillis(),
1252 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001253 } else {
1254 if (ar.result == null) {
1255 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001256 error = TelephonyManager.ModemActivityInfoException
1257 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001258 } else if (ar.exception instanceof CommandException) {
1259 loge("queryModemActivityInfo: CommandException: " +
1260 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001261 error = TelephonyManager.ModemActivityInfoException
1262 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001263 } else {
1264 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001265 error = TelephonyManager.ModemActivityInfoException
1266 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 }
1268 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001269 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001270 if (ret != null) {
1271 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1272 } else {
1273 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1274 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001275 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001276 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001278 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001279
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 case CMD_SET_ALLOWED_CARRIERS:
1281 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001282 CarrierRestrictionRules argument =
1283 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001285 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 break;
1287
1288 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
1291 if (ar.exception == null && ar.result != null) {
1292 request.result = ar.result;
1293 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001294 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1295 if (ar.exception instanceof CommandException) {
1296 loge("setAllowedCarriers: CommandException: " + ar.exception);
1297 CommandException.Error error =
1298 ((CommandException) (ar.exception)).getCommandError();
1299 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1300 request.result =
1301 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1302 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 } else {
1304 loge("setAllowedCarriers: Unknown exception");
1305 }
1306 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001307 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 break;
1309
1310 case CMD_GET_ALLOWED_CARRIERS:
1311 request = (MainThreadRequest) msg.obj;
1312 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001313 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001314 break;
1315
1316 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
1319 if (ar.exception == null && ar.result != null) {
1320 request.result = ar.result;
1321 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001322 request.result = new IllegalStateException(
1323 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001324 if (ar.result == null) {
1325 loge("getAllowedCarriers: Empty response");
1326 } else if (ar.exception instanceof CommandException) {
1327 loge("getAllowedCarriers: CommandException: " +
1328 ar.exception);
1329 } else {
1330 loge("getAllowedCarriers: Unknown exception");
1331 }
1332 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001333 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001334 break;
1335
Nathan Haroldb3014052017-01-25 15:57:32 -08001336 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
1339 if (ar.exception == null && ar.result != null) {
1340 request.result = ar.result;
1341 } else {
1342 request.result = new IllegalArgumentException(
1343 "Failed to retrieve Forbidden Plmns");
1344 if (ar.result == null) {
1345 loge("getForbiddenPlmns: Empty response");
1346 } else {
1347 loge("getForbiddenPlmns: Unknown exception");
1348 }
1349 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001351 break;
1352
1353 case CMD_GET_FORBIDDEN_PLMNS:
1354 request = (MainThreadRequest) msg.obj;
1355 uiccCard = getUiccCardFromRequest(request);
1356 if (uiccCard == null) {
1357 loge("getForbiddenPlmns() UiccCard is null");
1358 request.result = new IllegalArgumentException(
1359 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001360 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001361 break;
1362 }
1363 Integer appType = (Integer) request.argument;
1364 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1365 if (uiccApp == null) {
1366 loge("getForbiddenPlmns() no app with specified type -- "
1367 + appType);
1368 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371 } else {
1372 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1373 + " specified type -- " + appType);
1374 }
1375 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1376 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1377 onCompleted);
1378 break;
1379
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001380 case CMD_SWITCH_SLOTS:
1381 request = (MainThreadRequest) msg.obj;
1382 int[] physicalSlots = (int[]) request.argument;
1383 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1384 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1385 break;
1386
1387 case EVENT_SWITCH_SLOTS_DONE:
1388 ar = (AsyncResult) msg.obj;
1389 request = (MainThreadRequest) ar.userObj;
1390 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
1392 break;
1393 case CMD_GET_NETWORK_SELECTION_MODE:
1394 request = (MainThreadRequest) msg.obj;
1395 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1396 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1397 break;
1398
1399 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception != null) {
1403 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1404 } else {
1405 int mode = ((int[]) ar.result)[0];
1406 if (mode == 0) {
1407 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1408 } else {
1409 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1410 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001411 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
1413 break;
1414 case CMD_GET_CDMA_ROAMING_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1417 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1418 break;
1419 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception != null) {
1423 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1424 } else {
1425 request.result = ((int[]) ar.result)[0];
1426 }
1427 notifyRequester(request);
1428 break;
1429 case CMD_SET_CDMA_ROAMING_MODE:
1430 request = (MainThreadRequest) msg.obj;
1431 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1432 int mode = (int) request.argument;
1433 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1434 break;
1435 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
1438 request.result = ar.exception == null;
1439 notifyRequester(request);
1440 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001441 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1444 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1445 break;
1446 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception != null) {
1450 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1451 } else {
1452 request.result = ((int[]) ar.result)[0];
1453 }
1454 notifyRequester(request);
1455 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001456 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1457 request = (MainThreadRequest) msg.obj;
1458 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1459 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001460 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1461 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001462 break;
1463 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
1466 request.result = ar.exception == null;
1467 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001468 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 case CMD_GET_ALL_CELL_INFO:
1470 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001471 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001472 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001473 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 case EVENT_GET_ALL_CELL_INFO_DONE:
1475 ar = (AsyncResult) msg.obj;
1476 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001477 // If a timeout occurs, the response will be null
1478 request.result = (ar.exception == null && ar.result != null)
1479 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001480 synchronized (request) {
1481 request.notifyAll();
1482 }
1483 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 case CMD_REQUEST_CELL_INFO_UPDATE:
1485 request = (MainThreadRequest) msg.obj;
1486 request.phone.requestCellInfoUpdate(request.workSource,
1487 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1488 break;
1489 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1490 ar = (AsyncResult) msg.obj;
1491 request = (MainThreadRequest) ar.userObj;
1492 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1493 try {
1494 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001495 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001496 cb.onError(
1497 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1498 ar.exception.getClass().getName(),
1499 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001500 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001501 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001502 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001503 } else {
1504 // use the result as returned
1505 cb.onCellInfo((List<CellInfo>) ar.result);
1506 }
1507 } catch (RemoteException re) {
1508 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1509 }
1510 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001511 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001512 request = (MainThreadRequest) msg.obj;
1513 WorkSource ws = (WorkSource) request.argument;
1514 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001515 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001516 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001517 }
1518 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001519 ar = (AsyncResult) msg.obj;
1520 request = (MainThreadRequest) ar.userObj;
1521 if (ar.exception == null) {
1522 request.result = ar.result;
1523 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001524 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001526 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001527 }
1528
1529 synchronized (request) {
1530 request.notifyAll();
1531 }
1532 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001533 }
chen xu6dac5ab2018-10-26 17:39:23 -07001534 case CMD_MODEM_REBOOT:
1535 request = (MainThreadRequest) msg.obj;
1536 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001537 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001538 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001539 case EVENT_CMD_MODEM_REBOOT_DONE:
1540 handleNullReturnEvent(msg, "rebootModem");
1541 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001542 case CMD_REQUEST_ENABLE_MODEM:
1543 request = (MainThreadRequest) msg.obj;
1544 boolean enable = (boolean) request.argument;
1545 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001546 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001547 PhoneConfigurationManager.getInstance()
1548 .enablePhone(request.phone, enable, onCompleted);
1549 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001550 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001554 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001555 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001556 if ((boolean) request.result) {
1557 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1558 updateModemStateMetrics();
1559 } else {
1560 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1561 + ar.exception);
1562 }
1563 notifyRequester(request);
1564 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001565 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001566 case CMD_GET_MODEM_STATUS:
1567 request = (MainThreadRequest) msg.obj;
1568 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1569 PhoneConfigurationManager.getInstance()
1570 .getPhoneStatusFromModem(request.phone, onCompleted);
1571 break;
1572 case EVENT_GET_MODEM_STATUS_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 int id = request.phone.getPhoneId();
1576 if (ar.exception == null && ar.result != null) {
1577 request.result = ar.result;
1578 //update the cache as modem status has changed
1579 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1580 (boolean) request.result);
1581 } else {
1582 // Return true if modem status cannot be retrieved. For most cases,
1583 // modem status is on. And for older version modems, GET_MODEM_STATUS
1584 // and disable modem are not supported. Modem is always on.
1585 // TODO: this should be fixed in R to support a third
1586 // status UNKNOWN b/131631629
1587 request.result = true;
1588 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1589 + ar.exception);
1590 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001591 notifyRequester(request);
1592 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001593 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1594 request = (MainThreadRequest) msg.obj;
1595 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1596 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1597 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1598 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1599 break;
1600 }
1601 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1605 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1606 args.second.accept(ar.exception == null);
1607 notifyRequester(request);
1608 break;
1609 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001610 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1613 Phone phone = getPhoneFromRequest(request);
1614 if (phone != null) {
1615 phone.getSystemSelectionChannels(onCompleted);
1616 } else {
1617 loge("getSystemSelectionChannels: No phone object");
1618 request.result = new ArrayList<RadioAccessSpecifier>();
1619 notifyRequester(request);
1620 }
1621 break;
1622 }
1623 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1624 ar = (AsyncResult) msg.obj;
1625 request = (MainThreadRequest) ar.userObj;
1626 if (ar.exception == null && ar.result != null) {
1627 request.result = ar.result;
1628 } else {
1629 request.result = new IllegalArgumentException(
1630 "Failed to retrieve system selection channels");
1631 if (ar.result == null) {
1632 loge("getSystemSelectionChannels: Empty response");
1633 } else {
1634 loge("getSystemSelectionChannels: Unknown exception");
1635 }
1636 }
1637 notifyRequester(request);
1638 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001639 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1640 ar = (AsyncResult) msg.obj;
1641 request = (MainThreadRequest) ar.userObj;
1642 if (ar.exception == null && ar.result != null) {
1643 request.result = ar.result;
1644 } else {
1645 request.result = -1;
1646 loge("Failed to set Forbidden Plmns");
1647 if (ar.result == null) {
1648 loge("setForbidenPlmns: Empty response");
1649 } else if (ar.exception != null) {
1650 loge("setForbiddenPlmns: Exception: " + ar.exception);
1651 request.result = -1;
1652 } else {
1653 loge("setForbiddenPlmns: Unknown exception");
1654 }
1655 }
1656 notifyRequester(request);
1657 break;
1658 case CMD_SET_FORBIDDEN_PLMNS:
1659 request = (MainThreadRequest) msg.obj;
1660 uiccCard = getUiccCardFromRequest(request);
1661 if (uiccCard == null) {
1662 loge("setForbiddenPlmns: UiccCard is null");
1663 request.result = -1;
1664 notifyRequester(request);
1665 break;
1666 }
1667 Pair<Integer, List<String>> setFplmnsArgs =
1668 (Pair<Integer, List<String>>) request.argument;
1669 appType = setFplmnsArgs.first;
1670 List<String> fplmns = setFplmnsArgs.second;
1671 uiccApp = uiccCard.getApplicationByType(appType);
1672 if (uiccApp == null) {
1673 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1674 request.result = -1;
1675 loge("Failed to get UICC App");
1676 notifyRequester(request);
1677 } else {
1678 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1679 ((SIMRecords) uiccApp.getIccRecords())
1680 .setForbiddenPlmns(onCompleted, fplmns);
1681 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001682 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001683 case CMD_ERASE_MODEM_CONFIG:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1686 defaultPhone.eraseModemConfig(onCompleted);
1687 break;
1688 case EVENT_ERASE_MODEM_CONFIG_DONE:
1689 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001690 break;
zoey chene02881a2019-12-30 16:11:23 +08001691
1692 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1695 Pair<String, String> changed = (Pair<String, String>) request.argument;
1696 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1697 changed.first, changed.second, onCompleted);
1698 break;
1699 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1700 ar = (AsyncResult) msg.obj;
1701 request = (MainThreadRequest) ar.userObj;
1702 if (ar.exception == null) {
1703 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001704 // If the operation is successful, update the PIN storage
1705 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1706 int phoneId = getPhoneFromRequest(request).getPhoneId();
1707 UiccController.getInstance().getPinStorage()
1708 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001709 } else {
1710 request.result = msg.arg1;
1711 }
1712 notifyRequester(request);
1713 break;
1714
Michele Berionne5e411512020-11-13 02:36:59 +00001715 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001716 request = (MainThreadRequest) msg.obj;
1717 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1718 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1719 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1720 enabled.first, enabled.second, onCompleted);
1721 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001722 }
zoey chene02881a2019-12-30 16:11:23 +08001723 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1724 ar = (AsyncResult) msg.obj;
1725 request = (MainThreadRequest) ar.userObj;
1726 if (ar.exception == null) {
1727 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001728 // If the operation is successful, update the PIN storage
1729 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1730 int phoneId = getPhoneFromRequest(request).getPhoneId();
1731 if (enabled.first) {
1732 UiccController.getInstance().getPinStorage()
1733 .storePin(enabled.second, phoneId);
1734 } else {
1735 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1736 }
zoey chene02881a2019-12-30 16:11:23 +08001737 } else {
1738 request.result = msg.arg1;
1739 }
Michele Berionne5e411512020-11-13 02:36:59 +00001740
1741
zoey chene02881a2019-12-30 16:11:23 +08001742 notifyRequester(request);
1743 break;
1744
Peter Wangdafb9ac2020-01-15 14:13:38 -08001745 case MSG_NOTIFY_USER_ACTIVITY:
1746 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001747 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001748 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1749 getDefaultPhone().getContext().sendBroadcastAsUser(
1750 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1751 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001752
1753 case CMD_SET_DATA_THROTTLING: {
1754 request = (MainThreadRequest) msg.obj;
1755 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1756 DataThrottlingRequest dataThrottlingRequest =
1757 (DataThrottlingRequest) request.argument;
1758 Phone phone = getPhoneFromRequest(request);
1759 if (phone != null) {
1760 phone.setDataThrottling(onCompleted,
1761 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1762 dataThrottlingRequest.getCompletionDurationMillis());
1763 } else {
1764 loge("setDataThrottling: No phone object");
1765 request.result =
1766 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1767 notifyRequester(request);
1768 }
1769
1770 break;
1771 }
1772 case EVENT_SET_DATA_THROTTLING_DONE:
1773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
1775
1776 if (ar.exception == null) {
1777 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1778 } else if (ar.exception instanceof CommandException) {
1779 loge("setDataThrottling: CommandException: " + ar.exception);
1780 CommandException.Error error =
1781 ((CommandException) (ar.exception)).getCommandError();
1782
1783 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1784 request.result = TelephonyManager
1785 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1786 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1787 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1788 } else {
1789 request.result =
1790 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1791 }
1792 } else {
1793 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1794 }
1795 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1796 notifyRequester(request);
1797 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001798
1799 case CMD_SET_SIM_POWER: {
1800 request = (MainThreadRequest) msg.obj;
1801 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1802 request = (MainThreadRequest) msg.obj;
1803 int stateToSet =
1804 ((Pair<Integer, IIntegerConsumer>)
1805 request.argument).first;
1806 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1807 break;
1808 }
1809 case EVENT_SET_SIM_POWER_DONE: {
1810 ar = (AsyncResult) msg.obj;
1811 request = (MainThreadRequest) ar.userObj;
1812 IIntegerConsumer callback =
1813 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1814 if (ar.exception != null) {
1815 loge("setSimPower exception: " + ar.exception);
1816 int errorCode = TelephonyManager.CallForwardingInfoCallback
1817 .RESULT_ERROR_UNKNOWN;
1818 if (ar.exception instanceof CommandException) {
1819 CommandException.Error error =
1820 ((CommandException) (ar.exception)).getCommandError();
1821 if (error == CommandException.Error.SIM_ERR) {
1822 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1823 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1824 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1825 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1826 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1827 } else {
1828 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1829 }
1830 }
1831 try {
1832 callback.accept(errorCode);
1833 } catch (RemoteException e) {
1834 // Ignore if the remote process is no longer available to call back.
1835 Log.w(LOG_TAG, "setSimPower: callback not available.");
1836 }
1837 } else {
1838 try {
1839 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1840 } catch (RemoteException e) {
1841 // Ignore if the remote process is no longer available to call back.
1842 Log.w(LOG_TAG, "setSimPower: callback not available.");
1843 }
1844 }
1845 break;
1846 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001847 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1848 request = (MainThreadRequest) msg.obj;
1849
1850 final Phone phone = getPhoneFromRequest(request);
1851 if (phone == null || phone.getServiceStateTracker() == null) {
1852 request.result = new IllegalStateException("Phone or SST is null");
1853 notifyRequester(request);
1854 break;
1855 }
1856
1857 Pair<Integer, SignalStrengthUpdateRequest> pair =
1858 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1859 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1860 request);
1861 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1862 request.subId, pair.first /*callingUid*/,
1863 pair.second /*request*/, onCompleted);
1864 break;
1865 }
1866 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 // request.result will be the exception of ar if present, true otherwise.
1870 // Be cautious not to leave result null which will wait() forever
1871 request.result = ar.exception != null ? ar.exception : true;
1872 notifyRequester(request);
1873 break;
1874 }
1875 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1876 request = (MainThreadRequest) msg.obj;
1877
1878 Phone phone = getPhoneFromRequest(request);
1879 if (phone == null || phone.getServiceStateTracker() == null) {
1880 request.result = new IllegalStateException("Phone or SST is null");
1881 notifyRequester(request);
1882 break;
1883 }
1884
1885 Pair<Integer, SignalStrengthUpdateRequest> pair =
1886 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1887 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1888 request);
1889 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1890 request.subId, pair.first /*callingUid*/,
1891 pair.second /*request*/, onCompleted);
1892 break;
1893 }
1894 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
1897 request.result = ar.exception != null ? ar.exception : true;
1898 notifyRequester(request);
1899 break;
1900 }
Jordan Liu109698e2020-11-24 14:50:34 -08001901
Michele Berionne5e411512020-11-13 02:36:59 +00001902 case CMD_PREPARE_UNATTENDED_REBOOT:
1903 request = (MainThreadRequest) msg.obj;
1904 request.result =
1905 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1906 notifyRequester(request);
1907 break;
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 default:
1910 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1911 break;
1912 }
1913 }
Jake Hambye994d462014-02-03 13:10:13 -08001914
Pengquan Menga1bb6272018-09-06 09:59:22 -07001915 private void notifyRequester(MainThreadRequest request) {
1916 synchronized (request) {
1917 request.notifyAll();
1918 }
1919 }
1920
Jake Hambye994d462014-02-03 13:10:13 -08001921 private void handleNullReturnEvent(Message msg, String command) {
1922 AsyncResult ar = (AsyncResult) msg.obj;
1923 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1924 if (ar.exception == null) {
1925 request.result = true;
1926 } else {
1927 request.result = false;
1928 if (ar.exception instanceof CommandException) {
1929 loge(command + ": CommandException: " + ar.exception);
1930 } else {
1931 loge(command + ": Unknown exception");
1932 }
1933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001934 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 /**
1939 * Posts the specified command to be executed on the main thread,
1940 * waits for the request to complete, and returns the result.
1941 * @see #sendRequestAsync
1942 */
1943 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001944 return sendRequest(
1945 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001946 }
1947
1948 /**
1949 * Posts the specified command to be executed on the main thread,
1950 * waits for the request to complete, and returns the result.
1951 * @see #sendRequestAsync
1952 */
1953 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1954 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001955 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
1958 /**
1959 * Posts the specified command to be executed on the main thread,
1960 * waits for the request to complete, and returns the result.
1961 * @see #sendRequestAsync
1962 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001963 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001964 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001965 }
1966
1967 /**
1968 * Posts the specified command to be executed on the main thread,
1969 * waits for the request to complete, and returns the result.
1970 * @see #sendRequestAsync
1971 */
Nathan Harold92bed182018-10-12 18:16:49 -07001972 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1973 return sendRequest(command, argument, subId, null, workSource);
1974 }
1975
1976 /**
1977 * Posts the specified command to be executed on the main thread,
1978 * waits for the request to complete, and returns the result.
1979 * @see #sendRequestAsync
1980 */
1981 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1982 return sendRequest(
1983 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1984 }
1985
1986 /**
1987 * Posts the specified command to be executed on the main thread,
1988 * waits for the request to complete, and returns the result.
1989 * @see #sendRequestAsync
1990 */
1991 private Object sendRequest(
1992 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1994 throw new RuntimeException("This method will deadlock if called from the main thread.");
1995 }
1996
Nathan Harold92bed182018-10-12 18:16:49 -07001997 MainThreadRequest request = null;
1998 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1999 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2000 } else if (phone != null) {
2001 request = new MainThreadRequest(argument, phone, workSource);
2002 } else {
2003 request = new MainThreadRequest(argument, subId, workSource);
2004 }
2005
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 Message msg = mMainThreadHandler.obtainMessage(command, request);
2007 msg.sendToTarget();
2008
2009 // Wait for the request to complete
2010 synchronized (request) {
2011 while (request.result == null) {
2012 try {
2013 request.wait();
2014 } catch (InterruptedException e) {
2015 // Do nothing, go back and wait until the request is complete
2016 }
2017 }
2018 }
2019 return request.result;
2020 }
2021
2022 /**
2023 * Asynchronous ("fire and forget") version of sendRequest():
2024 * Posts the specified command to be executed on the main thread, and
2025 * returns immediately.
2026 * @see #sendRequest
2027 */
2028 private void sendRequestAsync(int command) {
2029 mMainThreadHandler.sendEmptyMessage(command);
2030 }
2031
2032 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002033 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002034 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002035 */
2036 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002037 sendRequestAsync(command, argument, null, null);
2038 }
2039
2040 /**
2041 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2042 * @see {@link #sendRequest(int,Object)}
2043 */
2044 private void sendRequestAsync(
2045 int command, Object argument, Phone phone, WorkSource workSource) {
2046 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002047 Message msg = mMainThreadHandler.obtainMessage(command, request);
2048 msg.sendToTarget();
2049 }
2050
2051 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 * Initialize the singleton PhoneInterfaceManager instance.
2053 * This is only done once, at startup, from PhoneApp.onCreate().
2054 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002055 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 synchronized (PhoneInterfaceManager.class) {
2057 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002058 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 } else {
2060 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2061 }
2062 return sInstance;
2063 }
2064 }
2065
2066 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002067 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002070 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002071 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2073 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002074 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002075 mTelephonySharedPreferences =
2076 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002077 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002078 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002079 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 publish();
2082 }
2083
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002084 private Phone getDefaultPhone() {
2085 Phone thePhone = getPhone(getDefaultSubscription());
2086 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2087 }
2088
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 private void publish() {
2090 if (DBG) log("publish: " + this);
2091
Peter Wangc035ce42020-01-08 21:00:22 -08002092 TelephonyFrameworkInitializer
2093 .getTelephonyServiceManager()
2094 .getTelephonyServiceRegisterer()
2095 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 }
2097
Stuart Scott584921c2015-01-15 17:10:34 -08002098 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002099 if (request.phone != null) {
2100 return request.phone;
2101 } else {
2102 return getPhoneFromSubId(request.subId);
2103 }
2104 }
2105
2106 private Phone getPhoneFromSubId(int subId) {
2107 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2108 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002109 }
2110
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002111 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2112 Phone phone = getPhoneFromRequest(request);
2113 return phone == null ? null :
2114 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2115 }
2116
Wink Saville36469e72014-06-11 15:17:00 -07002117 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002118 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002119 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121
Naina Nallurid63128d2019-09-17 14:10:30 -07002122 private void sendEraseModemConfig(Phone phone) {
2123 if (phone != null) {
2124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2125 mApp, phone.getSubId(), "eraseModemConfig");
2126 final long identity = Binder.clearCallingIdentity();
2127 try {
2128 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2129 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
2132 }
2133 }
2134 }
2135
Peter Wang44b186e2020-01-13 23:33:09 -08002136 private boolean isImsAvailableOnDevice() {
2137 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2138 if (pm == null) {
2139 // For some reason package manger is not available.. This will fail internally anyway,
2140 // so do not throw error and allow.
2141 return true;
2142 }
2143 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2144 }
2145
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002147 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002148 }
2149
Wink Savilleb564aae2014-10-23 10:18:09 -07002150 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 if (DBG) log("dial: " + number);
2152 // No permission check needed here: This is just a wrapper around the
2153 // ACTION_DIAL intent, which is available to any app since it puts up
2154 // the UI before it does anything.
2155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 String url = createTelUrl(number);
2159 if (url == null) {
2160 return;
2161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163 // PENDING: should we just silently fail if phone is offhook or ringing?
2164 PhoneConstants.State state = mCM.getState(subId);
2165 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2166 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2167 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2168 mApp.startActivity(intent);
2169 }
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173 }
2174
2175 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002176 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002177 }
2178
Wink Savilleb564aae2014-10-23 10:18:09 -07002179 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 if (DBG) log("call: " + number);
2181
2182 // This is just a wrapper around the ACTION_CALL intent, but we still
2183 // need to do a permission check since we're calling startActivity()
2184 // from the context of the phone app.
2185 enforceCallPermission();
2186
Jordan Liu1617b712019-07-10 15:06:26 -07002187 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 != AppOpsManager.MODE_ALLOWED) {
2189 return;
2190 }
2191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 String url = createTelUrl(number);
2195 if (url == null) {
2196 return;
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002199 boolean isValid = false;
2200 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2201 if (slist != null) {
2202 for (SubscriptionInfo subInfoRecord : slist) {
2203 if (subInfoRecord.getSubscriptionId() == subId) {
2204 isValid = true;
2205 break;
2206 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002207 }
Wink Saville08874612014-08-31 19:19:58 -07002208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 if (!isValid) {
2210 return;
2211 }
Wink Saville08874612014-08-31 19:19:58 -07002212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2214 intent.putExtra(SUBSCRIPTION_KEY, subId);
2215 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2216 mApp.startActivity(intent);
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
Wink Savilleb564aae2014-10-23 10:18:09 -07002222 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002223 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002224 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2225 }
2226
Wink Savilleb564aae2014-10-23 10:18:09 -07002227 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002228 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002229 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2230 }
2231
Wink Savilleb564aae2014-10-23 10:18:09 -07002232 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234
2235 final long identity = Binder.clearCallingIdentity();
2236 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002237 Phone phone = getPhone(subId);
2238 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 checkSimPin.start();
2240 return checkSimPin.unlockSim(null, pin);
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
2243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 }
2245
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248
2249 final long identity = Binder.clearCallingIdentity();
2250 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002251 Phone phone = getPhone(subId);
2252 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253 checkSimPuk.start();
2254 return checkSimPuk.unlockSim(puk, pin);
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
2260 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002261 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 * a synchronous one.
2263 */
2264 private static class UnlockSim extends Thread {
2265
2266 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002267 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268
2269 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002270 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2271 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272
2273 // For replies from SimCard interface
2274 private Handler mHandler;
2275
2276 // For async handler to identify request type
2277 private static final int SUPPLY_PIN_COMPLETE = 100;
2278
Michele Berionne5e411512020-11-13 02:36:59 +00002279 UnlockSim(int phoneId, IccCard simCard) {
2280 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 mSimCard = simCard;
2282 }
2283
2284 @Override
2285 public void run() {
2286 Looper.prepare();
2287 synchronized (UnlockSim.this) {
2288 mHandler = new Handler() {
2289 @Override
2290 public void handleMessage(Message msg) {
2291 AsyncResult ar = (AsyncResult) msg.obj;
2292 switch (msg.what) {
2293 case SUPPLY_PIN_COMPLETE:
2294 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2295 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002296 mRetryCount = msg.arg1;
2297 if (ar.exception != null) {
2298 if (ar.exception instanceof CommandException &&
2299 ((CommandException)(ar.exception)).getCommandError()
2300 == CommandException.Error.PASSWORD_INCORRECT) {
2301 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002302 } //When UiccCardApp dispose,handle message and return exception
2303 else if (ar.exception instanceof CommandException &&
2304 ((CommandException) (ar.exception)).getCommandError()
2305 == CommandException.Error.ABORTED) {
2306 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002307 } else {
2308 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2309 }
2310 } else {
2311 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 mDone = true;
2314 UnlockSim.this.notifyAll();
2315 }
2316 break;
2317 }
2318 }
2319 };
2320 UnlockSim.this.notifyAll();
2321 }
2322 Looper.loop();
2323 }
2324
2325 /*
2326 * Use PIN or PUK to unlock SIM card
2327 *
2328 * If PUK is null, unlock SIM card with PIN
2329 *
2330 * If PUK is not null, unlock SIM card with PUK and set PIN code
2331 */
Wink Saville9de0f752013-10-22 19:04:03 -07002332 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333
2334 while (mHandler == null) {
2335 try {
2336 wait();
2337 } catch (InterruptedException e) {
2338 Thread.currentThread().interrupt();
2339 }
2340 }
2341 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2342
2343 if (puk == null) {
2344 mSimCard.supplyPin(pin, callback);
2345 } else {
2346 mSimCard.supplyPuk(puk, pin, callback);
2347 }
2348
2349 while (!mDone) {
2350 try {
2351 Log.d(LOG_TAG, "wait for done");
2352 wait();
2353 } catch (InterruptedException e) {
2354 // Restore the interrupted status
2355 Thread.currentThread().interrupt();
2356 }
2357 }
2358 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002359 int[] resultArray = new int[2];
2360 resultArray[0] = mResult;
2361 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002362
2363 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2364 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2365 }
2366
Wink Saville9de0f752013-10-22 19:04:03 -07002367 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
2369 }
2370
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002371 /**
2372 * This method has been removed due to privacy and stability concerns.
2373 */
2374 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002376 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2377 return;
Wink Saville36469e72014-06-11 15:17:00 -07002378 }
2379
Nathan Harold1f889d82020-06-04 17:05:26 -07002380 @Override
2381 public void updateServiceLocationWithPackageName(String callingPackage) {
2382 mApp.getSystemService(AppOpsManager.class)
2383 .checkPackage(Binder.getCallingUid(), callingPackage);
2384
Nathan Haroldf096d982020-11-18 17:18:06 -08002385 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002386 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2387 // Callers targeting S have no business invoking this method.
2388 return;
2389 }
2390
2391 LocationAccessPolicy.LocationPermissionResult locationResult =
2392 LocationAccessPolicy.checkLocationPermission(mApp,
2393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2394 .setCallingPackage(callingPackage)
2395 .setCallingFeatureId(null)
2396 .setCallingPid(Binder.getCallingPid())
2397 .setCallingUid(Binder.getCallingUid())
2398 .setMethod("updateServiceLocation")
2399 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2400 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2401 .build());
2402 // Apps that lack location permission have no business calling this method;
2403 // however, because no permission was declared in the public API, denials must
2404 // all be "soft".
2405 switch (locationResult) {
2406 case DENIED_HARD: /* fall through */
2407 case DENIED_SOFT:
2408 return;
2409 }
2410
2411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412 final long identity = Binder.clearCallingIdentity();
2413 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002414 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002416 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 }
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002423 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002424 @Override
2425 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002426 return isRadioOnWithFeature(callingPackage, null);
2427 }
2428
2429
2430 @Override
2431 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2432 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2433 callingFeatureId);
2434 }
2435
2436 @Deprecated
2437 @Override
2438 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2439 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002440 }
2441
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002443 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2444 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002446 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 return false;
2448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449
2450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 return isRadioOnForSubscriber(subId);
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
2455 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 }
2457
2458 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 final Phone phone = getPhone(subId);
2462 if (phone != null) {
2463 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2464 } else {
2465 return false;
2466 }
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 }
2471
2472 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002473 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 }
Wink Saville36469e72014-06-11 15:17:00 -07002475
Wink Savilleb564aae2014-10-23 10:18:09 -07002476 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(subId);
2482 if (phone != null) {
2483 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 }
Wink Saville36469e72014-06-11 15:17:00 -07002488 }
2489
2490 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002491 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002492 }
2493
Wink Savilleb564aae2014-10-23 10:18:09 -07002494 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
2500 if (phone == null) {
2501 return false;
2502 }
2503 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2504 toggleRadioOnOffForSubscriber(subId);
2505 }
2506 return true;
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
Wink Saville36469e72014-06-11 15:17:00 -07002511
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002512 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002513 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002514 /*
2515 * If any of the Radios are available, it will need to be
2516 * shutdown. So return true if any Radio is available.
2517 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2521 Phone phone = PhoneFactory.getPhone(i);
2522 if (phone != null && phone.isRadioAvailable()) return true;
2523 }
2524 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2525 return false;
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002528 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002529 }
2530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002532 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 enforceModifyPermission();
2534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2538 logv("Shutting down Phone " + i);
2539 shutdownRadioUsingPhoneId(i);
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002543 }
2544 }
2545
2546 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002547 Phone phone = PhoneFactory.getPhone(phoneId);
2548 if (phone != null && phone.isRadioAvailable()) {
2549 phone.shutdownRadio();
2550 }
2551 }
2552
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2559 if (defaultPhone != null) {
2560 defaultPhone.setRadioPower(turnOn);
2561 return true;
2562 } else {
2563 loge("There's no default phone.");
2564 return false;
2565 }
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002568 }
Wink Saville36469e72014-06-11 15:17:00 -07002569 }
2570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 phone.setRadioPower(turnOn);
2579 return true;
2580 } else {
2581 return false;
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 }
2587
Wink Saville36469e72014-06-11 15:17:00 -07002588 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002589 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 public boolean enableDataConnectivity() {
2591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 int subId = mSubscriptionController.getDefaultDataSubId();
2596 final Phone phone = getPhone(subId);
2597 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002598 phone.getDataEnabledSettings().setDataEnabled(
2599 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 return true;
2601 } else {
2602 return false;
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 }
2608
Wink Saville36469e72014-06-11 15:17:00 -07002609 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 public boolean disableDataConnectivity() {
2612 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 int subId = mSubscriptionController.getDefaultDataSubId();
2617 final Phone phone = getPhone(subId);
2618 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002619 phone.getDataEnabledSettings().setDataEnabled(
2620 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 return true;
2622 } else {
2623 return false;
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629
Sanket Padawe356d7632015-06-22 14:03:32 -07002630 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002631 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 final Phone phone = getPhone(subId);
2635 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002636 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 } else {
2638 return false;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
2645 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002646 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002647 }
2648
pkanwarae03a6b2016-11-06 20:37:09 -08002649 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 enforceCallPermission();
2651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2655 return;
2656 }
2657 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2658 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
pkanwar32d516d2016-10-14 19:37:38 -07002662 };
2663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2670 return false;
2671 }
2672 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002679 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002680 }
2681
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002682 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 Phone phone = PhoneFactory.getPhone(slotIndex);
2686 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2687 PhoneConstantConversions.convertCallState(phone.getState());
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002694 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002695 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2696 }
2697
2698 @Override
2699 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 final long identity = Binder.clearCallingIdentity();
2701 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002702 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 if (phone != null) {
2704 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2705 } else {
2706 return PhoneConstantConversions.convertDataState(
2707 PhoneConstants.DataState.DISCONNECTED);
2708 }
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 }
2713
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002715 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002716 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2717 }
2718
2719 @Override
2720 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 final long identity = Binder.clearCallingIdentity();
2722 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002723 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 if (phone != null) {
2725 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2726 } else {
2727 return TelephonyManager.DATA_ACTIVITY_NONE;
2728 }
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 }
2733
2734 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002735 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002736 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002737 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002738
2739 LocationAccessPolicy.LocationPermissionResult locationResult =
2740 LocationAccessPolicy.checkLocationPermission(mApp,
2741 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2742 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002743 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002744 .setCallingPid(Binder.getCallingPid())
2745 .setCallingUid(Binder.getCallingUid())
2746 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002747 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002748 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2749 .build());
2750 switch (locationResult) {
2751 case DENIED_HARD:
2752 throw new SecurityException("Not allowed to access cell location");
2753 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002754 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2755 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
2757
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002758 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002762 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002763 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
Svetoslav64fad262015-04-14 14:35:21 -07002767 }
2768
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002770 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002771 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2772 // registered cell info, so return a NULL country instead.
2773 final long identity = Binder.clearCallingIdentity();
2774 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002775 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2776 // Get default phone in this case.
2777 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2778 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002779 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002781 if (phone == null) return "";
2782 ServiceStateTracker sst = phone.getServiceStateTracker();
2783 if (sst == null) return "";
2784 LocaleTracker lt = sst.getLocaleTracker();
2785 if (lt == null) return "";
2786 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2787 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2788 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002789 } finally {
2790 Binder.restoreCallingIdentity(identity);
2791 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002792 }
2793
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002794 /**
2795 * This method was removed due to potential issues caused by performing partial
2796 * updates of service state, and lack of a credible use case.
2797 *
2798 * This has the ability to break the telephony implementation by disabling notification of
2799 * changes in device connectivity. DO NOT USE THIS!
2800 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002801 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 public void enableLocationUpdates() {
2803 mApp.enforceCallingOrSelfPermission(
2804 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 }
2806
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002807 /**
2808 * This method was removed due to potential issues caused by performing partial
2809 * updates of service state, and lack of a credible use case.
2810 *
2811 * This has the ability to break the telephony implementation by disabling notification of
2812 * changes in device connectivity. DO NOT USE THIS!
2813 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 @Override
2815 public void disableLocationUpdates() {
2816 mApp.enforceCallingOrSelfPermission(
2817 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
2820 @Override
2821 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002822 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2823 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002824 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002825 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2826 throw new SecurityException(
2827 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2828 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002829
Jordan Liu1617b712019-07-10 15:06:26 -07002830 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2832 return null;
2833 }
Svetoslav64fad262015-04-14 14:35:21 -07002834
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002835 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002837 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002838 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839
Nathan Haroldf180aac2018-06-01 18:43:55 -07002840 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2841 for (CellInfo ci : info) {
2842 if (ci instanceof CellInfoGsm) {
2843 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2844 } else if (ci instanceof CellInfoWcdma) {
2845 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002848 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002851 private List<CellInfo> getCachedCellInfo() {
2852 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2853 for (Phone phone : PhoneFactory.getPhones()) {
2854 List<CellInfo> info = phone.getAllCellInfo();
2855 if (info != null) cellInfos.addAll(info);
2856 }
2857 return cellInfos;
2858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859
2860 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002861 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002862 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002863 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002864
2865 LocationAccessPolicy.LocationPermissionResult locationResult =
2866 LocationAccessPolicy.checkLocationPermission(mApp,
2867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2868 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002869 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002870 .setCallingPid(Binder.getCallingPid())
2871 .setCallingUid(Binder.getCallingUid())
2872 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002873 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2875 .build());
2876 switch (locationResult) {
2877 case DENIED_HARD:
2878 throw new SecurityException("Not allowed to access cell info");
2879 case DENIED_SOFT:
2880 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 }
2882
Nathan Haroldf096d982020-11-18 17:18:06 -08002883 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002884 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2885 return getCachedCellInfo();
2886 }
2887
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002888 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2893 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002894 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002895 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896 if (info != null) cellInfos.addAll(info);
2897 }
2898 return cellInfos;
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902 }
2903
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002904 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002905 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2906 String callingFeatureId) {
2907 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2908 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002909 }
2910
2911 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002912 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2913 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002914 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002915 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002916 }
2917
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002918 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2919 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002920 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002921 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002922
2923 LocationAccessPolicy.LocationPermissionResult locationResult =
2924 LocationAccessPolicy.checkLocationPermission(mApp,
2925 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2926 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002927 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002928 .setCallingPid(Binder.getCallingPid())
2929 .setCallingUid(Binder.getCallingUid())
2930 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002931 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2932 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002933 .build());
2934 switch (locationResult) {
2935 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002936 if (TelephonyPermissions
2937 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002938 // Safetynet logging for b/154934934
2939 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2940 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002941 throw new SecurityException("Not allowed to access cell info");
2942 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002943 if (TelephonyPermissions
2944 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002945 // Safetynet logging for b/154934934
2946 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2947 }
Nathan Harold5320c422019-05-09 10:26:08 -07002948 try {
2949 cb.onCellInfo(new ArrayList<CellInfo>());
2950 } catch (RemoteException re) {
2951 // Drop without consequences
2952 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002953 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002954 }
2955
Nathan Harolda939a962019-05-09 10:13:47 -07002956
2957 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002958 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2959
2960 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2961 }
2962
2963 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002965 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002966 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002970 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
Shishir Agrawala9f32182016-04-12 12:00:16 -07002976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002977 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002978 Phone phone = PhoneFactory.getPhone(slotIndex);
2979 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 return null;
2981 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002982 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002983 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002984 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002985 return null;
2986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 return phone.getImei();
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002994 }
2995
2996 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002997 public String getTypeAllocationCodeForSlot(int slotIndex) {
2998 Phone phone = PhoneFactory.getPhone(slotIndex);
2999 String tac = null;
3000 if (phone != null) {
3001 String imei = phone.getImei();
3002 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3003 }
3004 return tac;
3005 }
3006
3007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003008 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003009 Phone phone = PhoneFactory.getPhone(slotIndex);
3010 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003011 return null;
3012 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003013
Jeff Davidson913390f2018-02-23 17:11:49 -08003014 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003015 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003016 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003017 return null;
3018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 return phone.getMeid();
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Jack Yu2af8d712017-03-15 17:14:14 -07003026 }
3027
3028 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003029 public String getManufacturerCodeForSlot(int slotIndex) {
3030 Phone phone = PhoneFactory.getPhone(slotIndex);
3031 String manufacturerCode = null;
3032 if (phone != null) {
3033 String meid = phone.getMeid();
3034 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3035 }
3036 return manufacturerCode;
3037 }
3038
3039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003040 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3041 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003042 Phone phone = PhoneFactory.getPhone(slotIndex);
3043 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003044 return null;
3045 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003046 int subId = phone.getSubId();
3047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003048 mApp, subId, callingPackage, callingFeatureId,
3049 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003050 return null;
3051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 return phone.getDeviceSvn();
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003059 }
3060
fionaxu43304da2017-11-27 22:51:16 -08003061 @Override
3062 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 final Phone phone = getPhone(subId);
3066 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
fionaxu43304da2017-11-27 22:51:16 -08003070 }
3071
3072 @Override
3073 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 final Phone phone = getPhone(subId);
3077 return phone == null ? null : phone.getCarrierName();
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
fionaxu43304da2017-11-27 22:51:16 -08003081 }
3082
calvinpanffe225e2018-11-01 19:43:06 +08003083 @Override
chen xu0026ca62019-03-06 15:28:50 -08003084 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 final Phone phone = getPhone(subId);
3088 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003089 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
3093 }
3094
3095 @Override
chen xu0026ca62019-03-06 15:28:50 -08003096 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003100 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
chen xu651eec72018-11-11 19:03:44 -08003106 @Override
chen xu864e11c2018-12-06 22:10:03 -08003107 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3108 if (!isSubscriptionMccMnc) {
3109 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3110 }
chen xu651eec72018-11-11 19:03:44 -08003111 final Phone phone = PhoneFactory.getPhone(slotIndex);
3112 if (phone == null) {
3113 return TelephonyManager.UNKNOWN_CARRIER_ID;
3114 }
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
3121 }
3122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 //
3124 // Internal helper methods.
3125 //
3126
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003127 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3129 *
3130 * @throws SecurityException if the caller does not have the required permission
3131 */
3132 private void enforceModifyPermission() {
3133 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3134 }
3135
Shuo Qiancd19c462020-01-16 20:51:11 -08003136 /**
3137 * Make sure the caller is system.
3138 *
3139 * @throws SecurityException if the caller is not system.
3140 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003141 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003142 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3143 throw new SecurityException("Caller must be system");
3144 }
3145 }
3146
Shuo Qian3b6ee772019-11-13 17:43:31 -08003147 private void enforceActiveEmergencySessionPermission() {
3148 mApp.enforceCallingOrSelfPermission(
3149 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3150 }
3151
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 /**
3153 * Make sure the caller has the CALL_PHONE permission.
3154 *
3155 * @throws SecurityException if the caller does not have the required permission
3156 */
3157 private void enforceCallPermission() {
3158 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3159 }
3160
paulhu5a773602019-08-23 19:17:33 +08003161 private void enforceSettingsPermission() {
3162 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003163 }
3164
Michele Berionne5e411512020-11-13 02:36:59 +00003165 private void enforceRebootPermission() {
3166 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3167 }
3168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 private String createTelUrl(String number) {
3170 if (TextUtils.isEmpty(number)) {
3171 return null;
3172 }
3173
Jake Hambye994d462014-02-03 13:10:13 -08003174 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 }
3176
Ihab Awadf9e92732013-12-05 18:02:52 -08003177 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3179 }
3180
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003181 private static void logv(String msg) {
3182 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3183 }
3184
Ihab Awadf9e92732013-12-05 18:02:52 -08003185 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3187 }
3188
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003189 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003191 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003192 }
3193
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003195 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 final Phone phone = PhoneFactory.getPhone(slotIndex);
3199 if (phone == null) {
3200 return PhoneConstants.PHONE_TYPE_NONE;
3201 } else {
3202 return phone.getPhoneType();
3203 }
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208
3209 /**
3210 * Returns the CDMA ERI icon index to display
3211 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003212 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003213 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3214 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3215 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003216 }
3217
Sanket Padawe356d7632015-06-22 14:03:32 -07003218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003219 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3220 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003222 mApp, subId, callingPackage, callingFeatureId,
3223 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003224 return -1;
3225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 final Phone phone = getPhone(subId);
3230 if (phone != null) {
3231 return phone.getCdmaEriIconIndex();
3232 } else {
3233 return -1;
3234 }
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 }
3239
3240 /**
3241 * Returns the CDMA ERI icon mode,
3242 * 0 - ON
3243 * 1 - FLASHING
3244 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003245 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003246 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3247 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3248 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003249 }
3250
Sanket Padawe356d7632015-06-22 14:03:32 -07003251 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003252 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3253 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003255 mApp, subId, callingPackage, callingFeatureId,
3256 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003257 return -1;
3258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 final Phone phone = getPhone(subId);
3263 if (phone != null) {
3264 return phone.getCdmaEriIconMode();
3265 } else {
3266 return -1;
3267 }
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 }
3272
3273 /**
3274 * Returns the CDMA ERI text,
3275 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003277 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3278 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3279 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003280 }
3281
Sanket Padawe356d7632015-06-22 14:03:32 -07003282 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003283 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3284 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003286 mApp, subId, callingPackage, callingFeatureId,
3287 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003288 return null;
3289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 final Phone phone = getPhone(subId);
3294 if (phone != null) {
3295 return phone.getCdmaEriText();
3296 } else {
3297 return null;
3298 }
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 }
3303
3304 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003305 * Returns the CDMA MDN.
3306 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003307 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003308 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3310 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 return phone.getLine1Number();
3317 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003318 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 return null;
3320 }
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003323 }
3324 }
3325
3326 /**
3327 * Returns the CDMA MIN.
3328 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003329 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003330 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 final Phone phone = getPhone(subId);
3337 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3338 return phone.getCdmaMin();
3339 } else {
3340 return null;
3341 }
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003344 }
3345 }
3346
Hall Liud892bec2018-11-30 14:51:45 -08003347 @Override
3348 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3349 INumberVerificationCallback callback, String callingPackage) {
3350 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3351 != PERMISSION_GRANTED) {
3352 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3353 }
3354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3355
3356 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3357 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003358 throw new SecurityException("Calling package must be configured in the device config: "
3359 + "calling package: " + callingPackage
3360 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003361 }
3362
3363 if (range == null) {
3364 throw new NullPointerException("Range must be non-null");
3365 }
3366
3367 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003368 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003369
3370 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3371 }
3372
Junda Liuca05d5d2014-08-14 22:36:34 -07003373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003374 * Returns true if CDMA provisioning needs to run.
3375 */
3376 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377 final long identity = Binder.clearCallingIdentity();
3378 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 }
3384
3385 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003386 * Sets the voice mail number of a given subId.
3387 */
3388 @Override
3389 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003390 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3391 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3396 new Pair<String, String>(alphaTag, number), new Integer(subId));
3397 return success;
3398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003401 }
3402
Ta-wei Yen87c49842016-05-13 21:19:52 -07003403 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003404 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003406 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3407 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003408 if (!TextUtils.equals(callingPackage, systemDialer)) {
3409 throw new SecurityException("caller must be system dialer");
3410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3415 if (phoneAccountHandle == null) {
3416 return null;
3417 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003418 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 } finally {
3420 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003421 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003422 }
3423
3424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003425 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3426 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 mApp, subId, callingPackage, callingFeatureId,
3430 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003431 return null;
3432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003434 final long identity = Binder.clearCallingIdentity();
3435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003436 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003440 }
3441
3442 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003443 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3444 VisualVoicemailSmsFilterSettings settings) {
3445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003450 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003454 }
3455
3456 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003457 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459
3460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003467 }
3468
3469 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003470 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3471 String callingPackage, int subId) {
3472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003477 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003481 }
3482
3483 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003484 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003485 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003490 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003494 }
3495
3496 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003497 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3498 String callingAttributionTag, int subId, String number, int port, String text,
3499 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003501 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003502 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003503 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003504 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3505 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003506 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003507
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003508 /**
fionaxu0152e512016-11-14 13:36:14 -08003509 * Sets the voice activation state of a given subId.
3510 */
3511 @Override
3512 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3514 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 final Phone phone = getPhone(subId);
3519 if (phone != null) {
3520 phone.setVoiceActivationState(activationState);
3521 } else {
3522 loge("setVoiceActivationState fails with invalid subId: " + subId);
3523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003526 }
3527 }
3528
3529 /**
3530 * Sets the data activation state of a given subId.
3531 */
3532 @Override
3533 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3535 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 phone.setDataActivationState(activationState);
3542 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003543 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003547 }
3548 }
3549
3550 /**
3551 * Returns the voice activation state of a given subId.
3552 */
3553 @Override
3554 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
fionaxu0152e512016-11-14 13:36:14 -08003557 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 if (phone != null) {
3561 return phone.getVoiceActivationState();
3562 } else {
3563 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003567 }
3568 }
3569
3570 /**
3571 * Returns the data activation state of a given subId.
3572 */
3573 @Override
3574 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
fionaxu0152e512016-11-14 13:36:14 -08003577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 if (phone != null) {
3581 return phone.getDataActivationState();
3582 } else {
3583 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003587 }
3588 }
3589
3590 /**
Wink Saville36469e72014-06-11 15:17:00 -07003591 * Returns the unread count of voicemails for a subId
3592 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003594 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3595 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003597 mApp, subId, callingPackage, callingFeatureId,
3598 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003599 return 0;
3600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 final Phone phone = getPhone(subId);
3604 if (phone != null) {
3605 return phone.getVoiceMessageCount();
3606 } else {
3607 return 0;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 }
3613
3614 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003615 * returns true, if the device is in a state where both voice and data
3616 * are supported simultaneously. This can change based on location or network condition.
3617 */
3618 @Override
3619 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 final Phone phone = getPhone(subId);
3623 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003627 }
3628
3629 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003630 * Send the dialer code if called from the current default dialer or the caller has
3631 * carrier privilege.
3632 * @param inputCode The dialer code to send
3633 */
3634 @Override
3635 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003638 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3639 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003640 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003641 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003647 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 } finally {
3649 Binder.restoreCallingIdentity(identity);
3650 }
fionaxu235cc5e2017-03-06 22:25:57 -08003651 }
3652
Pengquan Menga1bb6272018-09-06 09:59:22 -07003653 @Override
3654 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003655 TelephonyPermissions
3656 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3657 mApp, subId, "getNetworkSelectionMode");
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 if (!isActiveSubscription(subId)) {
3661 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3662 }
3663 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003666 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003667 }
3668
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003670 public boolean isInEmergencySmsMode() {
3671 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 for (Phone phone : PhoneFactory.getPhones()) {
3675 if (phone.isInEmergencySmsMode()) {
3676 return true;
3677 }
3678 }
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 return false;
3683 }
3684
shilu366312e2019-12-17 09:28:10 -08003685 /**
3686 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3687 * @param subId The subscription to use to check the configuration.
3688 * @param c The callback that will be used to send the result.
3689 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003690 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003691 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3692 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003693 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3694 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003695
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003696 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3697 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3698 "IMS not available on device.");
3699 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 final long token = Binder.clearCallingIdentity();
3701 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 } catch (ImsException e) {
3706 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 } finally {
3708 Binder.restoreCallingIdentity(token);
3709 }
3710 }
3711
shilu366312e2019-12-17 09:28:10 -08003712 /**
3713 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3714 * @param subId The subscription to use to check the configuration.
3715 * @param c The callback that will be used to send the result.
3716 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003718 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003719 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3720 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3722 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3723 }
Meng Wangafbc5852019-09-19 17:37:13 -07003724 final long token = Binder.clearCallingIdentity();
3725 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003726 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003727 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3728 .removeRegistrationCallbackForSubscription(c, subId);
3729 } catch (ImsException e) {
3730 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3731 + "is inactive, ignoring unregister.");
3732 // If the subscription is no longer active, just return, since the callback
3733 // will already have been removed internally.
3734 } finally {
3735 Binder.restoreCallingIdentity(token);
3736 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 }
3738
Brad Ebingera34a6c22019-10-22 17:36:18 -07003739 /**
3740 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3741 */
3742 @Override
3743 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3744 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3745 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3746 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3747 "IMS not available on device.");
3748 }
3749 final long token = Binder.clearCallingIdentity();
3750 try {
3751 Phone phone = getPhone(subId);
3752 if (phone == null) {
3753 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3754 + subId + "'");
3755 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3756 }
3757 phone.getImsRegistrationState(regState -> {
3758 try {
3759 consumer.accept((regState == null)
3760 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3761 } catch (RemoteException e) {
3762 // Ignore if the remote process is no longer available to call back.
3763 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3764 }
3765 });
3766 } finally {
3767 Binder.restoreCallingIdentity(token);
3768 }
3769 }
3770
3771 /**
3772 * Get the transport type for the IMS service registration state.
3773 */
3774 @Override
3775 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003776 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3777 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003778 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3779 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3780 "IMS not available on device.");
3781 }
3782 final long token = Binder.clearCallingIdentity();
3783 try {
3784 Phone phone = getPhone(subId);
3785 if (phone == null) {
3786 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3787 + subId + "'");
3788 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3789 }
3790 phone.getImsRegistrationTech(regTech -> {
3791 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3792 int regTechConverted = (regTech == null)
3793 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3794 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3795 regTechConverted);
3796 try {
3797 consumer.accept(regTechConverted);
3798 } catch (RemoteException e) {
3799 // Ignore if the remote process is no longer available to call back.
3800 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3801 }
3802 });
3803 } finally {
3804 Binder.restoreCallingIdentity(token);
3805 }
3806 }
3807
shilu366312e2019-12-17 09:28:10 -08003808 /**
3809 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3810 * @param subId The subscription to use to check the configuration.
3811 * @param c The callback that will be used to send the result.
3812 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003814 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3815 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003816 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3817 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003818 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3819 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3820 "IMS not available on device.");
3821 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3823 final long token = Binder.clearCallingIdentity();
3824 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003827 } catch (ImsException e) {
3828 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 } finally {
3830 Binder.restoreCallingIdentity(token);
3831 }
3832 }
3833
shilu366312e2019-12-17 09:28:10 -08003834 /**
3835 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3836 * @param subId The subscription to use to check the configuration.
3837 * @param c The callback that will be used to send the result.
3838 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003840 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003841 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3842 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003843 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3844 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3845 }
Meng Wangafbc5852019-09-19 17:37:13 -07003846
3847 final long token = Binder.clearCallingIdentity();
3848 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003849 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003850 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003851 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003852 } catch (ImsException e) {
3853 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3854 + "is inactive, ignoring unregister.");
3855 // If the subscription is no longer active, just return, since the callback
3856 // will already have been removed internally.
3857 } finally {
3858 Binder.restoreCallingIdentity(token);
3859 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 }
3861
3862 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003863 public boolean isCapable(int subId, int capability, int regTech) {
3864 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3866 final long token = Binder.clearCallingIdentity();
3867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003868 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003870 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3872 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003873 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003874 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3875 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 } finally {
3877 Binder.restoreCallingIdentity(token);
3878 }
3879 }
3880
3881 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003882 public boolean isAvailable(int subId, int capability, int regTech) {
3883 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 final long token = Binder.clearCallingIdentity();
3885 try {
3886 Phone phone = getPhone(subId);
3887 if (phone == null) return false;
3888 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003889 } catch (com.android.ims.ImsException e) {
3890 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3891 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 } finally {
3893 Binder.restoreCallingIdentity(token);
3894 }
3895 }
3896
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003897 /**
3898 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3899 * subscription.
3900 * @param subId The subscription to use to check the configuration.
3901 * @param callback The callback that will be used to send the result.
3902 * @param capability The MmTelFeature capability that will be used to send the result.
3903 * @param transportType The transport type of the MmTelFeature capability.
3904 */
3905 @Override
3906 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3907 int transportType) {
3908 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3909 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3910 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3911 "IMS not available on device.");
3912 }
3913 final long token = Binder.clearCallingIdentity();
3914 try {
3915 int slotId = getSlotIndex(subId);
3916 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3917 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3918 + subId + "'");
3919 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3920 }
3921 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3922 transportType, aBoolean -> {
3923 try {
3924 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3925 } catch (RemoteException e) {
3926 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3927 + "running. Ignore");
3928 }
3929 });
3930 } finally {
3931 Binder.restoreCallingIdentity(token);
3932 }
3933 }
3934
shilu366312e2019-12-17 09:28:10 -08003935 /**
3936 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3937 * @param subId The subscription to use to check the configuration.
3938 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 @Override
3940 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003941 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3942 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003943
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3945 final long token = Binder.clearCallingIdentity();
3946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003949 } catch (ImsException e) {
3950 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003951 } finally {
3952 Binder.restoreCallingIdentity(token);
3953 }
3954 }
3955
3956 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003957 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003959 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003963 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003965 } catch (ImsException e) {
3966 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
3970 }
3971
shilu366312e2019-12-17 09:28:10 -08003972 /**
3973 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3974 * @param subId The subscription to use to check the configuration.
3975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003977 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003978 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3979 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003983 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3984 } catch (ImsException e) {
3985 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
3989 }
3990
3991 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003992 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003994 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003998 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003999 } catch (ImsException e) {
4000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
4004 }
4005
shilu366312e2019-12-17 09:28:10 -08004006 /**
4007 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4008 * @param subId The subscription to use to check the configuration.
4009 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 @Override
4011 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004012 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4013 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004017 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004019 } catch (ImsException e) {
4020 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
4024 }
4025
4026 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004027 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004029 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004033 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004034 } catch (ImsException e) {
4035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(identity);
4038 }
4039 }
4040
shilu366312e2019-12-17 09:28:10 -08004041 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004042 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4043 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4044 * @param subId The subscription to use to check the configuration.
4045 */
4046 @Override
4047 public boolean isCrossSimCallingEnabledByUser(int subId) {
4048 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4049 mApp, subId, "isCrossSimCallingEnabledByUser");
4050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4053 return ImsManager.getInstance(mApp,
4054 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
4060 }
4061
4062 /**
4063 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4064 * Requires MODIFY_PHONE_STATE permission.
4065 * @param subId The subscription to use to check the configuration.
4066 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4067 * false otherwise
4068 */
4069 @Override
4070 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4072 "setCrossSimCallingEnabled");
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4076 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4077 .setCrossSimCallingEnabled(isEnabled);
4078 } catch (ImsException e) {
4079 throw new ServiceSpecificException(e.getCode());
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
4083 }
4084
4085 /**
shilu366312e2019-12-17 09:28:10 -08004086 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4087 * @param subId The subscription to use to check the configuration.
4088 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 @Override
4090 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004091 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4092 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004098 } catch (ImsException e) {
4099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
4103 }
4104
4105 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004106 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004108 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004112 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004114 } catch (ImsException e) {
4115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
4119 }
4120
4121 @Override
4122 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4124 "setVoWiFiNonPersistent");
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004128 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004129 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004130 } catch (ImsException e) {
4131 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
4135 }
4136
shilu366312e2019-12-17 09:28:10 -08004137 /**
4138 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4139 * @param subId The subscription to use to check the configuration.
4140 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 @Override
4142 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004143 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4144 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004148 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (ImsException e) {
4151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public void setVoWiFiModeSetting(int subId, int mode) {
4159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4160 "setVoWiFiModeSetting");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 @Override
4174 public int getVoWiFiRoamingModeSetting(int subId) {
4175 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004179 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004181 } catch (ImsException e) {
4182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187
4188 @Override
4189 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4191 "setVoWiFiRoamingModeSetting");
4192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004195 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 } catch (ImsException e) {
4198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
4202 }
4203
4204 @Override
4205 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4207 "setRttCapabilityEnabled");
4208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4212 } catch (ImsException e) {
4213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
4217 }
4218
shilu366312e2019-12-17 09:28:10 -08004219 /**
4220 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4221 * @param subId The subscription to use to check the configuration.
4222 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 @Override
4224 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004225 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4226 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 final long identity = Binder.clearCallingIdentity();
4228 try {
4229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004230 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004232 } catch (ImsException e) {
4233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
4237 }
4238
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004239 @Override
4240 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4241 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004244 if (!isImsAvailableOnDevice()) {
4245 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4246 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004247 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004248 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004249 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004250 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004251 } catch (ImsException e) {
4252 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
4256 }
4257
4258 @Override
4259 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4260 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4261 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004262 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4263 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4264 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004265 try {
4266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004268 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004270 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4271 + "is inactive, ignoring unregister.");
4272 // If the subscription is no longer active, just return, since the callback will already
4273 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004274 } finally {
4275 Binder.restoreCallingIdentity(identity);
4276 }
4277 }
4278
allenwtsu99c623b2020-01-03 18:24:23 +08004279
4280 private void checkModifyPhoneStatePermission(int subId, String message) {
4281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4282 message);
4283 }
4284
4285 private boolean isImsProvisioningRequired(int subId, int capability,
4286 boolean isMmtelCapability) {
4287 Phone phone = getPhone(subId);
4288 if (phone == null) {
4289 loge("phone instance null for subid " + subId);
4290 return false;
4291 }
4292 if (isMmtelCapability) {
4293 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4294 return false;
4295 }
4296 } else {
4297 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4298 return false;
4299 }
4300 }
4301 return true;
4302 }
4303
4304 @Override
4305 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4306 boolean isProvisioned) {
4307 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4308
4309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4312 if (!isImsProvisioningRequired(subId, capability, false)) {
4313 return;
4314 }
4315
4316 // this capability requires provisioning, route to the correct API.
4317 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4318 switch (capability) {
4319 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4320 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4321 ims.setEabProvisioned(isProvisioned);
4322 break;
4323 default: {
4324 throw new IllegalArgumentException("Tried to set provisioning for "
4325 + "rcs capability '" + capability + "', which does not require "
4326 + "provisioning.");
4327 }
4328 }
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
4332
4333 }
4334
4335
4336 @Override
4337 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4338 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4342 if (!isImsProvisioningRequired(subId, capability, false)) {
4343 return true;
4344 }
4345
4346 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4347 switch (capability) {
4348 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4349 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4350 return ims.isEabProvisionedOnDevice();
4351
4352 default: {
4353 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4354 + "capability '" + capability + "', which does not require "
4355 + "provisioning.");
4356 }
4357 }
4358
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
4362 }
4363
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004364 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004365 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4366 boolean isProvisioned) {
4367 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4368 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4369 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4370 }
allenwtsu99c623b2020-01-03 18:24:23 +08004371 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004375 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004376 return;
4377 }
4378
4379 // this capability requires provisioning, route to the correct API.
4380 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4381 switch (capability) {
4382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4383 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4384 ims.setVolteProvisioned(isProvisioned);
4385 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4386 ims.setWfcProvisioned(isProvisioned);
4387 }
4388 break;
4389 }
4390 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4391 // There is currently no difference in VT provisioning type.
4392 ims.setVtProvisioned(isProvisioned);
4393 break;
4394 }
4395 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4396 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4397 // change the capability of the feature instead if needed.
4398 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4399 == isProvisioned) {
4400 // No change in provisioning.
4401 return;
4402 }
4403 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4404 try {
4405 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004406 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004407 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4408 + ", Exception" + e.getMessage());
4409 }
4410 break;
4411 }
4412 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004413 throw new IllegalArgumentException("Tried to set provisioning for "
4414 + "MmTel capability '" + capability + "', which does not require "
4415 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004416 }
4417 }
4418
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422 }
4423
4424 @Override
4425 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4426 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4427 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4428 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4429 }
4430 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004434 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004435 return true;
4436 }
4437
4438 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4439 switch (capability) {
4440 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4441 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4442 return ims.isVolteProvisionedOnDevice();
4443 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4444 return ims.isWfcProvisionedOnDevice();
4445 }
4446 // This should never happen, since we are checking tech above to make sure it
4447 // is either LTE or IWLAN.
4448 throw new IllegalArgumentException("Invalid radio technology for voice "
4449 + "capability.");
4450 }
4451 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4452 // There is currently no difference in VT provisioning type.
4453 return ims.isVtProvisionedOnDevice();
4454 }
4455 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4456 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4457 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4458 }
4459 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004460 throw new IllegalArgumentException(
4461 "Tried to get provisioning for MmTel capability '" + capability
4462 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 }
4464 }
4465
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4473 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4474 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4475 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4476 }
4477 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4478 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4479 return (provisionedBits & capability) > 0;
4480 }
4481
4482 @Override
4483 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4484 boolean isProvisioned) {
4485 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4486 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4487 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4488 }
4489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4490 "setProvisioningStatusForCapability");
4491 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4492 // If the current provisioning status for capability already matches isProvisioned,
4493 // do nothing.
4494 if (((provisionedBits & capability) > 0) == isProvisioned) {
4495 return;
4496 }
4497 if (isProvisioned) {
4498 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4499 } else {
4500 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4501 }
4502 }
4503
4504 /**
4505 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4506 * technology. The bitfield should mirror the bitfield defined by
4507 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4508 */
4509 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4510 String key = getMmTelProvisioningKey(subId, tech);
4511 // Default is no capabilities are provisioned.
4512 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4513 }
4514
4515 /**
4516 * Sets the MmTel capability provisioning bitfield (defined by
4517 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4518 * technology specified.
4519 *
4520 * Note: This is a synchronous command and should not be called on UI thread.
4521 */
4522 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4523 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4524 String key = getMmTelProvisioningKey(subId, tech);
4525 editor.putInt(key, newField);
4526 editor.commit();
4527 }
4528
4529 private static String getMmTelProvisioningKey(int subId, int tech) {
4530 // resulting key is provision_ims_mmtel_{subId}_{tech}
4531 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4532 }
4533
4534 /**
4535 * Query CarrierConfig to see if the specified capability requires provisioning for the
4536 * carrier associated with the subscription id.
4537 */
4538 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4539 int capability) {
4540 CarrierConfigManager configManager = new CarrierConfigManager(context);
4541 PersistableBundle c = configManager.getConfigForSubId(subId);
4542 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004543 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004544 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4545 false);
4546 boolean requireVoiceVtProvisioning = c.getBoolean(
4547 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4548
4549 // First check to make sure that the capability requires provisioning.
4550 switch (capability) {
4551 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4552 // intentional fallthrough
4553 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4554 if (requireVoiceVtProvisioning) {
4555 // Voice and Video requires provisioning
4556 return true;
4557 }
4558 break;
4559 }
4560 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4561 if (requireUtProvisioning) {
4562 // UT requires provisioning
4563 return true;
4564 }
4565 break;
4566 }
4567 }
4568 return false;
4569 }
4570
allenwtsu99c623b2020-01-03 18:24:23 +08004571 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4572 int capability) {
4573 CarrierConfigManager configManager = new CarrierConfigManager(context);
4574 PersistableBundle c = configManager.getConfigForSubId(subId);
4575
4576 boolean requireRcsProvisioning = c.getBoolean(
4577 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4578
4579 // First check to make sure that the capability requires provisioning.
4580 switch (capability) {
4581 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4582 // intentional fallthrough
4583 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4584 if (requireRcsProvisioning) {
4585 // OPTION or PRESENCE requires provisioning
4586 return true;
4587 }
4588 break;
4589 }
4590 }
4591 return false;
4592 }
4593
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004594 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004595 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4597 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4598 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004599 enforceReadPrivilegedPermission("getImsProvisioningInt");
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004603 int slotId = getSlotIndex(subId);
4604 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4605 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4606 + subId + "' for key:" + key);
4607 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4608 }
4609 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004610 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004611 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4612 + subId + "' for key:" + key);
4613 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
4617 }
4618
4619 @Override
4620 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4622 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4623 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004624 enforceReadPrivilegedPermission("getImsProvisioningString");
4625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 int slotId = getSlotIndex(subId);
4629 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4630 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4631 + subId + "' for key:" + key);
4632 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4633 }
4634 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004636 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4637 + subId + "' for key:" + key);
4638 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
4644 @Override
4645 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4647 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4648 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4650 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 int slotId = getSlotIndex(subId);
4655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4656 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4657 + subId + "' for key:" + key);
4658 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4659 }
4660 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4663 + "' for key:" + key);
4664 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
4670 @Override
4671 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4673 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4674 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4676 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 int slotId = getSlotIndex(subId);
4681 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4682 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4683 + subId + "' for key:" + key);
4684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4685 }
4686 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004687 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4689 + "' for key:" + key);
4690 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004696 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 int slotId = SubscriptionManager.getSlotIndex(subId);
4698 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004699 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4700 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004701 }
4702 return slotId;
4703 }
4704
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 private int getSlotIndex(int subId) {
4706 int slotId = SubscriptionManager.getSlotIndex(subId);
4707 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4708 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4709 }
4710 return slotId;
4711 }
4712
Wink Saville36469e72014-06-11 15:17:00 -07004713 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004714 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004715 */
4716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004717 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4718 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004719 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004720 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004721 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004722 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004723 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004724 mApp, subId, callingPackage, callingFeatureId,
4725 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004726 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4727 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 final Phone phone = getPhone(subId);
4732 if (phone != null) {
4733 return phone.getServiceState().getDataNetworkType();
4734 } else {
4735 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4736 }
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004740 }
4741
4742 /**
4743 * Returns the data network type
4744 */
4745 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004746 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4747 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4748 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004749 }
4750
4751 /**
4752 * Returns the data network type for a subId
4753 */
4754 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004755 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004758 mApp, subId, callingPackage, callingFeatureId,
4759 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4761 }
4762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 final Phone phone = getPhone(subId);
4766 if (phone != null) {
4767 return phone.getServiceState().getDataNetworkType();
4768 } else {
4769 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4770 }
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004774 }
4775
4776 /**
Wink Saville36469e72014-06-11 15:17:00 -07004777 * Returns the Voice network type for a subId
4778 */
4779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004780 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4781 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004783 mApp, subId, callingPackage, callingFeatureId,
4784 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4786 }
4787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788 final long identity = Binder.clearCallingIdentity();
4789 try {
4790 final Phone phone = getPhone(subId);
4791 if (phone != null) {
4792 return phone.getServiceState().getVoiceNetworkType();
4793 } else {
4794 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4795 }
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004799 }
4800
4801 /**
4802 * @return true if a ICC card is present
4803 */
4804 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004805 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004806 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4807 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004808 }
4809
4810 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004811 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004812 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004813 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004814 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 final Phone phone = PhoneFactory.getPhone(slotIndex);
4818 if (phone != null) {
4819 return phone.getIccCard().hasIccCard();
4820 } else {
4821 return false;
4822 }
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004826 }
4827
4828 /**
4829 * Return if the current radio is LTE on CDMA. This
4830 * is a tri-state return value as for a period of time
4831 * the mode may be unknown.
4832 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004833 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004834 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004835 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004836 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004838 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4839 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4840 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004841 }
4842
Sanket Padawe356d7632015-06-22 14:03:32 -07004843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004844 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4845 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004846 try {
4847 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4848 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004849 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4850 }
4851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 final Phone phone = getPhone(subId);
4855 if (phone == null) {
4856 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4857 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004858 return TelephonyProperties.lte_on_cdma_device()
4859 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 }
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004863 }
Wink Saville36469e72014-06-11 15:17:00 -07004864 }
4865
Wink Saville36469e72014-06-11 15:17:00 -07004866 /**
4867 * {@hide}
4868 * Returns Default subId, 0 in the case of single standby.
4869 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004870 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004871 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004872 }
4873
Shishir Agrawala9f32182016-04-12 12:00:16 -07004874 private int getSlotForDefaultSubscription() {
4875 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4876 }
4877
Wink Savilleb564aae2014-10-23 10:18:09 -07004878 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004879 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004880 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004881
Pengquan Menge92a50d2018-09-21 15:54:48 -07004882 private boolean isActiveSubscription(int subId) {
4883 return mSubscriptionController.isActiveSubId(subId);
4884 }
4885
Ihab Awadf2177b72013-11-25 13:33:23 -08004886 /**
4887 * @see android.telephony.TelephonyManager.WifiCallingChoices
4888 */
4889 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 final long identity = Binder.clearCallingIdentity();
4891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004892 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4894 getWhenToMakeWifiCallsDefaultPreference());
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004898 }
4899
4900 /**
4901 * @see android.telephony.TelephonyManager.WifiCallingChoices
4902 */
4903 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004907 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004912 }
4913
Sailesh Nepald1e68152013-12-12 19:08:02 -08004914 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004915 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004916 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004917 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004918
Jordan Liu4c733742019-02-28 12:03:40 -08004919 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4920 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4921 if (phoneId == -1) {
4922 throw new IllegalArgumentException("Given slot index: " + slotIndex
4923 + " does not correspond to an active phone");
4924 }
4925 return PhoneFactory.getPhone(phoneId);
4926 }
4927
Shishir Agrawal566b7612013-10-28 14:41:00 -07004928 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004929 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4930 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4932 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004934 if (DBG) {
4935 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4936 }
4937 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4938 p2);
4939 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004940
Jordan Liu4c733742019-02-28 12:03:40 -08004941
4942 @Override
4943 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4944 int slotIndex, String callingPackage, String aid, int p2) {
4945 enforceModifyPermission();
4946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4947 if (DBG) {
4948 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4949 }
4950 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4951 callingPackage, aid, p2);
4952 }
4953
4954 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4955 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 if (TextUtils.equals(ISDR_AID, aid)) {
4959 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004960 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4961 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 if (bestComponent == null
4963 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4964 loge("The calling package is not allowed to access ISD-R.");
4965 throw new SecurityException(
4966 "The calling package is not allowed to access ISD-R.");
4967 }
Derek Tan740e1672017-06-27 14:56:27 -07004968 }
Derek Tan740e1672017-06-27 14:56:27 -07004969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004971 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4972 null /* workSource */);
4973 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 return response;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 }
4979
4980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004981 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4983 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004984 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4985 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4986 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004987
Jordan Liu4c733742019-02-28 12:03:40 -08004988 @Override
4989 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4990 enforceModifyPermission();
4991 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4992 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4993 channel);
4994 }
4995
4996 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997 final long identity = Binder.clearCallingIdentity();
4998 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 if (channel < 0) {
5000 return false;
5001 }
Jordan Liu4c733742019-02-28 12:03:40 -08005002 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5003 null /* workSource */);
5004 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 return success;
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005008 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005009 }
5010
5011 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005012 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005013 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5015 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005016 if (DBG) {
5017 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5018 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5019 + p3 + " data=" + data);
5020 }
5021 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5022 command, p1, p2, p3, data);
5023 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005024
Jordan Liu4c733742019-02-28 12:03:40 -08005025 @Override
5026 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5027 int command, int p1, int p2, int p3, String data) {
5028 enforceModifyPermission();
5029 if (DBG) {
5030 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5031 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5032 + p3 + " data=" + data);
5033 }
5034 return iccTransmitApduLogicalChannelWithPermission(
5035 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5036 data);
5037 }
5038
5039 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5040 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
5042 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005043 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 return "";
5045 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005048 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5049 null /* workSource */);
5050 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 // Append the returned status code to the end of the response payload.
5053 String s = Integer.toHexString(
5054 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5055 if (response.payload != null) {
5056 s = IccUtils.bytesToHexString(response.payload) + s;
5057 }
5058 return s;
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005062 }
Jake Hambye994d462014-02-03 13:10:13 -08005063
Evan Charltonc66da362014-05-16 14:06:40 -07005064 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005065 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5066 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5068 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005070 if (DBG) {
5071 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5072 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5073 }
5074 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5075 cla, command, p1, p2, p3, data);
5076 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005077
Jordan Liu4c733742019-02-28 12:03:40 -08005078 @Override
5079 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5080 int command, int p1, int p2, int p3, String data) {
5081 enforceModifyPermission();
5082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5083 if (DBG) {
5084 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5085 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5086 + " data=" + data);
5087 }
5088
5089 return iccTransmitApduBasicChannelWithPermission(
5090 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5091 p2, p3, data);
5092 }
5093
5094 // open APDU basic channel assuming the caller has sufficient permissions
5095 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5096 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5100 && TextUtils.equals(ISDR_AID, data)) {
5101 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005102 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5103 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 if (bestComponent == null
5105 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5106 loge("The calling package is not allowed to select ISD-R.");
5107 throw new SecurityException(
5108 "The calling package is not allowed to select ISD-R.");
5109 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005110 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005113 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5114 null /* workSource */);
5115 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 // Append the returned status code to the end of the response payload.
5118 String s = Integer.toHexString(
5119 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5120 if (response.payload != null) {
5121 s = IccUtils.bytesToHexString(response.payload) + s;
5122 }
5123 return s;
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005126 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005127 }
5128
5129 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005130 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005131 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5133 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
5137 if (DBG) {
5138 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5139 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5140 }
5141
5142 IccIoResult response =
5143 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5144 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5145 subId);
5146
5147 if (DBG) {
5148 log("Exchange SIM_IO [R]" + response);
5149 }
5150
5151 byte[] result = null;
5152 int length = 2;
5153 if (response.payload != null) {
5154 length = 2 + response.payload.length;
5155 result = new byte[length];
5156 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5157 } else {
5158 result = new byte[length];
5159 }
5160
5161 result[length - 1] = (byte) response.sw2;
5162 result[length - 2] = (byte) response.sw1;
5163 return result;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005166 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005167 }
5168
Nathan Haroldb3014052017-01-25 15:57:32 -08005169 /**
5170 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5171 * on a particular subscription
5172 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005173 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5174 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005176 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005177 return null;
5178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179
5180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 if (appType != TelephonyManager.APPTYPE_USIM
5183 && appType != TelephonyManager.APPTYPE_SIM) {
5184 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5185 return null;
5186 }
5187 Object response = sendRequest(
5188 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5189 if (response instanceof String[]) {
5190 return (String[]) response;
5191 }
yincheng zhao2737e882019-09-06 17:06:54 -07005192 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005194 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 } finally {
5196 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005197 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005198 }
5199
yincheng zhao2737e882019-09-06 17:06:54 -07005200 /**
5201 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5202 * subscription.
5203 *
5204 * @param subId the id of the subscription.
5205 * @param appType the uicc app type, must be USIM or SIM.
5206 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5207 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005208 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005209 * @return number of fplmns that is successfully written to the SIM.
5210 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005211 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5212 String callingFeatureId) {
5213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5214 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005215 if (DBG) logv("no permissions for setForbiddenplmns");
5216 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5217 }
5218 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5219 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5220 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5221 }
5222 if (fplmns == null) {
5223 throw new IllegalArgumentException("Fplmn List provided is null");
5224 }
5225 for (String fplmn : fplmns) {
5226 if (!CellIdentity.isValidPlmn(fplmn)) {
5227 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5228 }
5229 }
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 Object response = sendRequest(
5233 CMD_SET_FORBIDDEN_PLMNS,
5234 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5235 subId);
5236 return (int) response;
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
5240 }
5241
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005243 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5245 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5250 if (response.payload == null) {
5251 return "";
5252 }
Evan Charltonc66da362014-05-16 14:06:40 -07005253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 // Append the returned status code to the end of the response payload.
5255 String s = Integer.toHexString(
5256 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5257 s = IccUtils.bytesToHexString(response.payload) + s;
5258 return s;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Evan Charltonc66da362014-05-16 14:06:40 -07005262 }
5263
Jake Hambye994d462014-02-03 13:10:13 -08005264 /**
5265 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5266 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5267 *
5268 * @param itemID the ID of the item to read
5269 * @return the NV item as a String, or null on error.
5270 */
5271 @Override
5272 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5275 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005280 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5282 return value;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Jake Hambye994d462014-02-03 13:10:13 -08005286 }
5287
5288 /**
5289 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5290 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5291 *
5292 * @param itemID the ID of the item to read
5293 * @param itemValue the value to write, as a String
5294 * @return true on success; false on any failure
5295 */
5296 @Override
5297 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005298 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5305 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005306 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5308 return success;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Jake Hambye994d462014-02-03 13:10:13 -08005312 }
5313
5314 /**
5315 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5316 * Used for device configuration by some CDMA operators.
5317 *
5318 * @param preferredRoamingList byte array containing the new PRL
5319 * @return true on success; false on any failure
5320 */
5321 @Override
5322 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5324 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5329 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5330 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5331 return success;
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Jake Hambye994d462014-02-03 13:10:13 -08005335 }
5336
5337 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005338 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005339 * Used for device configuration by some CDMA operators.
5340 *
chen xu6dac5ab2018-10-26 17:39:23 -07005341 * @param slotIndex - device slot.
5342 *
Jake Hambye994d462014-02-03 13:10:13 -08005343 * @return true on success; false on any failure
5344 */
5345 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005346 public boolean resetModemConfig(int slotIndex) {
5347 Phone phone = PhoneFactory.getPhone(slotIndex);
5348 if (phone != null) {
5349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
chen xu6dac5ab2018-10-26 17:39:23 -07005352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5355 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5356 return success;
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 }
chen xu6dac5ab2018-10-26 17:39:23 -07005361 return false;
5362 }
5363
5364 /**
5365 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5366 *
5367 * @param slotIndex - device slot.
5368 *
5369 * @return true on success; false on any failure
5370 */
5371 @Override
5372 public boolean rebootModem(int slotIndex) {
5373 Phone phone = PhoneFactory.getPhone(slotIndex);
5374 if (phone != null) {
5375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5376 mApp, phone.getSubId(), "rebootModem");
5377
5378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5381 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5382 return success;
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
5386 }
5387 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005388 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005389
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005390 public String[] getPcscfAddress(String apnType, String callingPackage,
5391 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005392 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5394 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005395 return new String[0];
5396 }
5397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005400 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
Wink Saville36469e72014-06-11 15:17:00 -07005404 }
5405
Brad Ebinger51f743a2017-01-23 13:50:20 -08005406 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005407 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5408 * {@link #disableIms(int)}.
5409 * @param slotIndex device slot.
5410 */
5411 public void resetIms(int slotIndex) {
5412 enforceModifyPermission();
5413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (mImsResolver == null) {
5417 // may happen if the does not support IMS.
5418 return;
5419 }
5420 mImsResolver.disableIms(slotIndex);
5421 mImsResolver.enableIms(slotIndex);
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
5425 }
5426
5427 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5429 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005430 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005431 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -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 Ebinger9c0eb502019-01-23 15:06:19 -08005437 // may happen if the device does not support IMS.
5438 return;
5439 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005440 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005444 }
5445
5446 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005447 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5448 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005449 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005450 public void disableIms(int slotId) {
5451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005455 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005456 // may happen if the device does not support IMS.
5457 return;
5458 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005459 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005463 }
5464
5465 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005466 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5467 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005468 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005469 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005470 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472
5473 final long identity = Binder.clearCallingIdentity();
5474 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005475 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005476 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5477 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005478 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005479 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005483 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005484 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005485 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5486 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005487 @Override
5488 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005489 enforceModifyPermission();
5490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005494 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
5498 }
5499
5500 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005501 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005502 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005503 */
5504 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005510 // may happen if the device does not support IMS.
5511 return null;
5512 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005513 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005517 }
5518
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005519 /**
5520 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005521 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005522 */
5523 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525
5526 final long identity = Binder.clearCallingIdentity();
5527 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005528 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005529 // may happen if the device does not support IMS.
5530 return null;
5531 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005532 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005536 }
5537
Brad Ebinger884c07b2018-02-15 16:17:40 -08005538 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005539 * Sets the ImsService Package Name that Telephony will bind to.
5540 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005541 * @param slotIndex the slot ID that the ImsService should bind for.
5542 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005543 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005544 * @param featureTypes An integer array of feature types associated with a packageName.
5545 * @param packageName The name of the package that the current configuration will be replaced
5546 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005547 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005548 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005549 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5550 int[] featureTypes, String packageName) {
5551 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5554 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005555 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005559 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005560 // may happen if the device does not support IMS.
5561 return false;
5562 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005563 Map<Integer, String> featureConfig = new HashMap<>();
5564 for (int featureType : featureTypes) {
5565 featureConfig.put(featureType, packageName);
5566 }
5567 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5568 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005572 }
5573
5574 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005575 * Clears any carrier ImsService overrides for the slot index specified that were previously
5576 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5577 *
5578 * This should only be used for testing.
5579 *
5580 * @param slotIndex the slot ID that the ImsService should bind for.
5581 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5582 */
5583 @Override
5584 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5585 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5587 "clearCarrierImsServiceOverride");
5588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5589 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5590 "clearCarrierImsServiceOverride");
5591
5592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 if (mImsResolver == null) {
5595 // may happen if the device does not support IMS.
5596 return false;
5597 }
5598 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603
5604 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005605 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005606 *
5607 * @param slotId The slot that the ImsService is associated with.
5608 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5609 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005610 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005611 * @return the package name of the ImsService configuration.
5612 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005613 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5614 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005615 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005616 TelephonyPermissions
5617 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5618 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5619 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005623 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005624 // may happen if the device does not support IMS.
5625 return "";
5626 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005627 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005628 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5629 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005633 }
5634
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005635 /**
5636 * Get the MmTelFeature state associated with the requested subscription id.
5637 * @param subId The subscription that the MmTelFeature is associated with.
5638 * @param callback A callback with an integer containing the
5639 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5640 */
5641 @Override
5642 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5643 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5644 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5646 "IMS not available on device.");
5647 }
5648 final long token = Binder.clearCallingIdentity();
5649 try {
5650 int slotId = getSlotIndex(subId);
5651 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5652 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5653 + subId + "'");
5654 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5655 }
5656 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5657 try {
5658 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5659 } catch (RemoteException e) {
5660 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5661 + "Ignore");
5662 }
5663 });
5664 } finally {
5665 Binder.restoreCallingIdentity(token);
5666 }
5667 }
5668
Daniel Brightbb5840b2021-01-12 15:48:18 -08005669 /**
5670 * Sets the ims registration state on all valid {@link Phone}s.
5671 */
5672 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005677 // NOTE: Before S, this method only set the default phone.
5678 for (final Phone phone : PhoneFactory.getPhones()) {
5679 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5680 phone.setImsRegistrationState(registered);
5681 }
5682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Wink Saville36469e72014-06-11 15:17:00 -07005686 }
5687
5688 /**
Stuart Scott54788802015-03-30 13:18:01 -07005689 * Set the network selection mode to automatic.
5690 *
5691 */
5692 @Override
5693 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696
5697 final long identity = Binder.clearCallingIdentity();
5698 try {
shilufc958392020-01-20 11:36:01 -08005699 if (!isActiveSubscription(subId)) {
5700 return;
5701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5703 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Stuart Scott54788802015-03-30 13:18:01 -07005707 }
5708
Jack Yud10cdd42020-09-28 20:28:01 -07005709 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005710 * Ask the radio to connect to the input network and change selection mode to manual.
5711 *
5712 * @param subId the id of the subscription.
5713 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5714 * the operator to attach to.
5715 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5716 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5717 * normal network selection next time.
5718 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005719 */
5720 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005721 public boolean setNetworkSelectionModeManual(
5722 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005725
5726 if (!isActiveSubscription(subId)) {
5727 return false;
5728 }
5729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005732 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005734 if (DBG) {
5735 log("setNetworkSelectionModeManual: subId: " + subId
5736 + " operator: " + operatorInfo);
5737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005742 }
shilu84f6e8b2019-12-19 13:58:01 -08005743 /**
5744 * Get the manual network selection
5745 *
5746 * @param subId the id of the subscription.
5747 *
5748 * @return the previously saved user selected PLMN
5749 */
5750 @Override
5751 public String getManualNetworkSelectionPlmn(int subId) {
5752 TelephonyPermissions
5753 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5754 mApp, subId, "getManualNetworkSelectionPlmn");
5755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005759 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005760 }
5761
5762 final Phone phone = getPhone(subId);
5763 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005764 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005765 }
5766 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5767 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5768 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005773
5774 /**
5775 * Scans for available networks.
5776 */
5777 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005778 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5781 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005782 LocationAccessPolicy.LocationPermissionResult locationResult =
5783 LocationAccessPolicy.checkLocationPermission(mApp,
5784 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5785 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005786 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005787 .setCallingPid(Binder.getCallingPid())
5788 .setCallingUid(Binder.getCallingUid())
5789 .setMethod("getCellNetworkScanResults")
5790 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005791 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5792 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005793 .build());
5794 switch (locationResult) {
5795 case DENIED_HARD:
5796 throw new SecurityException("Not allowed to access scan results -- location");
5797 case DENIED_SOFT:
5798 return null;
5799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
Pengquan Menga1bb6272018-09-06 09:59:22 -07005801 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 try {
5803 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005804 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005809 }
5810
5811 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005812 * Get the call forwarding info, given the call forwarding reason.
5813 */
5814 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005815 public void getCallForwarding(int subId, int callForwardingReason,
5816 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005817 enforceReadPrivilegedPermission("getCallForwarding");
5818 long identity = Binder.clearCallingIdentity();
5819 try {
5820 if (DBG) {
5821 log("getCallForwarding: subId " + subId
5822 + " callForwardingReason" + callForwardingReason);
5823 }
Hall Liu27d24262020-09-18 19:04:59 -07005824
5825 Phone phone = getPhone(subId);
5826 if (phone == null) {
5827 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005828 callback.onError(
5829 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005830 } catch (RemoteException e) {
5831 // ignore
5832 }
5833 return;
5834 }
5835
5836 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5837 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5838 @Override
5839 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5840 try {
5841 callback.onCallForwardingInfoAvailable(info);
5842 } catch (RemoteException e) {
5843 // ignore
5844 }
5845 }
5846
5847 @Override
5848 public void onError(int error) {
5849 try {
5850 callback.onError(error);
5851 } catch (RemoteException e) {
5852 // ignore
5853 }
5854 }
5855 });
5856 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 /**
5863 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5864 * reason, the number to forward, and the timeout before the forwarding is attempted.
5865 */
5866 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005867 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5868 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005869 enforceModifyPermission();
5870 long identity = Binder.clearCallingIdentity();
5871 try {
5872 if (DBG) {
5873 log("setCallForwarding: subId " + subId
5874 + " callForwardingInfo" + callForwardingInfo);
5875 }
Hall Liu27d24262020-09-18 19:04:59 -07005876
5877 Phone phone = getPhone(subId);
5878 if (phone == null) {
5879 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005880 callback.accept(
5881 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005882 } catch (RemoteException e) {
5883 // ignore
5884 }
5885 return;
5886 }
5887
5888 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5889 FunctionalUtils.ignoreRemoteException(callback::accept));
5890
5891 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
5895 }
5896
5897 /**
Hall Liu27d24262020-09-18 19:04:59 -07005898 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005899 */
5900 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005901 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005902 enforceReadPrivilegedPermission("getCallForwarding");
5903 long identity = Binder.clearCallingIdentity();
5904 try {
Hall Liu27d24262020-09-18 19:04:59 -07005905
5906 Phone phone = getPhone(subId);
5907 if (phone == null) {
5908 try {
5909 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5910 } catch (RemoteException e) {
5911 // ignore
5912 }
5913 return;
5914 }
5915
5916 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5917
Shuo Qian4a594052020-01-23 11:59:30 -08005918 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005919 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005920 } finally {
5921 Binder.restoreCallingIdentity(identity);
5922 }
5923 }
5924
5925 /**
Hall Liu27d24262020-09-18 19:04:59 -07005926 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005927 */
5928 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005929 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005930 enforceModifyPermission();
5931 long identity = Binder.clearCallingIdentity();
5932 try {
Hall Liu27d24262020-09-18 19:04:59 -07005933 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5934
5935 Phone phone = getPhone(subId);
5936 if (phone == null) {
5937 try {
5938 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5939 } catch (RemoteException e) {
5940 // ignore
5941 }
5942 return;
5943 }
5944
5945 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5946 FunctionalUtils.ignoreRemoteException(callback::accept));
5947
5948 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005949 } finally {
5950 Binder.restoreCallingIdentity(identity);
5951 }
5952 }
5953
5954 /**
yinxub1bed742017-04-17 11:45:04 -07005955 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005956 *
yinxub1bed742017-04-17 11:45:04 -07005957 * @param subId id of the subscription
5958 * @param request contains the radio access networks with bands/channels to scan
5959 * @param messenger callback messenger for scan results or errors
5960 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005961 * @return the id of the requested scan which can be used to stop the scan.
5962 */
5963 @Override
5964 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005965 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5967 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005968 LocationAccessPolicy.LocationPermissionResult locationResult =
5969 LocationAccessPolicy.checkLocationPermission(mApp,
5970 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5971 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005972 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005973 .setCallingPid(Binder.getCallingPid())
5974 .setCallingUid(Binder.getCallingUid())
5975 .setMethod("requestNetworkScan")
5976 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005977 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5978 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005979 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005980 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005981 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5982 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005983 if (e != null) {
5984 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5985 throw e;
5986 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005987 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005988 return TelephonyScanManager.INVALID_SCAN_ID;
5989 }
5990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 }
Hall Liu912dfd32019-04-25 14:02:26 -07005992 int callingUid = Binder.getCallingUid();
5993 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005994 final long identity = Binder.clearCallingIdentity();
5995 try {
5996 return mNetworkScanRequestTracker.startNetworkScan(
5997 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005998 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
yinxu504e1392017-04-12 16:03:22 -07006002 }
6003
Hall Liub2ac8ef2019-02-28 15:56:23 -08006004 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006005 NetworkScanRequest request, int subId, String callingPackage) {
6006 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006007 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6008 boolean hasNetworkScanPermission =
6009 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6010 == PERMISSION_GRANTED;
6011
6012 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6013 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6014 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006015 }
6016
6017 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6018 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006019 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6020 return new SecurityException("Specific channels must not be"
6021 + " scanned without location access.");
6022 }
6023 }
6024 }
6025
Hall Liub2ac8ef2019-02-28 15:56:23 -08006026 return null;
6027 }
6028
yinxu504e1392017-04-12 16:03:22 -07006029 /**
6030 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006031 *
6032 * @param subId id of the subscription
6033 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006034 */
6035 @Override
6036 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6038 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039
Hall Liu912dfd32019-04-25 14:02:26 -07006040 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 final long identity = Binder.clearCallingIdentity();
6042 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006043 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
yinxu504e1392017-04-12 16:03:22 -07006047 }
6048
6049 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006050 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006051 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006052 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006053 */
6054 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006055 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006056 TelephonyPermissions
6057 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006058 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059
6060 final long identity = Binder.clearCallingIdentity();
6061 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006062 if (DBG) log("getAllowedNetworkTypesBitmask");
6063 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6064 int networkTypesBitmask = (result != null ? result[0] : -1);
6065 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6066 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006070 }
6071
6072 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006073 * Get the allowed network types for certain reason.
6074 *
6075 * @param subId the id of the subscription.
6076 * @param reason the reason the allowed network type change is taking place
6077 * @return the allowed network types.
6078 */
6079 @Override
6080 public long getAllowedNetworkTypesForReason(int subId,
6081 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6082 TelephonyPermissions
6083 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6084 mApp, subId, "getAllowedNetworkTypesForReason");
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
6091 }
6092
6093 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006094 * Enable/Disable E-UTRA-NR Dual Connectivity
6095 * @param subId subscription id of the sim card
6096 * @param nrDualConnectivityState expected NR dual connectivity state
6097 * This can be passed following states
6098 * <ol>
6099 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6100 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6101 * <li>Disable NR dual connectivity and force secondary cell to be released
6102 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6103 * </ol>
6104 * @return operation result.
6105 */
6106 @Override
6107 public int setNrDualConnectivityState(int subId,
6108 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6110 mApp, subId, "enableNRDualConnectivity");
6111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6115 nrDualConnectivityState, subId,
6116 workSource);
6117 if (DBG) log("enableNRDualConnectivity result: " + result);
6118 return result;
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
6122 }
6123
6124 /**
6125 * Is E-UTRA-NR Dual Connectivity enabled
6126 * @return true if dual connectivity is enabled else false
6127 */
6128 @Override
6129 public boolean isNrDualConnectivityEnabled(int subId) {
6130 TelephonyPermissions
6131 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6132 mApp, subId, "isNRDualConnectivityEnabled");
6133 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6137 null, subId, workSource);
6138 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6139 return isEnabled;
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
6143 }
6144
6145 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006146 * get carrier bandwidth per primary and secondary carrier
6147 * @param subId subscription id of the sim card
6148 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6149 */
6150 @Override
6151 public CarrierBandwidth getCarrierBandwidth(int subId) {
6152 TelephonyPermissions
6153 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6154 mApp, subId, "isNRDualConnectivityEnabled");
6155 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6156 final long identity = Binder.clearCallingIdentity();
6157 try {
6158 CarrierBandwidth carrierBandwidth =
6159 getPhoneFromSubId(subId).getCarrierBandwidth();
6160 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6161 return carrierBandwidth;
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
6165 }
6166
6167 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006168 * Set the allowed network types of the device and
6169 * provide the reason triggering the allowed network change.
6170 *
6171 * @param subId the id of the subscription.
6172 * @param reason the reason the allowed network type change is taking place
6173 * @param allowedNetworkTypes the allowed network types.
6174 * @return true on success; false on any failure.
6175 */
6176 @Override
6177 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006178 @TelephonyManager.AllowedNetworkTypesReason int reason,
6179 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6181 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006182 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6183 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6184 return false;
6185 }
6186
6187 if (DBG) {
6188 log("setAllowedNetworkTypesForReason: " + reason
6189 + " value: " + allowedNetworkTypes);
6190 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006191 final long identity = Binder.clearCallingIdentity();
6192 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006193 Boolean success = (Boolean) sendRequest(
6194 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6195 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6196
6197 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6198 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
6202 }
6203
6204 /**
Miaoa84611c2019-03-15 09:21:10 +08006205 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006206 *
Miaoa84611c2019-03-15 09:21:10 +08006207 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006208 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006209 * @hide
6210 */
6211 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006212 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006213 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006215 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 try {
Miaoa84611c2019-03-15 09:21:10 +08006217 if (phone != null) {
6218 return phone.hasMatchedTetherApnSetting();
6219 } else {
6220 return false;
6221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006224 }
Junda Liu475951f2014-11-07 16:45:03 -08006225 }
6226
6227 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006228 * Enable or disable always reporting signal strength changes from radio.
6229 *
6230 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6231 */
6232 @Override
6233 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6234 enforceModifyPermission();
6235 enforceSystemCaller();
6236
6237 final long identity = Binder.clearCallingIdentity();
6238 final Phone phone = getPhone(subId);
6239 try {
6240 if (phone != null) {
6241 if (DBG) {
6242 log("setAlwaysReportSignalStrength: subId=" + subId
6243 + " isEnable=" + isEnable);
6244 }
6245 phone.setAlwaysReportSignalStrength(isEnable);
6246 } else {
6247 loge("setAlwaysReportSignalStrength: no phone found for subId="
6248 + subId);
6249 }
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
6253 }
6254
6255 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006256 * Get the user enabled state of Mobile Data.
6257 *
6258 * TODO: remove and use isUserDataEnabled.
6259 * This can't be removed now because some vendor codes
6260 * calls through ITelephony directly while they should
6261 * use TelephonyManager.
6262 *
6263 * @return true on enabled
6264 */
6265 @Override
6266 public boolean getDataEnabled(int subId) {
6267 return isUserDataEnabled(subId);
6268 }
6269
6270 /**
6271 * Get whether mobile data is enabled per user setting.
6272 *
6273 * There are other factors deciding whether mobile data is actually enabled, but they are
6274 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006275 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006276 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006277 *
6278 * @return {@code true} if data is enabled else {@code false}
6279 */
6280 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006281 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006282 try {
6283 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6284 null);
6285 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289
6290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 int phoneId = mSubscriptionController.getPhoneId(subId);
6293 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6294 Phone phone = PhoneFactory.getPhone(phoneId);
6295 if (phone != null) {
6296 boolean retVal = phone.isUserDataEnabled();
6297 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6298 return retVal;
6299 } else {
6300 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6301 return false;
6302 }
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006305 }
6306 }
6307
6308 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006309 * Checks if the device is capable of mobile data by considering whether whether the
6310 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6311 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006312 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006313 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006314 */
6315 @Override
6316 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006317 try {
6318 try {
6319 mApp.enforceCallingOrSelfPermission(
6320 android.Manifest.permission.ACCESS_NETWORK_STATE,
6321 null);
6322 } catch (Exception e) {
6323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6324 "isDataEnabled");
6325 }
6326 } catch (Exception e) {
6327 enforceReadPrivilegedPermission("isDataEnabled");
6328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329
6330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 int phoneId = mSubscriptionController.getPhoneId(subId);
6333 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6334 Phone phone = PhoneFactory.getPhone(phoneId);
6335 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006336 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6338 return retVal;
6339 } else {
6340 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6341 return false;
6342 }
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006345 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006346 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006347
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006348 /**
6349 * Check if data is enabled for a specific reason
6350 * @param subId Subscription index
6351 * @param reason the reason the data enable change is taking place
6352 * @return {@code true} if the overall data is enabled; {@code false} if not.
6353 */
6354 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006355 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006356 @TelephonyManager.DataEnabledReason int reason) {
6357 try {
6358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6359 null);
6360 } catch (Exception e) {
6361 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006362 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006363 }
6364
6365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 int phoneId = mSubscriptionController.getPhoneId(subId);
6369 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006370 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006371 + " reason=" + reason);
6372 }
6373 Phone phone = PhoneFactory.getPhone(phoneId);
6374 if (phone != null) {
6375 boolean retVal;
6376 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6377 retVal = phone.isUserDataEnabled();
6378 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006379 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006380 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006381 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006382 return retVal;
6383 } else {
6384 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006385 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006386 + subId + " retVal=false");
6387 }
6388 return false;
6389 }
6390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
6393 }
6394
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006395 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006396 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006397 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6398 // Skip the check if it's one of these special uids
6399 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6400 }
6401
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006402 //load access rules from carrier configs, and check those as well: b/139133814
6403 SubscriptionController subController = SubscriptionController.getInstance();
6404 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6405 || subController == null) return privilegeFromSim;
6406
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006407 PackageManager pkgMgr = phone.getContext().getPackageManager();
6408 String[] packages = pkgMgr.getPackagesForUid(uid);
6409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006412 int subId = phone.getSubId();
6413 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6414 // A test override is in place for the privileges for this subId, so don't try to
6415 // read the subscription privileges.
6416 return privilegeFromSim;
6417 }
6418 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006419 SubscriptionManager subManager = (SubscriptionManager)
6420 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6421 for (String pkg : packages) {
6422 if (subManager.canManageSubscription(subInfo, pkg)) {
6423 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6424 }
6425 }
6426 return privilegeFromSim;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6433 String pkgName) {
6434 //load access rules from carrier configs, and check those as well: b/139133814
6435 SubscriptionController subController = SubscriptionController.getInstance();
6436 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6437 || subController == null) return privilegeFromSim;
6438
6439 final long identity = Binder.clearCallingIdentity();
6440 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006441 int subId = phone.getSubId();
6442 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6443 // A test override is in place for the privileges for this subId, so don't try to
6444 // read the subscription privileges.
6445 return privilegeFromSim;
6446 }
6447 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006448 SubscriptionManager subManager = (SubscriptionManager)
6449 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6450 return subManager.canManageSubscription(subInfo, pkgName)
6451 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
6456
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006458 public int getCarrierPrivilegeStatus(int subId) {
6459 final Phone phone = getPhone(subId);
6460 if (phone == null) {
6461 loge("getCarrierPrivilegeStatus: Invalid subId");
6462 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6463 }
6464 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006465 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006466 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006467 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6468 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006469
6470 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6471 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006472 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006473 }
Junda Liu29340342014-07-10 15:23:27 -07006474
6475 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006476 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006477 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006478 final Phone phone = getPhone(subId);
6479 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006480 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006481 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6482 }
6483 UiccProfile profile =
6484 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6485 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006486 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006487 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6488 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006489 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006490 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006491 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006492 }
6493
6494 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006495 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6496 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006497 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006498 }
6499
6500 int phoneId = SubscriptionManager.getPhoneId(subId);
6501 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006502 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006503 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006504 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6505 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006506 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6507 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6508 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006509 }
6510
6511 @Override
6512 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006513 if (TextUtils.isEmpty(pkgName))
6514 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006515 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6516 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6517 UiccCard card = UiccController.getInstance().getUiccCard(i);
6518 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006519 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006520 continue;
6521 }
6522
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006523 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6524 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6525 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006526 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6527 break;
6528 }
6529 }
6530
6531 return result;
Junda Liu29340342014-07-10 15:23:27 -07006532 }
Derek Tan89e89d42014-07-08 17:00:10 -07006533
6534 @Override
Junda Liue64de782015-04-16 17:19:16 -07006535 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6536 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6537 loge("phoneId " + phoneId + " is not valid.");
6538 return null;
6539 }
6540 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006541 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006542 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006543 return null ;
6544 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006545 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006546 }
6547
Amith Yamasani6e118872016-02-19 12:53:51 -08006548 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006549 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006550 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006551 List<String> privilegedPackages = new ArrayList<>();
6552 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006553 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6554 // has UICC in that slot.
6555 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006556 if (card.hasCarrierPrivilegeRules()) {
6557 if (packages == null) {
6558 // Only check packages in user 0 for now
6559 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006560 PackageManager.MATCH_DISABLED_COMPONENTS
6561 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006562 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006563 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006564 }
6565 for (int p = packages.size() - 1; p >= 0; p--) {
6566 PackageInfo pkgInfo = packages.get(p);
6567 if (pkgInfo != null && pkgInfo.packageName != null
6568 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006569 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006570 privilegedPackages.add(pkgInfo.packageName);
6571 }
6572 }
6573 }
6574 }
6575 return privilegedPackages;
6576 }
6577
chen xuf7e9fe82019-05-09 19:31:02 -07006578 @Override
6579 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006580 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6581
6582 final long identity = Binder.clearCallingIdentity();
6583
chen xuf7e9fe82019-05-09 19:31:02 -07006584 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006585 try {
6586 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6587 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6588 }
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006591 }
6592 return privilegedPackages;
6593 }
6594
Wink Savilleb564aae2014-10-23 10:18:09 -07006595 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006596 final Phone phone = getPhone(subId);
6597 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006598 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006599 return null;
6600 }
6601 String iccId = card.getIccId();
6602 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006603 return null;
6604 }
6605 return iccId;
6606 }
6607
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006608 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006609 public void setCallComposerStatus(int subId, int status) {
6610 enforceModifyPermission();
6611
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 Phone phone = getPhone(subId);
6615 if (phone != null) {
6616 Phone defaultPhone = phone.getImsPhone();
6617 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6618 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6619 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006620 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6621 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006622 }
6623 }
Shuo Qian284ae752020-12-22 19:10:14 -08006624 } catch (ImsException e) {
6625 throw new ServiceSpecificException(e.getCode());
6626 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006627 Binder.restoreCallingIdentity(identity);
6628 }
6629 }
6630
6631 @Override
6632 public int getCallComposerStatus(int subId) {
6633 enforceReadPrivilegedPermission("getCallComposerStatus");
6634
6635 final long identity = Binder.clearCallingIdentity();
6636 try {
6637 Phone phone = getPhone(subId);
6638 if (phone != null) {
6639 Phone defaultPhone = phone.getImsPhone();
6640 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6641 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6642 return imsPhone.getCallComposerStatus();
6643 }
6644 }
6645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
6648 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6649 }
6650
6651 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006652 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6653 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006654 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006655 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 final String iccId = getIccId(subId);
6660 final Phone phone = getPhone(subId);
6661 if (phone == null) {
6662 return false;
6663 }
6664 final String subscriberId = phone.getSubscriberId();
6665
6666 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006667 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 + subscriberId + " to " + number);
6669 }
6670
6671 if (TextUtils.isEmpty(iccId)) {
6672 return false;
6673 }
6674
6675 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6676
6677 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6678 if (alphaTag == null) {
6679 editor.remove(alphaTagPrefKey);
6680 } else {
6681 editor.putString(alphaTagPrefKey, alphaTag);
6682 }
6683
6684 // Record both the line number and IMSI for this ICCID, since we need to
6685 // track all merged IMSIs based on line number
6686 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6687 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6688 if (number == null) {
6689 editor.remove(numberPrefKey);
6690 editor.remove(subscriberPrefKey);
6691 } else {
6692 editor.putString(numberPrefKey, number);
6693 editor.putString(subscriberPrefKey, subscriberId);
6694 }
6695
6696 editor.commit();
6697 return true;
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006700 }
Derek Tan7226c842014-07-02 17:42:23 -07006701 }
6702
6703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006704 public String getLine1NumberForDisplay(int subId, String callingPackage,
6705 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006706 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006708 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006709 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006710 return null;
6711 }
Derek Tan97ebb422014-09-05 16:55:38 -07006712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 final long identity = Binder.clearCallingIdentity();
6714 try {
6715 String iccId = getIccId(subId);
6716 if (iccId != null) {
6717 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6718 if (DBG_MERGE) {
6719 log("getLine1NumberForDisplay returning "
6720 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6721 }
6722 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6725 return null;
6726 } finally {
6727 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006728 }
Derek Tan7226c842014-07-02 17:42:23 -07006729 }
6730
6731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006732 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006735 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006736 return null;
6737 }
Derek Tan97ebb422014-09-05 16:55:38 -07006738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 final long identity = Binder.clearCallingIdentity();
6740 try {
6741 String iccId = getIccId(subId);
6742 if (iccId != null) {
6743 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6744 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6745 }
6746 return null;
6747 } finally {
6748 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006749 }
Derek Tan7226c842014-07-02 17:42:23 -07006750 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006751
6752 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006753 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6754 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006755 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6756 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006758 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006759 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006760 return null;
6761 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006762
Jordan Liub49b04b2019-05-06 14:45:15 -07006763 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6764 // the process, where TelephonyManager was instantiated.
6765 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006766 final long identity = Binder.clearCallingIdentity();
6767 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006768 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 final TelephonyManager tele = TelephonyManager.from(context);
6770 final SubscriptionManager sub = SubscriptionManager.from(context);
6771
6772 // Figure out what subscribers are currently active
6773 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774
Jordan Liub49b04b2019-05-06 14:45:15 -07006775 // Only consider subs which match the current subId
6776 // This logic can be simplified. See b/131189269 for progress.
6777 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006778 activeSubscriberIds.add(tele.getSubscriberId(subId));
6779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780
6781 // First pass, find a number override for an active subscriber
6782 String mergeNumber = null;
6783 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6784 for (String key : prefs.keySet()) {
6785 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6786 final String subscriberId = (String) prefs.get(key);
6787 if (activeSubscriberIds.contains(subscriberId)) {
6788 final String iccId = key.substring(
6789 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6790 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6791 mergeNumber = (String) prefs.get(numberKey);
6792 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006793 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 + " for active subscriber " + subscriberId);
6795 }
6796 if (!TextUtils.isEmpty(mergeNumber)) {
6797 break;
6798 }
6799 }
6800 }
6801 }
6802
6803 // Shortcut when no active merged subscribers
6804 if (TextUtils.isEmpty(mergeNumber)) {
6805 return null;
6806 }
6807
6808 // Second pass, find all subscribers under that line override
6809 final ArraySet<String> result = new ArraySet<>();
6810 for (String key : prefs.keySet()) {
6811 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6812 final String number = (String) prefs.get(key);
6813 if (mergeNumber.equals(number)) {
6814 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6815 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6816 final String subscriberId = (String) prefs.get(subscriberKey);
6817 if (!TextUtils.isEmpty(subscriberId)) {
6818 result.add(subscriberId);
6819 }
6820 }
6821 }
6822 }
6823
6824 final String[] resultArray = result.toArray(new String[result.size()]);
6825 Arrays.sort(resultArray);
6826 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006827 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6829 }
6830 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006831 } finally {
6832 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006833 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006834 }
6835
6836 @Override
zoey chen38003472019-12-13 17:16:31 +08006837 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6838 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006839
6840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 final TelephonyManager telephonyManager = mApp.getSystemService(
6843 TelephonyManager.class);
6844 String subscriberId = telephonyManager.getSubscriberId(subId);
6845 if (subscriberId == null) {
6846 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006847 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006848 + subId);
6849 }
6850 return null;
6851 }
6852
6853 final SubscriptionInfo info = SubscriptionController.getInstance()
6854 .getSubscriptionInfo(subId);
6855 final ParcelUuid groupUuid = info.getGroupUuid();
6856 // If it doesn't belong to any group, return just subscriberId of itself.
6857 if (groupUuid == null) {
6858 return new String[]{subscriberId};
6859 }
6860
6861 // Get all subscriberIds from the group.
6862 final List<String> mergedSubscriberIds = new ArrayList<>();
6863 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006864 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006865 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006866 for (SubscriptionInfo subInfo : groupInfos) {
6867 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6868 if (subscriberId != null) {
6869 mergedSubscriberIds.add(subscriberId);
6870 }
6871 }
6872
6873 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876
6877 }
6878 }
6879
6880 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006881 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006882 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006883 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
6887 final Phone phone = getPhone(subId);
6888 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006892 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006893
6894 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006895 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006896 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6897 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006898 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6899 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900
6901 final long identity = Binder.clearCallingIdentity();
6902 try {
6903 final Phone phone = getPhone(subId);
6904 if (phone == null) {
6905 return false;
6906 }
6907 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6908 cdmaNonRoamingList);
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006911 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006912 }
6913
6914 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006915 @Deprecated
6916 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6917 enforceModifyPermission();
6918
6919 int returnValue = 0;
6920 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006921 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006922 if(result.exception == null) {
6923 if (result.result != null) {
6924 byte[] responseData = (byte[])(result.result);
6925 if(responseData.length > oemResp.length) {
6926 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6927 responseData.length + "bytes. Buffer Size is " +
6928 oemResp.length + "bytes.");
6929 }
6930 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6931 returnValue = responseData.length;
6932 }
6933 } else {
6934 CommandException ex = (CommandException) result.exception;
6935 returnValue = ex.getCommandError().ordinal();
6936 if(returnValue > 0) returnValue *= -1;
6937 }
6938 } catch (RuntimeException e) {
6939 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6940 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6941 if(returnValue > 0) returnValue *= -1;
6942 }
6943
6944 return returnValue;
6945 }
6946
6947 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006948 public void setRadioCapability(RadioAccessFamily[] rafs) {
6949 try {
6950 ProxyController.getInstance().setRadioCapability(rafs);
6951 } catch (RuntimeException e) {
6952 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6953 }
6954 }
6955
6956 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006957 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006958 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006959 try {
6960 TelephonyPermissions
6961 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6962 mApp, phone.getSubId(), "getRadioAccessFamily");
6963 } catch (SecurityException e) {
6964 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6965 throw e;
6966 }
chen xub97461a2018-10-26 14:17:57 -07006967 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006968 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006969 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006971 final long identity = Binder.clearCallingIdentity();
6972 try {
chen xub97461a2018-10-26 14:17:57 -07006973 TelephonyPermissions
6974 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6975 mApp, phone.getSubId(), "getRadioAccessFamily");
6976 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 } finally {
6978 Binder.restoreCallingIdentity(identity);
6979 }
chen xub97461a2018-10-26 14:17:57 -07006980 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006981 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006982
6983 @Override
Hall Liu82694d52020-12-11 18:22:04 -08006984 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08006985 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08006986 try {
6987 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
6988 Binder.getCallingUid())) {
6989 throw new SecurityException("Package uid and package name do not match: "
6990 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
6991 }
6992 } catch (PackageManager.NameNotFoundException e) {
6993 throw new SecurityException("Package name invalid:" + callingPackage);
6994 }
6995 RoleManager rm = mApp.getSystemService(RoleManager.class);
6996 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
6997 if (!dialerRoleHolders.contains(callingPackage)) {
6998 throw new SecurityException("App must be the dialer role holder to"
6999 + " upload a call composer pic");
7000 }
7001
7002 Executors.newSingleThreadExecutor().execute(() -> {
7003 ByteArrayOutputStream output = new ByteArrayOutputStream(
7004 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7005 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7006 boolean readUntilEnd = false;
7007 int totalBytesRead = 0;
7008 byte[] buffer = new byte[16 * 1024];
7009 while (true) {
7010 int numRead;
7011 try {
7012 numRead = input.read(buffer);
7013 } catch (IOException e) {
7014 try {
7015 fd.checkError();
7016 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7017 null);
7018 } catch (IOException e1) {
7019 // This means that the other side closed explicitly with an error. If this
7020 // happens, log and ignore.
7021 loge("Remote end of call composer picture pipe closed: " + e1);
7022 }
7023 break;
7024 }
7025 if (numRead == -1) {
7026 readUntilEnd = true;
7027 break;
7028 }
7029 totalBytesRead += numRead;
7030 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7031 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7032 try {
7033 input.close();
7034 } catch (IOException e) {
7035 // ignore
7036 }
7037 break;
7038 }
7039 output.write(buffer, 0, numRead);
7040 }
7041 // Generally, the remote end will close the file descriptors. The only case where we
7042 // close is above, where the picture size is too big.
7043
7044 try {
7045 fd.checkError();
7046 } catch (IOException e) {
7047 loge("Remote end for call composer closed with an error: " + e);
7048 return;
7049 }
7050
Hall Liuaa4211e2021-01-20 15:43:39 -08007051 if (!readUntilEnd) {
7052 loge("Did not finish reading entire image; aborting");
7053 return;
7054 }
Hall Liu82694d52020-12-11 18:22:04 -08007055
Hall Liuaa4211e2021-01-20 15:43:39 -08007056 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7057 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7058 new CallComposerPictureTransfer.Factory() {},
7059 imageData,
7060 (result) -> {
7061 if (result.first != null) {
7062 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7063 Bundle outputResult = new Bundle();
7064 outputResult.putParcelable(
7065 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7066 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7067 outputResult);
7068 } else {
7069 callback.send(result.second, null);
7070 }
7071 }
7072 );
Hall Liu82694d52020-12-11 18:22:04 -08007073 });
7074 }
7075
7076 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007077 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007078 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080
7081 final long identity = Binder.clearCallingIdentity();
7082 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007083 ImsManager.getInstance(defaultPhone.getContext(),
7084 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 } finally {
7086 Binder.restoreCallingIdentity(identity);
7087 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007088 }
7089
7090 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007092 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7094 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007095 return false;
7096 }
Svet Ganovb320e182015-04-16 12:30:10 -07007097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 // Check the user preference and the system-level IMS setting. Even if the user has
7101 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7102 // In the long run, we may instead need to check if there exists a connection service
7103 // which can support video calling.
7104 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007105 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 return imsManager.isVtEnabledByPlatform()
7107 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7108 && imsManager.isVtEnabledByUser();
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
7111 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007112 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007113
Andrew Leea1239f22015-03-02 17:44:07 -08007114 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007115 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7116 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 mApp, subId, callingPackage, callingFeatureId,
7119 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 return false;
7121 }
7122
7123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 CarrierConfigManager configManager =
7126 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007127 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
7131 }
Andrew Leea1239f22015-03-02 17:44:07 -08007132 }
7133
7134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007135 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007137 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 return false;
7139 }
7140
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 CarrierConfigManager configManager =
7144 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007145 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
7149 }
Andrew Leea1239f22015-03-02 17:44:07 -08007150 }
7151
Andrew Lee9431b832015-03-09 18:46:45 -07007152 @Override
7153 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007154 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007155 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007156 }
7157
7158 @Override
7159 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 final long identity = Binder.clearCallingIdentity();
7161 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007162 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
Andrew Lee9431b832015-03-09 18:46:45 -07007166 }
7167
Hall Liuf6668912018-10-31 17:05:23 -07007168 /**
7169 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7170 * support for the feature and device firmware support.
7171 *
7172 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7173 */
7174 @Override
7175 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007177 final Phone phone = getPhone(subscriptionId);
7178 if (phone == null) {
7179 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7180 return false;
7181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7185 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007186 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 return isCarrierSupported && isDeviceSupported;
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190 }
Hall Liu98187582018-01-22 19:15:32 -08007191 }
7192
Hall Liuf6668912018-10-31 17:05:23 -07007193 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007194 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7195 * RTT setting, will return true if the device and carrier both support RTT.
7196 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007197 */
7198 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 final long identity = Binder.clearCallingIdentity();
7200 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007201 boolean isRttSupported = isRttSupported(subscriptionId);
7202 boolean isUserRttSettingOn = Settings.Secure.getInt(
7203 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7204 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7205 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7206 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007210 }
7211
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007212 @Deprecated
7213 @Override
7214 public String getDeviceId(String callingPackage) {
7215 return getDeviceIdWithFeature(callingPackage, null);
7216 }
7217
Sanket Padawe7310cc72015-01-14 09:53:20 -08007218 /**
7219 * Returns the unique device ID of phone, for example, the IMEI for
7220 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7221 *
7222 * <p>Requires Permission:
7223 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7224 */
7225 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007226 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007227 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007228 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007229 return null;
7230 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007231 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007232 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007233 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007234 return null;
7235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236
7237 final long identity = Binder.clearCallingIdentity();
7238 try {
7239 return phone.getDeviceId();
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007243 }
7244
Ping Sunc67b7c22016-03-02 19:16:45 +08007245 /**
7246 * {@hide}
7247 * Returns the IMS Registration Status on a particular subid
7248 *
7249 * @param subId
7250 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007251 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007252 Phone phone = getPhone(subId);
7253 if (phone != null) {
7254 return phone.isImsRegistered();
7255 } else {
7256 return false;
7257 }
7258 }
7259
Santos Cordon7a1885b2015-02-03 11:15:19 -08007260 @Override
7261 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
7267 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007268 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007269
Tyler Gunnf70ed162019-04-03 15:28:53 -07007270 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007271 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007272 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007274 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007275 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7276 }
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
7284
7285 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007286 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007287 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7288 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007289 final long identity = Binder.clearCallingIdentity();
7290 try {
7291 Phone phone = getPhone(subscriptionId);
7292 if (phone == null) {
7293 return null;
7294 }
7295 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
7298 }
7299 }
7300
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007301 /**
7302 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007303 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007304 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 Phone phone = getPhone(subId);
7308 if (phone != null) {
7309 return phone.isWifiCallingEnabled();
7310 } else {
7311 return false;
7312 }
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007315 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007316 }
7317
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007318 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007319 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007320 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007321 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 Phone phone = getPhone(subId);
7325 if (phone != null) {
7326 return phone.isVideoEnabled();
7327 } else {
7328 return false;
7329 }
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007332 }
7333 }
7334
7335 /**
7336 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7337 * defined in {@link ImsRegistrationImplBase}.
7338 */
7339 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 final long identity = Binder.clearCallingIdentity();
7341 try {
7342 Phone phone = getPhone(subId);
7343 if (phone != null) {
7344 return phone.getImsRegistrationTech();
7345 } else {
7346 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7347 }
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007350 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007351 }
7352
Stuart Scott8eef64f2015-04-08 15:13:54 -07007353 @Override
7354 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007355 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007356 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7357 return;
7358 }
7359
Svet Ganovcc087f82015-05-12 20:35:54 -07007360 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361
Svet Ganovcc087f82015-05-12 20:35:54 -07007362 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007363 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7364 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007365 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007366 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007367 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007368 setAllowedNetworkTypesForReason(subId,
7369 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7370 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7371 setAllowedNetworkTypesForReason(subId,
7372 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7373 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7374 setAllowedNetworkTypesForReason(subId,
7375 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7376 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007377 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7378 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007379 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007380 // There has been issues when Sms raw table somehow stores orphan
7381 // fragments. They lead to garbled message when new fragments come
7382 // in and combined with those stale ones. In case this happens again,
7383 // user can reset all network settings which will clean up this table.
7384 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007385 // Clean up IMS settings as well here.
7386 int slotId = getSlotIndex(subId);
7387 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7388 ImsManager.getInstance(mApp, slotId).factoryReset();
7389 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007390
7391 // Erase modem config if erase modem on network setting is enabled.
7392 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7393 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7394 if (configValue != null && Boolean.parseBoolean(configValue)) {
7395 sendEraseModemConfig(getDefaultPhone());
7396 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007397 } finally {
7398 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007399 }
7400 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007401
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007402 private void cleanUpSmsRawTable(Context context) {
7403 ContentResolver resolver = context.getContentResolver();
7404 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7405 resolver.delete(uri, null, null);
7406 }
7407
Narayan Kamath1c496c22015-04-16 14:40:19 +01007408 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007409 public String getSimLocaleForSubscriber(int subId) {
7410 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7411 final Phone phone = getPhone(subId);
7412 if (phone == null) {
7413 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007414 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 final long identity = Binder.clearCallingIdentity();
7417 try {
chen xu5d3637b2019-01-21 23:31:38 -08007418 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007419 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007420 if (info == null) {
7421 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7422 return null;
7423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 // Try and fetch the locale from the carrier properties or from the SIM language
7425 // preferences (EF-PL and EF-LI)...
7426 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007428 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7429 if (localeFromDefaultSim != null) {
7430 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7431 if (DBG) log("Using locale from subId: " + subId + " locale: "
7432 + localeFromDefaultSim);
7433 return localeFromDefaultSim.toLanguageTag();
7434 } else {
7435 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 }
7437 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 // The SIM language preferences only store a language (e.g. fr = French), not an
7440 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7441 // the SIM and carrier preferences does not include a country we add the country
7442 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007443 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007445 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 return mccLocale.toLanguageTag();
7447 }
7448
7449 if (DBG) log("No locale found - returning null");
7450 return null;
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
7453 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007454 }
7455
7456 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007457 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007458 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007459 }
7460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 /**
7462 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7463 */
7464 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007465 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007466 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007468
Chenjie Yu1ba97252018-01-11 18:16:20 -08007469 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007470 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007471
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007472 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007473 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7474 * representing the state of the modem.
7475 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007476 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7477 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007478 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007479 */
7480 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007481 public void requestModemActivityInfo(ResultReceiver result) {
7482 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007483 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007487 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 } finally {
7489 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007490 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007491 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007492
Siddharth Rayb8114062018-06-17 15:02:38 -07007493 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7494 // less than total activity duration.
7495 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7496 if (info == null) {
7497 return false;
7498 }
7499 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007500 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7501 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7502
Siddharth Rayb8114062018-06-17 15:02:38 -07007503 return (info.isValid()
7504 && (info.getSleepTimeMillis() <= activityDurationMs)
7505 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007506 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007507 && (totalTxTimeMs <= activityDurationMs));
7508 }
7509
Jack Yu85bd38a2015-11-09 11:34:32 -08007510 /**
7511 * {@hide}
7512 * Returns the service state information on specified subscription.
7513 */
7514 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007515 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7516 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007519 return null;
7520 }
7521
Hall Liuf19c44f2018-11-27 14:38:17 -08007522 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7523 LocationAccessPolicy.checkLocationPermission(mApp,
7524 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7525 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007526 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007527 .setCallingPid(Binder.getCallingPid())
7528 .setCallingUid(Binder.getCallingUid())
7529 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007530 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007531 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007532 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7533 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007534 .build());
7535
7536 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7537 LocationAccessPolicy.checkLocationPermission(mApp,
7538 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7539 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007540 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007541 .setCallingPid(Binder.getCallingPid())
7542 .setCallingUid(Binder.getCallingUid())
7543 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007544 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007545 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007546 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7547 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007548 .build());
7549 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7550 boolean hasFinePermission =
7551 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7552 boolean hasCoarsePermission =
7553 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7554
Jack Yu479f40e2020-10-27 21:29:25 -07007555 final Phone phone = getPhone(subId);
7556 if (phone == null) {
7557 return null;
7558 }
7559
Jordan Liu0f2bc442020-11-18 16:47:37 -08007560 final long identity = Binder.clearCallingIdentity();
7561
Jack Yu479f40e2020-10-27 21:29:25 -07007562 boolean isCallingPackageDataService = phone.getDataServicePackages()
7563 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007565 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7566 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7567 Rlog.d(LOG_TAG,
7568 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7569 return null;
7570 }
7571
Hall Liuf19c44f2018-11-27 14:38:17 -08007572 ServiceState ss = phone.getServiceState();
7573
7574 // Scrub out the location info in ServiceState depending on what level of access
7575 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007576 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007577 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7578 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 } finally {
7580 Binder.restoreCallingIdentity(identity);
7581 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007582 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007583
7584 /**
7585 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7586 *
7587 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7588 * voicemail ringtone.
7589 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7590 * PhoneAccount.
7591 */
7592 @Override
7593 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7597 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007598 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
7604 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007605 }
7606
7607 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007608 * Sets the per-account voicemail ringtone.
7609 *
7610 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7611 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7612 *
7613 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7614 * voicemail ringtone.
7615 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7616 * PhoneAccount.
7617 */
7618 @Override
7619 public void setVoicemailRingtoneUri(String callingPackage,
7620 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007621 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007623 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7624 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7626 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7627 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7633 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007634 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 }
7636 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007639 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007640 }
7641
7642 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007643 * Returns whether vibration is set for voicemail notification in Phone settings.
7644 *
7645 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7646 * voicemail vibration setting.
7647 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7648 */
7649 @Override
7650 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7654 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007655 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007662 }
7663
Youhan Wange64578a2016-05-02 15:32:42 -07007664 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007665 * Sets the per-account voicemail vibration.
7666 *
7667 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7668 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7669 *
7670 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7671 * voicemail vibration setting.
7672 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7673 * specific PhoneAccount.
7674 */
7675 @Override
7676 public void setVoicemailVibrationEnabled(String callingPackage,
7677 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007678 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007680 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7681 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7683 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7684 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007685 }
7686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7690 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007691 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 }
7693 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007696 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007697 }
7698
7699 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007700 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7701 *
7702 * @throws SecurityException if the caller does not have the required permission
7703 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007704 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007706 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007707 }
7708
7709 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007710 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7711 * permission.
7712 *
7713 * @throws SecurityException if the caller does not have the required permission
7714 */
7715 private void enforceSendSmsPermission() {
7716 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7717 }
7718
7719 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007720 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007721 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007722 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007723 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007724 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 final long identity = Binder.clearCallingIdentity();
7726 try {
7727 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007728 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 if (componentName == null) {
7730 throw new SecurityException(
7731 "Caller not current active visual voicemail package[null]");
7732 }
7733 String vvmPackage = componentName.getPackageName();
7734 if (!callingPackage.equals(vvmPackage)) {
7735 throw new SecurityException("Caller not current active visual voicemail package["
7736 + vvmPackage + "]");
7737 }
7738 } finally {
7739 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007740 }
7741 }
7742
7743 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007744 * Return the application ID for the app type.
7745 *
7746 * @param subId the subscription ID that this request applies to.
7747 * @param appType the uicc app type.
7748 * @return Application ID for specificied app type, or null if no uicc.
7749 */
7750 @Override
7751 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007752 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007753 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754
7755 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007756 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 if (phone == null) {
7758 return null;
7759 }
7760 String aid = null;
7761 try {
7762 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7763 .getApplicationByType(appType).getAid();
7764 } catch (Exception e) {
7765 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7766 }
7767 return aid;
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007770 }
Youhan Wange64578a2016-05-02 15:32:42 -07007771 }
7772
Youhan Wang4001d252016-05-11 10:29:41 -07007773 /**
7774 * Return the Electronic Serial Number.
7775 *
7776 * @param subId the subscription ID that this request applies to.
7777 * @return ESN or null if error.
7778 */
7779 @Override
7780 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007781 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007782 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783
7784 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007785 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 if (phone == null) {
7787 return null;
7788 }
7789 String esn = null;
7790 try {
7791 esn = phone.getEsn();
7792 } catch (Exception e) {
7793 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7794 }
7795 return esn;
7796 } finally {
7797 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007798 }
Youhan Wang4001d252016-05-11 10:29:41 -07007799 }
7800
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007801 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007802 * Return the Preferred Roaming List Version.
7803 *
7804 * @param subId the subscription ID that this request applies to.
7805 * @return PRLVersion or null if error.
7806 */
7807 @Override
7808 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007809 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007810 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811
7812 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007813 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 if (phone == null) {
7815 return null;
7816 }
7817 String cdmaPrlVersion = null;
7818 try {
7819 cdmaPrlVersion = phone.getCdmaPrlVersion();
7820 } catch (Exception e) {
7821 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7822 }
7823 return cdmaPrlVersion;
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007826 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007827 }
7828
7829 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007830 * Get snapshot of Telephony histograms
7831 * @return List of Telephony histograms
7832 * @hide
7833 */
7834 @Override
7835 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7837 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838
7839 final long identity = Binder.clearCallingIdentity();
7840 try {
7841 return RIL.getTelephonyRILTimingHistograms();
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007845 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007846
7847 /**
7848 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007849 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7850 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007851 * Require system privileges. In the future we may add this to carrier APIs.
7852 *
Michele Berionne482f8202018-11-27 18:57:59 -08007853 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007854 */
7855 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007856 @TelephonyManager.SetCarrierRestrictionResult
7857 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007858 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007860
Michele Berionne482f8202018-11-27 18:57:59 -08007861 if (carrierRestrictionRules == null) {
7862 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007863 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 final long identity = Binder.clearCallingIdentity();
7866 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007867 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007868 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007872 }
7873
7874 /**
7875 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007876 * Get the allowed carrier list and the excluded carrier list, including the priority between
7877 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007878 * Require system privileges. In the future we may add this to carrier APIs.
7879 *
Michele Berionne482f8202018-11-27 18:57:59 -08007880 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007881 */
7882 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007883 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007884 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007889 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7890 if (response instanceof CarrierRestrictionRules) {
7891 return (CarrierRestrictionRules) response;
7892 }
7893 // Response is an Exception of some kind,
7894 // which is signalled to the user as a NULL retval
7895 return null;
7896 } catch (Exception e) {
7897 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7898 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007902 }
7903
fionaxu59545b42016-05-25 15:53:37 -07007904 /**
fionaxu59545b42016-05-25 15:53:37 -07007905 * Action set from carrier signalling broadcast receivers to enable/disable radio
7906 * @param subId the subscription ID that this action applies to.
7907 * @param enabled control enable or disable radio.
7908 * {@hide}
7909 */
7910 @Override
7911 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7912 enforceModifyPermission();
7913 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914
7915 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007916 if (phone == null) {
7917 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7918 return;
7919 }
7920 try {
7921 phone.carrierActionSetRadioEnabled(enabled);
7922 } catch (Exception e) {
7923 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 } finally {
7925 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007926 }
7927 }
7928
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007929 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007930 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7931 * network status based on which carrier apps could apply actions accordingly,
7932 * enable/disable default url handler for example.
7933 *
7934 * @param subId the subscription ID that this action applies to.
7935 * @param report control start/stop reporting the default network status.
7936 * {@hide}
7937 */
7938 @Override
7939 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7940 enforceModifyPermission();
7941 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942
7943 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007944 if (phone == null) {
7945 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7946 return;
7947 }
7948 try {
7949 phone.carrierActionReportDefaultNetworkStatus(report);
7950 } catch (Exception e) {
7951 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 } finally {
7953 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007954 }
7955 }
7956
7957 /**
fionaxud9622282017-07-17 17:51:30 -07007958 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7959 * @param subId the subscription ID that this action applies to.
7960 * {@hide}
7961 */
7962 @Override
7963 public void carrierActionResetAll(int subId) {
7964 enforceModifyPermission();
7965 final Phone phone = getPhone(subId);
7966 if (phone == null) {
7967 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7968 return;
7969 }
7970 try {
7971 phone.carrierActionResetAll();
7972 } catch (Exception e) {
7973 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7974 }
7975 }
7976
7977 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007978 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7979 * bug report is being generated.
7980 */
7981 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007982 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007983 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7984 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007985 writer.println("Permission Denial: can't dump Phone from pid="
7986 + Binder.getCallingPid()
7987 + ", uid=" + Binder.getCallingUid()
7988 + "without permission "
7989 + android.Manifest.permission.DUMP);
7990 return;
7991 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007993 }
Jack Yueb89b242016-06-22 13:27:47 -07007994
Brad Ebingerdac2f002018-04-03 15:17:52 -07007995 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007996 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7997 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7998 @NonNull String[] args) {
7999 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8000 this, in.getFileDescriptor(), out.getFileDescriptor(),
8001 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008002 }
8003
Jack Yueb89b242016-06-22 13:27:47 -07008004 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008005 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008006 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008007 * @param reason the reason the data enable change is taking place
8008 * @param enabled True if enabling the data, otherwise disabling.
8009 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008010 */
8011 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008012 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008013 boolean enabled) {
8014 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8015 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8016 try {
8017 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008018 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008019 } catch (SecurityException se) {
8020 enforceModifyPermission();
8021 }
8022 } else {
8023 enforceModifyPermission();
8024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025
8026 final long identity = Binder.clearCallingIdentity();
8027 try {
8028 Phone phone = getPhone(subId);
8029 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008030 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8031 phone.carrierActionSetMeteredApnsEnabled(enabled);
8032 } else {
8033 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 }
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008038 }
8039 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008040
8041 /**
8042 * Get Client request stats
8043 * @return List of Client Request Stats
8044 * @hide
8045 */
8046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008047 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8048 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008050 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008051 return null;
8052 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008053 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 if (phone != null) {
8058 return phone.getClientRequestStats();
8059 }
8060
8061 return null;
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
8064 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008065 }
8066
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008067 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008068 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008069 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008070 }
Jack Yueb4124c2017-02-16 15:32:43 -08008071
8072 /**
Grace Chen70990072017-03-24 17:21:30 -07008073 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008074 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008075 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008076 * @param state State of SIM (power down, power up, pass through)
8077 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8078 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8079 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008080 *
8081 **/
8082 @Override
Grace Chen70990072017-03-24 17:21:30 -07008083 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008084 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008085 Phone phone = PhoneFactory.getPhone(slotIndex);
8086
vagdeviaf9a5b92018-08-15 16:01:53 -07008087 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008092 phone.setSimPowerState(state, null, workSource);
8093 }
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
8097 }
8098
8099 /**
8100 * Set SIM card power state.
8101 *
8102 * @param slotIndex SIM slot id.
8103 * @param state State of SIM (power down, power up, pass through)
8104 * @param callback callback to trigger after success or failure
8105 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8106 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8107 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8108 *
8109 **/
8110 @Override
8111 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8112 IIntegerConsumer callback) {
8113 enforceModifyPermission();
8114 Phone phone = PhoneFactory.getPhone(slotIndex);
8115
8116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8117
8118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 if (phone != null) {
8121 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8122 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 }
8124 } finally {
8125 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008126 }
8127 }
Shuo Qiandd210312017-04-12 22:11:33 +00008128
Tyler Gunn65d45c22017-06-05 11:22:26 -07008129 private boolean isUssdApiAllowed(int subId) {
8130 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008131 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008132 if (configManager == null) {
8133 return false;
8134 }
8135 PersistableBundle pb = configManager.getConfigForSubId(subId);
8136 if (pb == null) {
8137 return false;
8138 }
8139 return pb.getBoolean(
8140 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8141 }
8142
Shuo Qiandd210312017-04-12 22:11:33 +00008143 /**
8144 * Check if phone is in emergency callback mode
8145 * @return true if phone is in emergency callback mode
8146 * @param subId sub id
8147 */
goneil9c5f4872017-12-05 14:07:56 -08008148 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008149 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008150 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008151 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 if (phone != null) {
8156 return phone.isInEcm();
8157 } else {
8158 return false;
8159 }
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008162 }
8163 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008164
8165 /**
8166 * Get the current signal strength information for the given subscription.
8167 * Because this information is not updated when the device is in a low power state
8168 * it should not be relied-upon to be current.
8169 * @param subId Subscription index
8170 * @return the most recent cached signal strength info from the modem
8171 */
8172 @Override
8173 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174 final long identity = Binder.clearCallingIdentity();
8175 try {
8176 Phone p = getPhone(subId);
8177 if (p == null) {
8178 return null;
8179 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 return p.getSignalStrength();
8182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008185 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008186
Pengquan Meng77b7f132018-08-22 14:49:57 -07008187 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008188 * Get the current modem radio state for the given slot.
8189 * @param slotIndex slot index.
8190 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008191 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008192 * @return the current radio power state from the modem
8193 */
8194 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008195 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008196 Phone phone = PhoneFactory.getPhone(slotIndex);
8197 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8199 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008200 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8201 }
8202
8203 final long identity = Binder.clearCallingIdentity();
8204 try {
8205 return phone.getRadioPowerState();
8206 } finally {
8207 Binder.restoreCallingIdentity(identity);
8208 }
8209 }
8210 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8211 }
8212
8213 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008214 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8215 *
8216 * <p>Requires one of the following permissions:
8217 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8218 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8219 * privileges.
8220 *
8221 * @param subId subscription id
8222 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8223 * {@code false}.
8224 */
8225 @Override
8226 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008227 try {
8228 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8229 null);
8230 } catch (Exception e) {
8231 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8232 mApp, subId, "isDataRoamingEnabled");
8233 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008234
Pengquan Menga1bb6272018-09-06 09:59:22 -07008235 boolean isEnabled = false;
8236 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008237 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008238 Phone phone = getPhone(subId);
8239 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008240 } finally {
8241 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008242 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008243 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008244 }
8245
8246
8247 /**
8248 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8249 *
8250 * <p> Requires permission:
8251 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8252 * privileges.
8253 *
8254 * @param subId subscription id
8255 * @param isEnabled {@code true} means enable, {@code false} means disable.
8256 */
8257 @Override
8258 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8260 mApp, subId, "setDataRoamingEnabled");
8261
Pengquan Menga1bb6272018-09-06 09:59:22 -07008262 final long identity = Binder.clearCallingIdentity();
8263 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008264 Phone phone = getPhone(subId);
8265 if (phone != null) {
8266 phone.setDataRoamingEnabled(isEnabled);
8267 }
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008270 }
8271 }
8272
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008273 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008274 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008275 TelephonyPermissions
8276 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008277 mApp, subId, "isManualNetworkSelectionAllowed");
8278
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008279 boolean isAllowed = true;
8280 final long identity = Binder.clearCallingIdentity();
8281 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008282 Phone phone = getPhone(subId);
8283 if (phone != null) {
8284 isAllowed = phone.isCspPlmnEnabled();
8285 }
8286 } finally {
8287 Binder.restoreCallingIdentity(identity);
8288 }
8289 return isAllowed;
8290 }
8291
8292 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008293 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008294 // Verify that tha callingPackage belongs to the calling UID
8295 mApp.getSystemService(AppOpsManager.class)
8296 .checkPackage(Binder.getCallingUid(), callingPackage);
8297
Jordan Liu1e142fc2019-04-22 15:10:43 -07008298 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008299 try {
8300 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008301 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008302 } catch (SecurityException e) {
8303 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8304 // has carrier privileges on an active UICC
8305 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8306 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008307 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008308 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008309 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008310
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008313 UiccController uiccController = UiccController.getInstance();
8314 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008315 if (hasReadPermission) {
8316 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008317 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008318
8319 // Remove private info if the caller doesn't have access
8320 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8321 for (UiccCardInfo cardInfo : cardInfos) {
8322 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8323 // is available
8324 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8325 if (card == null || card.getUiccProfile() == null) {
8326 // assume no access if the card or profile is unavailable
8327 filteredInfos.add(cardInfo.getUnprivileged());
8328 continue;
8329 }
8330 UiccProfile profile = card.getUiccProfile();
8331 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8332 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8333 filteredInfos.add(cardInfo);
8334 } else {
8335 filteredInfos.add(cardInfo.getUnprivileged());
8336 }
8337 }
8338 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008345 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008346 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 final long identity = Binder.clearCallingIdentity();
8349 try {
8350 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8351 if (slots == null) {
8352 Rlog.i(LOG_TAG, "slots is null.");
8353 return null;
8354 }
8355
8356 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8357 for (int i = 0; i < slots.length; i++) {
8358 UiccSlot slot = slots[i];
8359 if (slot == null) {
8360 continue;
8361 }
8362
Jordan Liu7be7e652019-05-06 18:55:02 +00008363 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364 UiccCard card = slot.getUiccCard();
8365 if (card != null) {
8366 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008367 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008368 cardId = slot.getEid();
8369 if (TextUtils.isEmpty(cardId)) {
8370 cardId = slot.getIccId();
8371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 }
8373
Jordan Liu857451f2019-05-09 16:35:35 -07008374 if (cardId != null) {
8375 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8376 // if cardId is an EID, it's all digits so this is fine
8377 cardId = IccUtils.stripTrailingFs(cardId);
8378 }
8379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 int cardState = 0;
8381 switch (slot.getCardState()) {
8382 case CARDSTATE_ABSENT:
8383 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8384 break;
8385 case CARDSTATE_PRESENT:
8386 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8387 break;
8388 case CARDSTATE_ERROR:
8389 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8390 break;
8391 case CARDSTATE_RESTRICTED:
8392 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8393 break;
8394 default:
8395 break;
8396
8397 }
8398
8399 infos[i] = new UiccSlotInfo(
8400 slot.isActive(),
8401 slot.isEuicc(),
8402 cardId,
8403 cardState,
8404 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008405 slot.isExtendedApduSupported(),
8406 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 }
8408 return infos;
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008411 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008412 }
8413
8414 @Override
8415 public boolean switchSlots(int[] physicalSlots) {
8416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008417
8418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008424 }
Jack Yu4c988042018-02-27 15:30:01 -08008425
8426 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008427 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 return UiccController.getInstance().getCardIdForDefaultEuicc();
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
8434 }
8435
Pengquan Meng85728fb2018-03-12 16:31:21 -07008436 /**
goneil47ffb6e2018-04-06 15:40:58 -07008437 * A test API to reload the UICC profile.
8438 *
8439 * <p>Requires that the calling app has permission
8440 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8441 * @hide
8442 */
8443 @Override
8444 public void refreshUiccProfile(int subId) {
8445 enforceModifyPermission();
8446
8447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 Phone phone = getPhone(subId);
8450 if (phone == null) {
8451 return;
8452 }
8453 UiccCard uiccCard = phone.getUiccCard();
8454 if (uiccCard == null) {
8455 return;
8456 }
8457 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8458 if (uiccProfile == null) {
8459 return;
8460 }
8461 uiccProfile.refresh();
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
8465 }
8466
8467 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008468 * Returns false if the mobile data is disabled by default, otherwise return true.
8469 */
8470 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008471 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008472 }
8473
8474 /**
8475 * Returns true if the data roaming is enabled by default, i.e the system property
8476 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8477 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8478 */
8479 private boolean getDefaultDataRoamingEnabled(int subId) {
8480 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008481 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008482 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008483 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8484 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8485 return isDataRoamingEnabled;
8486 }
8487
8488 /**
8489 * Returns the default network type for the given {@code subId}, if the default network type is
8490 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8491 */
8492 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008493 List<Integer> list = TelephonyProperties.default_network();
8494 int phoneId = mSubscriptionController.getPhoneId(subId);
8495 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8496 return list.get(phoneId);
8497 }
8498 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008499 }
fionaxua13278b2018-03-21 00:08:13 -07008500
8501 @Override
8502 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008503 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008505
8506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 final Phone phone = getPhone(subId);
8509 if (phone == null) {
8510 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8511 return;
8512 }
chen xueaba88a2019-03-15 13:15:10 -07008513 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8514 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008515 if (carrierPrivilegeRules == null) {
8516 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8517 } else {
8518 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 } finally {
8521 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008522 }
fionaxua13278b2018-03-21 00:08:13 -07008523 }
8524
8525 @Override
8526 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008527 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 final Phone phone = getPhone(subId);
8532 if (phone == null) {
8533 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8534 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8535 }
8536 return phone.getCarrierIdListVersion();
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008539 }
fionaxua13278b2018-03-21 00:08:13 -07008540 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008541
8542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008543 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8544 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008546 mApp, subId, callingPackage, callingFeatureId,
8547 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008548 return -1;
8549 }
8550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
8557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008558
8559 @Override
8560 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008561 TelephonyPermissions
8562 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008563 mApp, subId, "getCdmaRoamingMode");
8564
8565 final long identity = Binder.clearCallingIdentity();
8566 try {
8567 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
8570 }
8571 }
8572
8573 @Override
8574 public boolean setCdmaRoamingMode(int subId, int mode) {
8575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8576 mApp, subId, "setCdmaRoamingMode");
8577
8578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
8585
8586 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008587 public int getCdmaSubscriptionMode(int subId) {
8588 TelephonyPermissions
8589 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8590 mApp, subId, "getCdmaSubscriptionMode");
8591
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
8598 }
8599
8600 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008601 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8603 mApp, subId, "setCdmaSubscriptionMode");
8604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
8611 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008612
sqianc5eccab2018-10-19 18:46:41 -07008613 @Override
sqian8c685422019-02-22 15:55:18 -08008614 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008617 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8618 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008619 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8620 }
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
sqian854d44b2018-12-12 16:48:18 -08008623 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8624 for (Phone phone: PhoneFactory.getPhones()) {
8625 if (phone.getEmergencyNumberTracker() != null
8626 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8627 emergencyNumberListInternal.put(
8628 phone.getSubId(),
8629 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8630 }
sqian11b7a0e2018-12-05 18:48:28 -08008631 }
sqian854d44b2018-12-12 16:48:18 -08008632 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
sqianc5eccab2018-10-19 18:46:41 -07008636 }
8637
8638 @Override
sqian8c685422019-02-22 15:55:18 -08008639 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008640 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008641 if (!exactMatch) {
8642 TelephonyPermissions
8643 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008644 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008645 }
8646 final long identity = Binder.clearCallingIdentity();
8647 try {
sqian854d44b2018-12-12 16:48:18 -08008648 for (Phone phone: PhoneFactory.getPhones()) {
8649 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008650 && phone.getEmergencyNumberTracker()
8651 .isEmergencyNumber(number, exactMatch)) {
8652 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008653 }
sqian11b7a0e2018-12-05 18:48:28 -08008654 }
8655 return false;
8656 } finally {
8657 Binder.restoreCallingIdentity(identity);
8658 }
8659 }
8660
sqianf4ca7ed2019-01-15 18:32:07 -08008661 /**
8662 * Update emergency number list for test mode.
8663 */
8664 @Override
8665 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8667 "updateEmergencyNumberListTestMode");
8668
8669 final long identity = Binder.clearCallingIdentity();
8670 try {
8671 for (Phone phone: PhoneFactory.getPhones()) {
8672 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8673 if (tracker != null) {
8674 tracker.executeEmergencyNumberTestModeCommand(action, num);
8675 }
8676 }
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 }
8681
8682 /**
8683 * Get the full emergency number list for test mode.
8684 */
8685 @Override
8686 public List<String> getEmergencyNumberListTestMode() {
8687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8688 "getEmergencyNumberListTestMode");
8689
8690 final long identity = Binder.clearCallingIdentity();
8691 try {
8692 Set<String> emergencyNumbers = new HashSet<>();
8693 for (Phone phone: PhoneFactory.getPhones()) {
8694 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8695 if (tracker != null) {
8696 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8697 emergencyNumbers.add(num.getNumber());
8698 }
8699 }
8700 }
8701 return new ArrayList<>(emergencyNumbers);
8702 } finally {
8703 Binder.restoreCallingIdentity(identity);
8704 }
8705 }
8706
chen xud6b45bd2018-10-30 22:27:10 -07008707 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008708 public int getEmergencyNumberDbVersion(int subId) {
8709 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8710
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 final Phone phone = getPhone(subId);
8714 if (phone == null) {
8715 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8716 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8717 }
8718 return phone.getEmergencyNumberDbVersion();
8719 } finally {
8720 Binder.restoreCallingIdentity(identity);
8721 }
8722 }
8723
8724 @Override
8725 public void notifyOtaEmergencyNumberDbInstalled() {
8726 enforceModifyPermission();
8727
8728 final long identity = Binder.clearCallingIdentity();
8729 try {
8730 for (Phone phone: PhoneFactory.getPhones()) {
8731 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8732 if (tracker != null) {
8733 tracker.updateOtaEmergencyNumberDatabase();
8734 }
8735 }
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740
8741 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008742 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008743 enforceActiveEmergencySessionPermission();
8744
8745 final long identity = Binder.clearCallingIdentity();
8746 try {
8747 for (Phone phone: PhoneFactory.getPhones()) {
8748 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8749 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008750 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8751 }
8752 }
8753 } finally {
8754 Binder.restoreCallingIdentity(identity);
8755 }
8756 }
8757
8758 @Override
8759 public void resetOtaEmergencyNumberDbFilePath() {
8760 enforceActiveEmergencySessionPermission();
8761
8762 final long identity = Binder.clearCallingIdentity();
8763 try {
8764 for (Phone phone: PhoneFactory.getPhones()) {
8765 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8766 if (tracker != null) {
8767 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008768 }
8769 }
8770 } finally {
8771 Binder.restoreCallingIdentity(identity);
8772 }
8773 }
8774
8775 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008776 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8777 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8778 Phone phone = getPhone(subId);
8779 if (phone == null) {
8780 return null;
8781 }
8782 final long identity = Binder.clearCallingIdentity();
8783 try {
8784 UiccProfile profile = UiccController.getInstance()
8785 .getUiccProfileForPhone(phone.getPhoneId());
8786 if (profile != null) {
8787 return profile.getCertsFromCarrierPrivilegeAccessRules();
8788 }
8789 } finally {
8790 Binder.restoreCallingIdentity(identity);
8791 }
8792 return null;
8793 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008794
8795 /**
8796 * Enable or disable a modem stack.
8797 */
8798 @Override
8799 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8800 enforceModifyPermission();
8801
8802 final long identity = Binder.clearCallingIdentity();
8803 try {
8804 Phone phone = PhoneFactory.getPhone(slotIndex);
8805 if (phone == null) {
8806 return false;
8807 } else {
8808 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8809 }
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
Michelecea4cf22018-12-21 15:00:11 -08008814
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008815 /**
8816 * Whether a modem stack is enabled or not.
8817 */
8818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008819 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8820 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008821 Phone phone = PhoneFactory.getPhone(slotIndex);
8822 if (phone == null) return false;
8823
8824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008825 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8826 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008827 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8828 }
8829
8830 final long identity = Binder.clearCallingIdentity();
8831 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008832 try {
8833 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8834 } catch (NoSuchElementException ex) {
8835 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8836 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008837 } finally {
8838 Binder.restoreCallingIdentity(identity);
8839 }
8840 }
8841
Michelecea4cf22018-12-21 15:00:11 -08008842 @Override
Michele0ea7d782019-03-19 14:58:42 -07008843 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008844 enforceModifyPermission();
8845
8846 final long identity = Binder.clearCallingIdentity();
8847 try {
8848 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008849 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008850 .commit();
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
8854 }
8855
8856 @Override
Michele0ea7d782019-03-19 14:58:42 -07008857 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008858 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008860 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8861 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008862 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008863 }
Michelecea4cf22018-12-21 15:00:11 -08008864
8865 final long identity = Binder.clearCallingIdentity();
8866 try {
Michele0ea7d782019-03-19 14:58:42 -07008867 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008868 } finally {
8869 Binder.restoreCallingIdentity(identity);
8870 }
8871 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008872
Michele0ea7d782019-03-19 14:58:42 -07008873 @TelephonyManager.IsMultiSimSupportedResult
8874 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008875 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8876 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8877 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008878 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8879 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008880 }
8881 // Check if the hardware supports multisim functionality. If usage of multisim is not
8882 // supported by the modem, indicate that it is restricted.
8883 PhoneCapability staticCapability =
8884 mPhoneConfigurationManager.getStaticPhoneCapability();
8885 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008886 loge("isMultiSimSupportedInternal: no static configuration available");
8887 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008888 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008889 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008890 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8891 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008892 }
8893 // Check if support of multiple SIMs is restricted by carrier
8894 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008895 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008896 }
8897
Michele0ea7d782019-03-19 14:58:42 -07008898 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008899 }
8900
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008901 /**
8902 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008903 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8904 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8905 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008906 * @param numOfSims number of active sims we want to switch to
8907 */
8908 @Override
8909 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008910 if (numOfSims == 1) {
8911 enforceModifyPermission();
8912 } else {
8913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8914 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8915 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008916 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008917
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008918 try {
Michele30b57b22019-03-01 12:01:14 -08008919 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008920 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008921 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8922 return;
8923 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008924 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8925 } finally {
8926 Binder.restoreCallingIdentity(identity);
8927 }
8928 }
8929
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008930 @Override
8931 public boolean isApplicationOnUicc(int subId, int appType) {
8932 enforceReadPrivilegedPermission("isApplicationOnUicc");
8933 Phone phone = getPhone(subId);
8934 if (phone == null) {
8935 return false;
8936 }
8937 final long identity = Binder.clearCallingIdentity();
8938 try {
8939 UiccCard uiccCard = phone.getUiccCard();
8940 if (uiccCard == null) {
8941 return false;
8942 }
8943 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8944 if (uiccProfile == null) {
8945 return false;
8946 }
8947 if (TelephonyManager.APPTYPE_SIM <= appType
8948 && appType <= TelephonyManager.APPTYPE_ISIM) {
8949 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8950 }
8951 return false;
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
8955 }
8956
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008957 /**
chen xub4baa772019-04-03 10:23:41 -07008958 * Get whether making changes to modem configurations will trigger reboot.
8959 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008960 */
8961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008962 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8963 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008965 mApp, subId, callingPackage, callingFeatureId,
8966 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008967 return false;
8968 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8972 } finally {
8973 Binder.restoreCallingIdentity(identity);
8974 }
8975 }
8976
Nathan Harold29f5f052019-02-15 13:41:57 -08008977 private void updateModemStateMetrics() {
8978 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8979 // TODO: check the state for each modem if the api is ready.
8980 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8981 }
8982
Pengquan Meng3889a572019-01-23 11:16:29 -08008983 @Override
8984 public int[] getSlotsMapping() {
8985 enforceReadPrivilegedPermission("getSlotsMapping");
8986
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8990 // All logical slots should have a mapping to a physical slot.
8991 int[] logicalSlotsMapping = new int[phoneCount];
8992 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8993 for (int i = 0; i < slotInfos.length; i++) {
8994 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8995 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8996 }
8997 }
8998 return logicalSlotsMapping;
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009003
9004 /**
9005 * Get the IRadio HAL Version
9006 */
9007 @Override
9008 public int getRadioHalVersion() {
9009 Phone phone = getDefaultPhone();
9010 if (phone == null) return -1;
9011 HalVersion hv = phone.getHalVersion();
9012 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9013 return hv.major * 100 + hv.minor;
9014 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009015
9016 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009017 * Get the current calling package name.
9018 * @return the current calling package name
9019 */
9020 @Override
9021 public String getCurrentPackageName() {
9022 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9023 }
9024
9025 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009026 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9027 * corresponding network requests on a subId.
9028 *
9029 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009030 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009031 * 2) APN is un-metered for this subscription, or
9032 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009033 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009034 *
9035 * @return whether data is allowed for a apn type.
9036 *
9037 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009038 */
9039 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009040 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009041 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9042 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009043
9044 // Now that all security checks passes, perform the operation as ourselves.
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 Phone phone = getPhone(subId);
9048 if (phone == null) return false;
9049
Jack Yu41407ee2019-05-13 16:54:09 -07009050 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009051 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 }
9056
9057 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009058 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009059 enforceReadPrivilegedPermission("isApnMetered");
9060
9061 // Now that all security checks passes, perform the operation as ourselves.
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 Phone phone = getPhone(subId);
9065 if (phone == null) return true; // By default return true.
9066
Jack Yu41407ee2019-05-13 16:54:09 -07009067 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009068 } finally {
9069 Binder.restoreCallingIdentity(identity);
9070 }
9071 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009072
9073 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009074 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9075 int subscriptionId, IBooleanConsumer resultCallback) {
9076 enforceModifyPermission();
9077 long token = Binder.clearCallingIdentity();
9078 try {
9079 Phone phone = getPhone(subscriptionId);
9080 if (phone == null) {
9081 try {
9082 if (resultCallback != null) {
9083 resultCallback.accept(false);
9084 }
9085 } catch (RemoteException e) {
9086 // ignore
9087 }
9088 return;
9089 }
9090 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9091 Pair.create(specifiers, (x) -> {
9092 try {
9093 if (resultCallback != null) {
9094 resultCallback.accept(x);
9095 }
9096 } catch (RemoteException e) {
9097 // ignore
9098 }
9099 });
9100 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9101 } finally {
9102 Binder.restoreCallingIdentity(token);
9103 }
9104 }
9105
9106 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009107 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9108 TelephonyPermissions
9109 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9110 mApp, subId, "getSystemSelectionChannels");
9111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9112 final long identity = Binder.clearCallingIdentity();
9113 try {
9114 List<RadioAccessSpecifier> specifiers =
9115 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9116 null, subId, workSource);
9117 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9118 return specifiers;
9119 } finally {
9120 Binder.restoreCallingIdentity(identity);
9121 }
9122 }
9123
9124 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009125 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009126 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009127 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9128 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9129 if (iccRecords == null) {
9130 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9131 return false;
9132 }
9133 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9134 }
9135
9136 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009137 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9138 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009139 if (callingPackage == null) {
9140 callingPackage = getCurrentPackageName();
9141 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009142 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9143 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009144 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9145 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009146 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9147 }
9148 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9149 Intent intent = new Intent();
9150 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9151 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9152 // Bring up choose default SMS subscription dialog right now
9153 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9154 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9155 mApp.startActivity(intent);
9156 }
chen xud5ca2d52019-05-28 15:20:57 -07009157
9158 @Override
9159 public String getMmsUAProfUrl(int subId) {
9160 //TODO investigate if this API should require proper permission check in R b/133791609
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009163 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9164 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9165 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9166 return carrierUAProfUrl;
9167 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009168 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9169 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
9176 public String getMmsUserAgent(int subId) {
9177 //TODO investigate if this API should require proper permission check in R b/133791609
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009180 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9181 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9182 if (!TextUtils.isEmpty(carrierUserAgent)) {
9183 return carrierUserAgent;
9184 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009185 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9186 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
Jack Yub07d4972019-05-28 16:12:25 -07009191
9192 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009193 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9194 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009195
Jack Yub07d4972019-05-28 16:12:25 -07009196 final long identity = Binder.clearCallingIdentity();
9197 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009198 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009199 if (phone == null) return false;
9200
Hall Liua62f5da2020-09-25 10:42:19 -07009201 switch (policy) {
9202 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9203 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9204 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9205 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9206 default:
9207 throw new IllegalArgumentException(policy + " is not a valid policy");
9208 }
Jack Yub07d4972019-05-28 16:12:25 -07009209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 }
9213
9214 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009215 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009216 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009217 enforceModifyPermission();
9218
changbettyd5c246e2019-12-24 15:40:37 +08009219 final long identity = Binder.clearCallingIdentity();
9220 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009221 Phone phone = getPhone(subscriptionId);
9222 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009223
Hall Liua62f5da2020-09-25 10:42:19 -07009224 switch (policy) {
9225 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9226 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9227 break;
9228 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9229 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9230 break;
9231 default:
9232 throw new IllegalArgumentException(policy + " is not a valid policy");
9233 }
changbettyd5c246e2019-12-24 15:40:37 +08009234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 }
9238
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009239 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009240 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009241 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9242 * otherwise.
9243 */
9244 @Override
9245 public void setCepEnabled(boolean isCepEnabled) {
9246 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9247
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9251 for (Phone phone : PhoneFactory.getPhones()) {
9252 Phone defaultPhone = phone.getImsPhone();
9253 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9254 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9255 ImsPhoneCallTracker imsPhoneCallTracker =
9256 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9257 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9258 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9259 + imsPhone.getMsisdn());
9260 }
9261 }
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
allenwtsu46dcc572020-01-08 18:24:03 +08009266
9267 /**
9268 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9269 *
9270 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9271 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9272 * before being read.
9273 */
9274 @Override
9275 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9276 isCompressed) {
9277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9278 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009279 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9280 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9281 }
9282 if (!isImsAvailableOnDevice()) {
9283 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9284 "IMS not available on device.");
9285 }
9286
9287 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009288 try {
Hui Wang761a6682020-10-31 05:12:53 +00009289 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9290 } finally {
9291 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009292 }
9293 }
zoey chene02881a2019-12-30 16:11:23 +08009294
9295 @Override
9296 public boolean isIccLockEnabled(int subId) {
9297 enforceReadPrivilegedPermission("isIccLockEnabled");
9298
9299 // Now that all security checks passes, perform the operation as ourselves.
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
9302 Phone phone = getPhone(subId);
9303 if (phone != null && phone.getIccCard() != null) {
9304 return phone.getIccCard().getIccLockEnabled();
9305 } else {
9306 return false;
9307 }
9308 } finally {
9309 Binder.restoreCallingIdentity(identity);
9310 }
9311 }
9312
9313 /**
9314 * Set the ICC pin lock enabled or disabled.
9315 *
9316 * @return an integer representing the status of IccLock enabled or disabled in the following
9317 * three cases:
9318 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9319 * successfully.
9320 * - Positive number and zero for remaining password attempts.
9321 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9322 *
9323 */
9324 @Override
9325 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9326 enforceModifyPermission();
9327
9328 Phone phone = getPhone(subId);
9329 if (phone == null) {
9330 return 0;
9331 }
9332 // Now that all security checks passes, perform the operation as ourselves.
9333 final long identity = Binder.clearCallingIdentity();
9334 try {
9335 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9336 new Pair<Boolean, String>(enabled, password), phone, null);
9337 return attemptsRemaining;
9338
9339 } catch (Exception e) {
9340 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9341 } finally {
9342 Binder.restoreCallingIdentity(identity);
9343 }
9344 return 0;
9345 }
9346
9347 /**
9348 * Change the ICC password used in ICC pin lock.
9349 *
9350 * @return an integer representing the status of IccLock changed in the following three cases:
9351 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9352 * - Positive number and zero for remaining password attempts.
9353 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9354 *
9355 */
9356 @Override
9357 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9358 enforceModifyPermission();
9359
9360 Phone phone = getPhone(subId);
9361 if (phone == null) {
9362 return 0;
9363 }
9364 // Now that all security checks passes, perform the operation as ourselves.
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9368 new Pair<String, String>(oldPassword, newPassword), phone, null);
9369 return attemptsRemaining;
9370
9371 } catch (Exception e) {
9372 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 return 0;
9377 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009378
9379 /**
9380 * Request for receiving user activity notification
9381 */
9382 @Override
9383 public void requestUserActivityNotification() {
9384 if (!mNotifyUserActivity.get()
9385 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9386 mNotifyUserActivity.set(true);
9387 }
9388 }
9389
9390 /**
9391 * Called when userActivity is signalled in the power manager.
9392 * This is safe to call from any thread, with any window manager locks held or not.
9393 */
9394 @Override
9395 public void userActivity() {
9396 // ***************************************
9397 // * Inherited from PhoneWindowManager *
9398 // ***************************************
9399 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9400 // WITH ITS LOCKS HELD.
9401 //
9402 // This code must be VERY careful about the locks
9403 // it acquires.
9404 // In fact, the current code acquires way too many,
9405 // and probably has lurking deadlocks.
9406
9407 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9408 throw new SecurityException("Only the OS may call notifyUserActivity()");
9409 }
9410
9411 if (mNotifyUserActivity.getAndSet(false)) {
9412 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9413 USER_ACTIVITY_NOTIFICATION_DELAY);
9414 }
9415 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009416
9417 @Override
9418 public boolean canConnectTo5GInDsdsMode() {
9419 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9420 }
Jack Yud10cdd42020-09-28 20:28:01 -07009421
9422 @Override
9423 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9424 String callingFeatureId) {
9425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9426 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9427 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9428 }
9429
9430 Phone phone = getPhone(subId);
9431 if (phone == null) {
9432 throw new RuntimeException("phone is not available");
9433 }
9434 // Now that all security checks passes, perform the operation as ourselves.
9435 final long identity = Binder.clearCallingIdentity();
9436 try {
9437 return phone.getEquivalentHomePlmns();
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 }
Daniel Bright59e67312020-11-13 11:49:37 -08009442
9443 @Override
9444 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009445 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9446 Set<String> radioInterfaceCapabilities =
Daniel Bright59e67312020-11-13 11:49:37 -08009447 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9448 if (radioInterfaceCapabilities == null) {
9449 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009450 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009451 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009452 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009453
Hui Wang641e81c2020-10-12 12:14:23 -07009454 @Override
9455 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9456 UaSecurityProtocolIdentifier securityProtocol,
9457 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9458 throws RemoteException {
9459 enforceModifyPermission();
9460 if (DBG) {
9461 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9462 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9463 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9464 }
9465
9466 if (!SubscriptionManager.isValidSubscriptionId(subId)
9467 || appType < TelephonyManager.APPTYPE_UNKNOWN
9468 || appType > TelephonyManager.APPTYPE_ISIM
9469 || nafUrl == null || securityProtocol == null || callback == null) {
9470 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9471 if (callback != null) {
9472 try {
9473 callback.onAuthenticationFailure(
9474 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9475 } catch (RemoteException exception) {
9476 log("Fail to notify onAuthenticationFailure due to " + exception);
9477 }
9478 return;
9479 }
9480 }
9481
9482 final long token = Binder.clearCallingIdentity();
9483 try {
9484 getGbaManager(subId).bootstrapAuthenticationRequest(
9485 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9486 forceBootStrapping, callback));
9487 } finally {
9488 Binder.restoreCallingIdentity(token);
9489 }
9490 }
9491
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009492 /**
9493 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9494 * requested radio power state will actually be set. See {@link
9495 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9496 *
9497 * @param subId the subscription ID of the phone requesting to set the radio power state.
9498 * @param enable {@code true} if trying to turn radio on.
9499 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9500 * false}.
9501 */
9502 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9503 Phone phone = getPhone(subId);
9504 if (phone != null) {
9505 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9506 return true;
9507 }
9508 return false;
9509 }
9510
9511 private int handleDataThrottlingRequest(int subId,
9512 DataThrottlingRequest dataThrottlingRequest) {
9513 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9514 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9515 if (!setRadioPowerForThermal(subId, true)) {
9516 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9517 }
9518
9519 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9520
9521 int thermalMitigationResult =
9522 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9523 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9524 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9525 }
9526 return thermalMitigationResult;
9527 }
9528
9529 /**
9530 * Thermal mitigation request to control functionalities at modem.
9531 *
9532 * @param subId the id of the subscription.
9533 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9534 *
9535 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9536 */
9537 @Override
9538 @ThermalMitigationResult
9539 public int sendThermalMitigationRequest(
9540 int subId,
9541 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9542 enforceModifyPermission();
9543
9544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9545 final long identity = Binder.clearCallingIdentity();
9546
9547 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9548 try {
9549 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9550 switch (thermalMitigationAction) {
9551 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9552 thermalMitigationResult =
9553 handleDataThrottlingRequest(subId,
9554 thermalMitigationRequest.getDataThrottlingRequest());
9555 break;
9556 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9557 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9558 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9559 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9560 }
9561
9562 // Ensure that radio is on. If not able to power on due to phone being
9563 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9564 if (!setRadioPowerForThermal(subId, true)) {
9565 thermalMitigationResult =
9566 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9567 break;
9568 }
9569
9570 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9571 false);
9572 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9573 break;
9574 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9575 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9576 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9577 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9578 }
9579
9580 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9581 if (registry != null) {
9582 TelephonyConnectionService service =
9583 registry.getTelephonyConnectionService();
9584 Phone phone = getPhone(subId);
9585 if (phone == null) {
9586 thermalMitigationResult =
9587 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9588 break;
9589 }
9590
9591 if (PhoneConstantConversions.convertCallState(phone.getState())
9592 != TelephonyManager.CALL_STATE_IDLE
9593 || phone.isInEmergencySmsMode() || phone.isInEcm()
9594 || (service != null && service.isEmergencyCallPending())) {
9595 String errorMessage = "Phone state is not valid. call state = "
9596 + PhoneConstantConversions.convertCallState(phone.getState())
9597 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9598 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9599 errorMessage += service == null
9600 ? " TelephonyConnectionService is null"
9601 : " isEmergencyCallPending = "
9602 + service.isEmergencyCallPending();
9603 Log.e(LOG_TAG, errorMessage);
9604 thermalMitigationResult =
9605 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9606 break;
9607 }
9608 } else {
9609 thermalMitigationResult =
9610 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9611 break;
9612 }
9613
9614 // Turn radio off. If not able to power off due to phone being unavailable,
9615 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9616 if (!setRadioPowerForThermal(subId, false)) {
9617 thermalMitigationResult =
9618 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9619 break;
9620 }
9621 thermalMitigationResult =
9622 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9623 break;
9624 default:
9625 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9626 + "not exist. Requested action: " + thermalMitigationAction);
9627 }
9628 } catch (IllegalArgumentException e) {
9629 throw e;
9630 } catch (Exception e) {
9631 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9632 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636
9637 if (DBG) {
9638 log("thermalMitigationRequest returning with thermalMitigationResult: "
9639 + thermalMitigationResult);
9640 }
9641
9642 return thermalMitigationResult;
9643 }
Hui Wang641e81c2020-10-12 12:14:23 -07009644
9645 /**
9646 * Set the GbaService Package Name that Telephony will bind to.
9647 *
9648 * @param subId The sim that the GbaService is associated with.
9649 * @param packageName The name of the package to be replaced with.
9650 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9651 */
9652 @Override
9653 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9654 enforceModifyPermission();
9655
9656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 return getGbaManager(subId).overrideServicePackage(packageName);
9659 } finally {
9660 Binder.restoreCallingIdentity(identity);
9661 }
9662 }
9663
9664 /**
9665 * Return the package name of the currently bound GbaService.
9666 *
9667 * @param subId The sim that the GbaService is associated with.
9668 * @return the package name of the GbaService configuration, null if GBA is not supported.
9669 */
9670 @Override
9671 public String getBoundGbaService(int subId) {
9672 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9673
9674 final long identity = Binder.clearCallingIdentity();
9675 try {
9676 return getGbaManager(subId).getServicePackage();
9677 } finally {
9678 Binder.restoreCallingIdentity(identity);
9679 }
9680 }
9681
9682 /**
9683 * Set the release time for telephony to unbind GbaService.
9684 *
9685 * @param subId The sim that the GbaService is associated with.
9686 * @param interval The release time to unbind GbaService by millisecond.
9687 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9688 */
9689 @Override
9690 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9691 enforceModifyPermission();
9692
9693 final long identity = Binder.clearCallingIdentity();
9694 try {
9695 return getGbaManager(subId).overrideReleaseTime(interval);
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699 }
9700
9701 /**
9702 * Return the release time for telephony to unbind GbaService.
9703 *
9704 * @param subId The sim that the GbaService is associated with.
9705 * @return The release time to unbind GbaService by millisecond.
9706 */
9707 @Override
9708 public int getGbaReleaseTime(int subId) {
9709 enforceReadPrivilegedPermission("getGbaReleaseTime");
9710
9711 final long identity = Binder.clearCallingIdentity();
9712 try {
9713 return getGbaManager(subId).getReleaseTime();
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
9719 private GbaManager getGbaManager(int subId) {
9720 GbaManager instance = GbaManager.getInstance(subId);
9721 if (instance == null) {
9722 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9723 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9724 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9725 }
9726 return instance;
9727 }
Hui Wang761a6682020-10-31 05:12:53 +00009728
9729 /**
9730 * indicate whether the device and the carrier can support
9731 * RCS VoLTE single registration.
9732 */
9733 @Override
9734 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9735 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9736
9737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9739 }
9740
9741 final long identity = Binder.clearCallingIdentity();
9742 try {
9743 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9744 if (rpm != null) {
9745 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9746 }
9747 return false;
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 /**
9754 * Register RCS provisioning callback.
9755 */
9756 @Override
9757 public void registerRcsProvisioningChangedCallback(int subId,
9758 IRcsConfigCallback callback) {
9759 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9760
9761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9762 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9763 }
9764 if (!isImsAvailableOnDevice()) {
9765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9766 "IMS not available on device.");
9767 }
9768
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009771 if (!RcsProvisioningMonitor.getInstance()
9772 .registerRcsProvisioningChangedCallback(subId, callback)) {
9773 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9774 "Service not available for the subscription.");
9775 }
Hui Wang761a6682020-10-31 05:12:53 +00009776 } finally {
9777 Binder.restoreCallingIdentity(identity);
9778 }
9779 }
9780
9781 /**
9782 * Unregister RCS provisioning callback.
9783 */
9784 @Override
9785 public void unregisterRcsProvisioningChangedCallback(int subId,
9786 IRcsConfigCallback callback) {
9787 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9788
9789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9791 }
9792 if (!isImsAvailableOnDevice()) {
9793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9794 "IMS not available on device.");
9795 }
9796
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009799 RcsProvisioningMonitor.getInstance()
9800 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
9805
9806 /**
9807 * trigger RCS reconfiguration.
9808 */
9809 public void triggerRcsReconfiguration(int subId) {
9810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9811 mApp, subId, "triggerRcsReconfiguration");
9812
9813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9814 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9815 }
9816 if (!isImsAvailableOnDevice()) {
9817 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9818 "IMS not available on device.");
9819 }
9820
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9824 } finally {
9825 Binder.restoreCallingIdentity(identity);
9826 }
9827 }
9828
9829 /**
9830 * Provide the client configuration parameters of the RCS application.
9831 */
9832 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9834 mApp, subId, "setRcsClientConfiguration");
9835
9836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9837 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9838 }
9839 if (!isImsAvailableOnDevice()) {
9840 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9841 "IMS not available on device.");
9842 }
9843
9844 final long identity = Binder.clearCallingIdentity();
9845
9846 try {
9847 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9848 if (configBinder == null) {
9849 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9850 } else {
9851 configBinder.setRcsClientConfiguration(rcc);
9852 }
9853 } catch (RemoteException e) {
9854 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
9858 }
9859
9860 /**
9861 * Overrides the config of RCS VoLTE single registration enabled for the device.
9862 */
9863 @Override
9864 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9866 "setDeviceSingleRegistrationEnabledOverride");
9867 enforceModifyPermission();
9868
9869 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9870 : Boolean.parseBoolean(enabledStr);
9871 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009872 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009873 }
9874
9875 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009876 * Sends a device to device communication message. Only usable via shell.
9877 * @param message message to send.
9878 * @param value message value.
9879 */
9880 @Override
9881 public void sendDeviceToDeviceMessage(int message, int value) {
9882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9883 "setCarrierSingleRegistrationEnabledOverride");
9884 enforceModifyPermission();
9885
9886 final long identity = Binder.clearCallingIdentity();
9887 try {
9888 TelephonyConnectionService service =
9889 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9890 if (service == null) {
9891 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9892 return;
9893 }
9894 service.sendTestDeviceToDeviceMessage(message, value);
9895 } finally {
9896 Binder.restoreCallingIdentity(identity);
9897 }
9898 }
9899
9900
9901 /**
Hui Wang761a6682020-10-31 05:12:53 +00009902 * Gets the config of RCS VoLTE single registration enabled for the device.
9903 */
9904 @Override
9905 public boolean getDeviceSingleRegistrationEnabled() {
9906 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9907 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9908 }
9909
9910 /**
9911 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9912 */
9913 @Override
9914 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9916 "setCarrierSingleRegistrationEnabledOverride");
9917 enforceModifyPermission();
9918
9919 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9920 : Boolean.parseBoolean(enabledStr);
9921 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9922 subId, enabled);
9923 }
9924
9925 /**
9926 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9927 */
9928 @Override
9929 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9930 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9931 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9932 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009933
9934 /**
9935 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9936 * their mobile plan.
9937 */
9938 @Override
9939 public String getMobileProvisioningUrl() {
9940 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
9943 return getDefaultPhone().getMobileProvisioningUrl();
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009948
James.cf Linbcdf8b32021-01-14 16:44:13 +08009949 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009950 * Get the EAB contact from the EAB database.
9951 */
9952 @Override
9953 public String getContactFromEab(String contact) {
9954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9955 enforceModifyPermission();
9956 final long identity = Binder.clearCallingIdentity();
9957 try {
9958 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
9964 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009965 * Remove the EAB contacts from the EAB database.
9966 */
9967 @Override
9968 public int removeContactFromEab(int subId, String contacts) {
9969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9970 enforceModifyPermission();
9971 final long identity = Binder.clearCallingIdentity();
9972 try {
9973 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9974 } finally {
9975 Binder.restoreCallingIdentity(identity);
9976 }
9977 }
9978
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009979 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009980 public boolean getDeviceUceEnabled() {
9981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9982 final long identity = Binder.clearCallingIdentity();
9983 try {
9984 return mApp.getDeviceUceEnabled();
9985 } finally {
9986 Binder.restoreCallingIdentity(identity);
9987 }
9988 }
9989
9990 @Override
9991 public void setDeviceUceEnabled(boolean isEnabled) {
9992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9993 final long identity = Binder.clearCallingIdentity();
9994 try {
9995 mApp.setDeviceUceEnabled(isEnabled);
9996 } finally {
9997 Binder.restoreCallingIdentity(identity);
9998 }
9999 }
10000
10001 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010002 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10003 String callingPackage) {
10004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10005 mApp, subId, "setSignalStrengthUpdateRequest");
10006
10007 final int callingUid = Binder.getCallingUid();
10008 // Verify that tha callingPackage belongs to the calling UID
10009 mApp.getSystemService(AppOpsManager.class)
10010 .checkPackage(callingUid, callingPackage);
10011
10012 validateSignalStrengthUpdateRequest(request, callingUid);
10013
10014 final long identity = Binder.clearCallingIdentity();
10015 try {
10016 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10017 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10018
10019 if (result instanceof IllegalStateException) {
10020 throw (IllegalStateException) result;
10021 }
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
10024 }
10025 }
10026
10027 @Override
10028 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10029 String callingPackage) {
10030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10031 mApp, subId, "clearSignalStrengthUpdateRequest");
10032
10033 final int callingUid = Binder.getCallingUid();
10034 // Verify that tha callingPackage belongs to the calling UID
10035 mApp.getSystemService(AppOpsManager.class)
10036 .checkPackage(callingUid, callingPackage);
10037
10038 final long identity = Binder.clearCallingIdentity();
10039 try {
10040 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10041 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10042
10043 if (result instanceof IllegalStateException) {
10044 throw (IllegalStateException) result;
10045 }
10046 } finally {
10047 Binder.restoreCallingIdentity(identity);
10048 }
10049 }
10050
10051 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10052 int callingUid) {
10053 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10054 // phone/system process do not have further restriction on request
10055 return;
10056 }
10057
10058 // Applications has restrictions on how to use the request:
10059 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10060 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10061 // This is not system caller which has been checked above
10062 throw new IllegalArgumentException(
10063 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10064 }
10065
10066 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10067 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10068 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10069 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10070 || info.isEnabled()) {
10071 throw new IllegalArgumentException(
10072 "Only system can set hide fields in SignalThresholdInfo");
10073 }
10074
10075 // Thresholds length for each RAN need in range. This has been validated in
10076 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10077 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10078 final int[] thresholds = info.getThresholds();
10079 Objects.requireNonNull(thresholds);
10080 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10081 || thresholds.length
10082 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10083 throw new IllegalArgumentException(
10084 "thresholds length is out of range: " + thresholds.length);
10085 }
10086 }
10087 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010088
10089 /**
10090 * Gets the current phone capability.
10091 *
10092 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10093 * @return the PhoneCapability which describes the data connection capability of modem.
10094 * It's used to evaluate possible phone config change, for example from single
10095 * SIM device to multi-SIM device.
10096 */
10097 @Override
10098 public PhoneCapability getPhoneCapability() {
10099 enforceReadPrivilegedPermission("getPhoneCapability");
10100 final long identity = Binder.clearCallingIdentity();
10101 try {
10102 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10103 } finally {
10104 Binder.restoreCallingIdentity(identity);
10105 }
10106 }
Michele Berionne5e411512020-11-13 02:36:59 +000010107
10108 /**
10109 * Prepare TelephonyManager for an unattended reboot. The reboot is
10110 * required to be done shortly after the API is invoked.
10111 */
10112 @Override
10113 @TelephonyManager.PrepareUnattendedRebootResult
10114 public int prepareForUnattendedReboot() {
10115 enforceRebootPermission();
10116
10117 final long identity = Binder.clearCallingIdentity();
10118 try {
10119 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010124}