blob: 1410770f7c3f609cb23cd77868948c54390a9592 [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;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070058import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080066import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080078import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070079import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070080import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070081import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080082import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070085import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080086import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080087import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070088import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080090import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080093import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080095import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070096import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800100import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000101import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700102import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800104import android.telephony.data.ApnSetting;
105import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700106import android.telephony.gba.GbaAuthRequest;
107import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700108import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800109import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000110import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700111import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800113import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700114import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700116import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700118import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800119import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800120import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800122import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800124import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700125import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800127import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800128
Andrew Lee312e8172014-10-23 17:01:36 -0700129import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800130import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700133import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700134import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800135import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700136import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800138import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800141import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800142import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700143import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700144import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800145import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800147import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700149import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700150import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700152import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800153import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700154import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700155import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700156import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700157import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700158import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700160import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700161import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800162import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800163import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800164import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700165import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800166import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700167import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800168import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700169import com.android.internal.telephony.imsphone.ImsPhone;
170import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800171import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700172import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800174import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800176import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700177import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800180import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000181import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800182import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700183import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700184import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800185import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700186import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700187import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800188import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700189import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700190import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800191import com.android.services.telephony.TelecomAccountRegistry;
192import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800193import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800194
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700195import java.io.FileDescriptor;
196import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800198import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800199import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800200import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800201import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100202import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700204import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800206import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800207import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208
209/**
210 * Implementation of the ITelephony interface.
211 */
Santos Cordon117fee72014-05-16 17:56:12 -0700212public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 private static final String LOG_TAG = "PhoneInterfaceManager";
214 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
215 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
218 // Message codes used with mMainThreadHandler
219 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700220 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
221 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700222 private static final int CMD_OPEN_CHANNEL = 9;
223 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
224 private static final int CMD_CLOSE_CHANNEL = 11;
225 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800226 private static final int CMD_NV_READ_ITEM = 13;
227 private static final int EVENT_NV_READ_ITEM_DONE = 14;
228 private static final int CMD_NV_WRITE_ITEM = 15;
229 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
230 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
231 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700232 private static final int CMD_RESET_MODEM_CONFIG = 19;
233 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800234 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
235 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
236 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
237 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800238 private static final int CMD_SEND_ENVELOPE = 25;
239 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000240 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
241 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700242 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
243 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
244 private static final int CMD_EXCHANGE_SIM_IO = 31;
245 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800246 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
247 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700248 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
249 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700250 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
251 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700252 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
253 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
254 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
255 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700256 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
257 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
258 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
259 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700260 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800261 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
262 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000263 private static final int CMD_SWITCH_SLOTS = 50;
264 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700265 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
266 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
267 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
268 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
269 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
270 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
271 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
272 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700273 private static final int CMD_GET_ALL_CELL_INFO = 60;
274 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
275 private static final int CMD_GET_CELL_LOCATION = 62;
276 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700277 private static final int CMD_MODEM_REBOOT = 64;
278 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700279 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
280 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800281 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
282 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283 private static final int CMD_GET_MODEM_STATUS = 70;
284 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700285 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
286 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700287 private static final int CMD_ERASE_MODEM_CONFIG = 74;
288 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800289 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
290 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
291 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
292 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800293 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
294 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800295 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800296 private static final int CMD_GET_CALL_FORWARDING = 83;
297 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
298 private static final int CMD_SET_CALL_FORWARDING = 85;
299 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
300 private static final int CMD_GET_CALL_WAITING = 87;
301 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
302 private static final int CMD_SET_CALL_WAITING = 89;
303 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700304 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
305 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
306 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
307 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700308 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
309 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800310 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
311 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800312 private static final int CMD_SET_DATA_THROTTLING = 99;
313 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800314 private static final int CMD_SET_SIM_POWER = 101;
315 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800317 // Parameters of select command.
318 private static final int SELECT_COMMAND = 0xA4;
319 private static final int SELECT_P1 = 0x04;
320 private static final int SELECT_P2 = 0;
321 private static final int SELECT_P3 = 0x10;
322
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 /** The singleton instance. */
324 private static PhoneInterfaceManager sInstance;
325
Wink Saville3ab207e2014-11-20 13:07:20 -0800326 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800327 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800328 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700329 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800330 private AppOpsManager mAppOps;
331 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800332 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800333 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700334 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335
Peter Wangdafb9ac2020-01-15 14:13:38 -0800336 /** User Activity */
337 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800338 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
339
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700340 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
341
Derek Tan97ebb422014-09-05 16:55:38 -0700342 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
343 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800344 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800345 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700346
Michelecea4cf22018-12-21 15:00:11 -0800347 // String to store multi SIM allowed
348 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
349
Derek Tan740e1672017-06-27 14:56:27 -0700350 // The AID of ISD-R.
351 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
352
yinxub1bed742017-04-17 11:45:04 -0700353 private NetworkScanRequestTracker mNetworkScanRequestTracker;
354
David Kelly5e06a7f2018-03-12 14:10:59 +0000355 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
356 private static final int MANUFACTURER_CODE_LENGTH = 8;
357
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800358 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
359
Derek Tan89e89d42014-07-08 17:00:10 -0700360 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700361 * Experiment flag to enable erase modem config on reset network, default value is false
362 */
363 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
364 "reset_network_erase_modem_config_enabled";
365
366 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700367 * A request object to use for transmitting data to an ICC.
368 */
369 private static final class IccAPDUArgument {
370 public int channel, cla, command, p1, p2, p3;
371 public String data;
372
373 public IccAPDUArgument(int channel, int cla, int command,
374 int p1, int p2, int p3, String data) {
375 this.channel = channel;
376 this.cla = cla;
377 this.command = command;
378 this.p1 = p1;
379 this.p2 = p2;
380 this.p3 = p3;
381 this.data = data;
382 }
383 }
384
385 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700386 * A request object to use for transmitting data to an ICC.
387 */
388 private static final class ManualNetworkSelectionArgument {
389 public OperatorInfo operatorInfo;
390 public boolean persistSelection;
391
392 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
393 this.operatorInfo = operatorInfo;
394 this.persistSelection = persistSelection;
395 }
396 }
397
398 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
400 * request after sending. The main thread will notify the request when it is complete.
401 */
402 private static final class MainThreadRequest {
403 /** The argument to use for the request */
404 public Object argument;
405 /** The result of the request that is run on the main thread */
406 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800407 // The subscriber id that this request applies to. Defaults to
408 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
409 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410
Nathan Harold92bed182018-10-12 18:16:49 -0700411 // In cases where subId is unavailable, the caller needs to specify the phone.
412 public Phone phone;
413
vagdeviaf9a5b92018-08-15 16:01:53 -0700414 public WorkSource workSource;
415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 public MainThreadRequest(Object argument) {
417 this.argument = argument;
418 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800419
Nathan Harold92bed182018-10-12 18:16:49 -0700420 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
421 this.argument = argument;
422 if (phone != null) {
423 this.phone = phone;
424 }
425 this.workSource = workSource;
426 }
427
vagdeviaf9a5b92018-08-15 16:01:53 -0700428 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800429 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800430 if (subId != null) {
431 this.subId = subId;
432 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700433 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 }
436
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800437 private static final class IncomingThirdPartyCallArgs {
438 public final ComponentName component;
439 public final String callId;
440 public final String callerDisplayName;
441
442 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
443 String callerDisplayName) {
444 this.component = component;
445 this.callId = callId;
446 this.callerDisplayName = callerDisplayName;
447 }
448 }
449
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 /**
451 * A handler that processes messages on the main thread in the phone process. Since many
452 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
453 * inbound binder threads to the main thread in the phone process. The Binder thread
454 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
455 * on, which will be notified when the operation completes and will contain the result of the
456 * request.
457 *
458 * <p>If a MainThreadRequest object is provided in the msg.obj field,
459 * note that request.result must be set to something non-null for the calling thread to
460 * unblock.
461 */
462 private final class MainThreadHandler extends Handler {
463 @Override
464 public void handleMessage(Message msg) {
465 MainThreadRequest request;
466 Message onCompleted;
467 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800470 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471
472 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700473 case CMD_HANDLE_USSD_REQUEST: {
474 request = (MainThreadRequest) msg.obj;
475 final Phone phone = getPhoneFromRequest(request);
476 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
477 String ussdRequest = ussdObject.first;
478 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700479
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 if (!isUssdApiAllowed(request.subId)) {
481 // Carrier does not support use of this API, return failure.
482 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
483 UssdResponse response = new UssdResponse(ussdRequest, null);
484 Bundle returnData = new Bundle();
485 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
486 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700487
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 request.result = true;
489 notifyRequester(request);
490 return;
491 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700492
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 try {
494 request.result = phone != null
495 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
496 } catch (CallStateException cse) {
497 request.result = false;
498 }
499 // Wake up the requesting thread
500 notifyRequester(request);
501 break;
pkanwar32d516d2016-10-14 19:37:38 -0700502 }
503
Yorke Lee716f67e2015-06-17 15:39:16 -0700504 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700506 final Phone phone = getPhoneFromRequest(request);
507 request.result = phone != null ?
508 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
509 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700519 if (uiccCard == null) {
520 loge("iccTransmitApduLogicalChannel: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
525 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 iccArgument.channel, iccArgument.cla, iccArgument.command,
528 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 break;
532
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
538 } else {
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800542 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800544 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 } else {
546 loge("iccTransmitApduLogicalChannel: Unknown exception");
547 }
548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 break;
551
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
553 request = (MainThreadRequest) msg.obj;
554 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 if (uiccCard == null) {
557 loge("iccTransmitApduBasicChannel: No UICC");
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
562 request);
563 uiccCard.iccTransmitApduBasicChannel(
564 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
565 iccArgument.p3, iccArgument.data, onCompleted);
566 }
567 break;
568
569 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
570 ar = (AsyncResult) msg.obj;
571 request = (MainThreadRequest) ar.userObj;
572 if (ar.exception == null && ar.result != null) {
573 request.result = ar.result;
574 } else {
575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
576 if (ar.result == null) {
577 loge("iccTransmitApduBasicChannel: Empty response");
578 } else if (ar.exception instanceof CommandException) {
579 loge("iccTransmitApduBasicChannel: CommandException: " +
580 ar.exception);
581 } else {
582 loge("iccTransmitApduBasicChannel: Unknown exception");
583 }
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
588 case CMD_EXCHANGE_SIM_IO:
589 request = (MainThreadRequest) msg.obj;
590 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800591 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 if (uiccCard == null) {
593 loge("iccExchangeSimIO: No UICC");
594 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 } else {
597 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
598 request);
599 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
600 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
601 iccArgument.data, onCompleted);
602 }
603 break;
604
605 case EVENT_EXCHANGE_SIM_IO_DONE:
606 ar = (AsyncResult) msg.obj;
607 request = (MainThreadRequest) ar.userObj;
608 if (ar.exception == null && ar.result != null) {
609 request.result = ar.result;
610 } else {
611 request.result = new IccIoResult(0x6f, 0, (byte[])null);
612 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 break;
615
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 case CMD_SEND_ENVELOPE:
617 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800618 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 if (uiccCard == null) {
620 loge("sendEnvelopeWithStatus: No UICC");
621 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 } else {
624 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
625 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
626 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 break;
628
629 case EVENT_SEND_ENVELOPE_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700632 if (ar.exception == null && ar.result != null) {
633 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800634 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700635 request.result = new IccIoResult(0x6F, 0, (byte[])null);
636 if (ar.result == null) {
637 loge("sendEnvelopeWithStatus: Empty response");
638 } else if (ar.exception instanceof CommandException) {
639 loge("sendEnvelopeWithStatus: CommandException: " +
640 ar.exception);
641 } else {
642 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
643 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 break;
647
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 case CMD_OPEN_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800651 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800654 request.result = new IccOpenLogicalChannelResponse(-1,
655 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800659 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
660 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_OPEN_CHANNEL_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 int[] result = (int[]) ar.result;
670 int channelId = result[0];
671 byte[] selectResponse = null;
672 if (result.length > 1) {
673 selectResponse = new byte[result.length - 1];
674 for (int i = 1; i < result.length; ++i) {
675 selectResponse[i - 1] = (byte) result[i];
676 }
677 }
678 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700679 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.result == null) {
682 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 if (ar.exception != null) {
685 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
686 }
687
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700688 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700689 if (ar.exception instanceof CommandException) {
690 CommandException.Error error =
691 ((CommandException) (ar.exception)).getCommandError();
692 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700693 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700694 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 }
697 }
698 openChannelResp = new IccOpenLogicalChannelResponse(
699 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700701 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 break;
704
705 case CMD_CLOSE_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800707 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700708 if (uiccCard == null) {
709 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900710 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 } else {
713 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
714 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
715 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 break;
717
718 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800719 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
720 break;
721
722 case CMD_NV_READ_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800725 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
726 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800735 request.result = "";
736 if (ar.result == null) {
737 loge("nvReadItem: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("nvReadItem: CommandException: " +
740 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800742 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 break;
747
Jake Hambye994d462014-02-03 13:10:13 -0800748 case CMD_NV_WRITE_ITEM:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
751 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800752 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700753 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800754 break;
755
756 case EVENT_NV_WRITE_ITEM_DONE:
757 handleNullReturnEvent(msg, "nvWriteItem");
758 break;
759
760 case CMD_NV_WRITE_CDMA_PRL:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800764 break;
765
766 case EVENT_NV_WRITE_CDMA_PRL_DONE:
767 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
768 break;
769
chen xu6dac5ab2018-10-26 17:39:23 -0700770 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800771 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700772 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800773 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800774 break;
775
chen xu6dac5ab2018-10-26 17:39:23 -0700776 case EVENT_RESET_MODEM_CONFIG_DONE:
777 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
Sooraj Sasindran37444802020-08-11 10:40:43 -0700780 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
783 request);
784 Phone phone = getPhoneFromRequest(request);
785 if (phone != null) {
786 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
787 } else {
788 loge("isNRDualConnectivityEnabled: No phone object");
789 request.result = false;
790 notifyRequester(request);
791 }
792 break;
793 }
794
795 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 if (ar.exception == null && ar.result != null) {
799 request.result = ar.result;
800 } else {
801 // request.result must be set to something non-null
802 // for the calling thread to unblock
803 if (request.result != null) {
804 request.result = ar.result;
805 } else {
806 request.result = false;
807 }
808 if (ar.result == null) {
809 loge("isNRDualConnectivityEnabled: Empty response");
810 } else if (ar.exception instanceof CommandException) {
811 loge("isNRDualConnectivityEnabled: CommandException: "
812 + ar.exception);
813 } else {
814 loge("isNRDualConnectivityEnabled: Unknown exception");
815 }
816 }
817 notifyRequester(request);
818 break;
819
820 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
823 Phone phone = getPhoneFromRequest(request);
824 if (phone != null) {
825 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
826 request.workSource);
827 } else {
828 loge("enableNrDualConnectivity: No phone object");
829 request.result =
830 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
831 notifyRequester(request);
832 }
833 break;
834 }
835
836 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null) {
840 request.result =
841 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
842 } else {
843 request.result =
844 TelephonyManager
845 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
846 if (ar.exception instanceof CommandException) {
847 CommandException.Error error =
848 ((CommandException) (ar.exception)).getCommandError();
849 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
850 request.result =
851 TelephonyManager
852 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
853 }
854 loge("enableNrDualConnectivity" + ": CommandException: "
855 + ar.exception);
856 } else {
857 loge("enableNrDualConnectivity" + ": Unknown exception");
858 }
859 }
860 notifyRequester(request);
861 break;
862 }
863
Jake Hamby7c27be32014-03-03 13:25:59 -0800864 case CMD_GET_PREFERRED_NETWORK_TYPE:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700867 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800868 break;
869
870 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result; // Integer
875 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530876 // request.result must be set to something non-null
877 // for the calling thread to unblock
878 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 if (ar.result == null) {
880 loge("getPreferredNetworkType: Empty response");
881 } else if (ar.exception instanceof CommandException) {
882 loge("getPreferredNetworkType: CommandException: " +
883 ar.exception);
884 } else {
885 loge("getPreferredNetworkType: Unknown exception");
886 }
887 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700888 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 break;
890
891 case CMD_SET_PREFERRED_NETWORK_TYPE:
892 request = (MainThreadRequest) msg.obj;
893 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
894 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700895 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 break;
897
898 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
899 handleNullReturnEvent(msg, "setPreferredNetworkType");
900 break;
901
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000902 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
903 request = (MainThreadRequest)msg.obj;
904 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800905 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000906 break;
907
908 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
909 ar = (AsyncResult)msg.obj;
910 request = (MainThreadRequest)ar.userObj;
911 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 break;
914
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800915 case CMD_SET_VOICEMAIL_NUMBER:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
918 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800919 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
920 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800921 break;
922
923 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
924 handleNullReturnEvent(msg, "setVoicemailNumber");
925 break;
926
Stuart Scott54788802015-03-30 13:18:01 -0700927 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
930 request);
931 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
932 break;
933
934 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
935 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
936 break;
937
Shishir Agrawal302c8692015-06-19 13:49:39 -0700938 case CMD_PERFORM_NETWORK_SCAN:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
941 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
942 break;
943
Hall Liu27d24262020-09-18 19:04:59 -0700944 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700947 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
948 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
949 request.argument;
950 int callForwardingReason = args.first;
951 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800952 break;
Hall Liu27d24262020-09-18 19:04:59 -0700953 }
954 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700957 TelephonyManager.CallForwardingInfoCallback callback =
958 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
959 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800960 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700961 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800962 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
963 for (CallForwardInfo callForwardInfo : callForwardInfos) {
964 // Service Class is a bit mask per 3gpp 27.007. Search for
965 // any service for voice call.
966 if ((callForwardInfo.serviceClass
967 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700968 callForwardingInfo = new CallForwardingInfo(true,
969 callForwardInfo.reason,
970 callForwardInfo.number,
971 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800972 break;
973 }
974 }
975 // Didn't find a call forward info for voice call.
976 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700977 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
978 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800979 }
Hall Liu27d24262020-09-18 19:04:59 -0700980 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800981 } else {
982 if (ar.result == null) {
983 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
984 }
985 if (ar.exception != null) {
986 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
987 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700988 int errorCode = TelephonyManager
989 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700994 errorCode = TelephonyManager
995 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800996 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700997 errorCode = TelephonyManager
998 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800999 }
1000 }
Hall Liu27d24262020-09-18 19:04:59 -07001001 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001002 }
Shuo Qian4a594052020-01-23 11:59:30 -08001003 break;
Hall Liu27d24262020-09-18 19:04:59 -07001004 }
Shuo Qian4a594052020-01-23 11:59:30 -08001005
Hall Liu27d24262020-09-18 19:04:59 -07001006 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001009 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001010 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001011 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1012 request.argument).first;
1013 request.phone.setCallForwardingOption(
1014 callForwardingInfoToSet.isEnabled()
1015 ? CommandsInterface.CF_ACTION_ENABLE
1016 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001017 callForwardingInfoToSet.getReason(),
1018 callForwardingInfoToSet.getNumber(),
1019 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1020 break;
Hall Liu27d24262020-09-18 19:04:59 -07001021 }
Shuo Qian4a594052020-01-23 11:59:30 -08001022
Hall Liu27d24262020-09-18 19:04:59 -07001023 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001026 Consumer<Integer> callback =
1027 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1028 request.argument).second;
1029 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001030 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001031 int errorCode = TelephonyManager.CallForwardingInfoCallback
1032 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001033 if (ar.exception instanceof CommandException) {
1034 CommandException.Error error =
1035 ((CommandException) (ar.exception)).getCommandError();
1036 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager.CallForwardingInfoCallback
1038 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001039 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager.CallForwardingInfoCallback
1041 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001042 }
1043 }
1044 callback.accept(errorCode);
1045 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001046 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001047 }
Shuo Qian4a594052020-01-23 11:59:30 -08001048 break;
Hall Liu27d24262020-09-18 19:04:59 -07001049 }
Shuo Qian4a594052020-01-23 11:59:30 -08001050
Hall Liu27d24262020-09-18 19:04:59 -07001051 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1054 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1055 break;
Hall Liu27d24262020-09-18 19:04:59 -07001056 }
Shuo Qian4a594052020-01-23 11:59:30 -08001057
Hall Liu27d24262020-09-18 19:04:59 -07001058 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001061 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001062 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1063 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001064 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001065 // Service Class is a bit mask per 3gpp 27.007.
1066 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001067 if (callForwardResults.length > 1
1068 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001069 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001070 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001071 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1072 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001073 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001074 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001075 }
1076 } else {
1077 if (ar.result == null) {
1078 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1079 }
1080 if (ar.exception != null) {
1081 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1082 }
1083 if (ar.exception instanceof CommandException) {
1084 CommandException.Error error =
1085 ((CommandException) (ar.exception)).getCommandError();
1086 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1087 callForwardingStatus =
1088 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1089 }
1090 }
1091 }
Hall Liu27d24262020-09-18 19:04:59 -07001092 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001093 break;
Hall Liu27d24262020-09-18 19:04:59 -07001094 }
Shuo Qian4a594052020-01-23 11:59:30 -08001095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001099 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1100 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001101 break;
Hall Liu27d24262020-09-18 19:04:59 -07001102 }
Shuo Qian4a594052020-01-23 11:59:30 -08001103
Hall Liu27d24262020-09-18 19:04:59 -07001104 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1108 Consumer<Integer> callback =
1109 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1110 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001111 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001112 if (ar.exception instanceof CommandException) {
1113 CommandException.Error error =
1114 ((CommandException) (ar.exception)).getCommandError();
1115 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1116 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1117 } else {
1118 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1119 }
1120 } else {
1121 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1122 }
1123 } else {
1124 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1125 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001126 }
Shuo Qian4a594052020-01-23 11:59:30 -08001127 break;
Hall Liu27d24262020-09-18 19:04:59 -07001128 }
Shuo Qian4a594052020-01-23 11:59:30 -08001129
Shishir Agrawal302c8692015-06-19 13:49:39 -07001130 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 CellNetworkScanResult cellScanResult;
1134 if (ar.exception == null && ar.result != null) {
1135 cellScanResult = new CellNetworkScanResult(
1136 CellNetworkScanResult.STATUS_SUCCESS,
1137 (List<OperatorInfo>) ar.result);
1138 } else {
1139 if (ar.result == null) {
1140 loge("getCellNetworkScanResults: Empty response");
1141 }
1142 if (ar.exception != null) {
1143 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1144 }
1145 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1146 if (ar.exception instanceof CommandException) {
1147 CommandException.Error error =
1148 ((CommandException) (ar.exception)).getCommandError();
1149 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1150 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1151 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1152 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1153 }
1154 }
1155 cellScanResult = new CellNetworkScanResult(errorCode, null);
1156 }
1157 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001159 break;
1160
1161 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1162 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001163 ManualNetworkSelectionArgument selArg =
1164 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1166 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001167 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1168 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001169 break;
1170
1171 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001172 ar = (AsyncResult) msg.obj;
1173 request = (MainThreadRequest) ar.userObj;
1174 if (ar.exception == null) {
1175 request.result = true;
1176 } else {
1177 request.result = false;
1178 loge("setNetworkSelectionModeManual " + ar.exception);
1179 }
1180 notifyRequester(request);
1181 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 break;
1183
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001184 case CMD_GET_MODEM_ACTIVITY_INFO:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001187 if (defaultPhone != null) {
1188 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001189 } else {
1190 ResultReceiver result = (ResultReceiver) request.argument;
1191 Bundle bundle = new Bundle();
1192 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001193 new ModemActivityInfo(0, 0, 0,
1194 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001195 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001196 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001197 break;
1198
Hall Liud0f208c2020-10-14 16:54:44 -07001199 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001202 ResultReceiver result = (ResultReceiver) request.argument;
1203
Hall Liud0f208c2020-10-14 16:54:44 -07001204 ModemActivityInfo ret = null;
1205 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001206 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001207 // Update the last modem activity info and the result of the request.
1208 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1209 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001210 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001211 int[] txTimeMs = info.getTransmitTimeMillis();
1212 int[] lastModemTxTimeMs = mLastModemActivityInfo
1213 .getTransmitTimeMillis();
1214 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1215 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1216 }
Hall Liu49656c02020-10-09 19:00:11 -07001217 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001218 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1219 + mLastModemActivityInfo.getSleepTimeMillis());
1220 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1221 + mLastModemActivityInfo.getIdleTimeMillis());
1222 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1223 mLastModemActivityInfo.setReceiveTimeMillis(
1224 info.getReceiveTimeMillis()
1225 + mLastModemActivityInfo.getReceiveTimeMillis());
1226 }
Hall Liu49656c02020-10-09 19:00:11 -07001227 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001228 mLastModemActivityInfo.getSleepTimeMillis(),
1229 mLastModemActivityInfo.getIdleTimeMillis(),
1230 mLastModemActivityInfo.getTransmitTimeMillis(),
1231 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001232 } else {
1233 if (ar.result == null) {
1234 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001235 error = TelephonyManager.ModemActivityInfoException
1236 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 } else if (ar.exception instanceof CommandException) {
1238 loge("queryModemActivityInfo: CommandException: " +
1239 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001240 error = TelephonyManager.ModemActivityInfoException
1241 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 } else {
1243 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001244 error = TelephonyManager.ModemActivityInfoException
1245 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001246 }
1247 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001248 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001249 if (ret != null) {
1250 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1251 } else {
1252 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1253 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001254 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001255 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001256 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001257 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001258
Meng Wang1a7c35a2016-05-05 20:56:15 -07001259 case CMD_SET_ALLOWED_CARRIERS:
1260 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001261 CarrierRestrictionRules argument =
1262 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001264 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 break;
1266
1267 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
1270 if (ar.exception == null && ar.result != null) {
1271 request.result = ar.result;
1272 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001273 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1274 if (ar.exception instanceof CommandException) {
1275 loge("setAllowedCarriers: CommandException: " + ar.exception);
1276 CommandException.Error error =
1277 ((CommandException) (ar.exception)).getCommandError();
1278 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1279 request.result =
1280 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1281 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 } else {
1283 loge("setAllowedCarriers: Unknown exception");
1284 }
1285 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001286 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001287 break;
1288
1289 case CMD_GET_ALLOWED_CARRIERS:
1290 request = (MainThreadRequest) msg.obj;
1291 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001292 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 break;
1294
1295 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
1298 if (ar.exception == null && ar.result != null) {
1299 request.result = ar.result;
1300 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001301 request.result = new IllegalStateException(
1302 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 if (ar.result == null) {
1304 loge("getAllowedCarriers: Empty response");
1305 } else if (ar.exception instanceof CommandException) {
1306 loge("getAllowedCarriers: CommandException: " +
1307 ar.exception);
1308 } else {
1309 loge("getAllowedCarriers: Unknown exception");
1310 }
1311 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001313 break;
1314
Nathan Haroldb3014052017-01-25 15:57:32 -08001315 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
1318 if (ar.exception == null && ar.result != null) {
1319 request.result = ar.result;
1320 } else {
1321 request.result = new IllegalArgumentException(
1322 "Failed to retrieve Forbidden Plmns");
1323 if (ar.result == null) {
1324 loge("getForbiddenPlmns: Empty response");
1325 } else {
1326 loge("getForbiddenPlmns: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001330 break;
1331
1332 case CMD_GET_FORBIDDEN_PLMNS:
1333 request = (MainThreadRequest) msg.obj;
1334 uiccCard = getUiccCardFromRequest(request);
1335 if (uiccCard == null) {
1336 loge("getForbiddenPlmns() UiccCard is null");
1337 request.result = new IllegalArgumentException(
1338 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001339 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001340 break;
1341 }
1342 Integer appType = (Integer) request.argument;
1343 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1344 if (uiccApp == null) {
1345 loge("getForbiddenPlmns() no app with specified type -- "
1346 + appType);
1347 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001349 break;
1350 } else {
1351 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1352 + " specified type -- " + appType);
1353 }
1354 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1355 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1356 onCompleted);
1357 break;
1358
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001359 case CMD_SWITCH_SLOTS:
1360 request = (MainThreadRequest) msg.obj;
1361 int[] physicalSlots = (int[]) request.argument;
1362 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1363 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1364 break;
1365
1366 case EVENT_SWITCH_SLOTS_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
1371 break;
1372 case CMD_GET_NETWORK_SELECTION_MODE:
1373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1375 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1376 break;
1377
1378 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
1381 if (ar.exception != null) {
1382 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1383 } else {
1384 int mode = ((int[]) ar.result)[0];
1385 if (mode == 0) {
1386 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1387 } else {
1388 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1389 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001390 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
1392 break;
1393 case CMD_GET_CDMA_ROAMING_MODE:
1394 request = (MainThreadRequest) msg.obj;
1395 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1396 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1397 break;
1398 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception != null) {
1402 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1403 } else {
1404 request.result = ((int[]) ar.result)[0];
1405 }
1406 notifyRequester(request);
1407 break;
1408 case CMD_SET_CDMA_ROAMING_MODE:
1409 request = (MainThreadRequest) msg.obj;
1410 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1411 int mode = (int) request.argument;
1412 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1413 break;
1414 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1415 ar = (AsyncResult) msg.obj;
1416 request = (MainThreadRequest) ar.userObj;
1417 request.result = ar.exception == null;
1418 notifyRequester(request);
1419 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001420 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1423 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1424 break;
1425 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception != null) {
1429 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1430 } else {
1431 request.result = ((int[]) ar.result)[0];
1432 }
1433 notifyRequester(request);
1434 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1438 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001439 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1440 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001441 break;
1442 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 request.result = ar.exception == null;
1446 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001447 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001448 case CMD_GET_ALL_CELL_INFO:
1449 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001450 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001451 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 case EVENT_GET_ALL_CELL_INFO_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001456 // If a timeout occurs, the response will be null
1457 request.result = (ar.exception == null && ar.result != null)
1458 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 synchronized (request) {
1460 request.notifyAll();
1461 }
1462 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001463 case CMD_REQUEST_CELL_INFO_UPDATE:
1464 request = (MainThreadRequest) msg.obj;
1465 request.phone.requestCellInfoUpdate(request.workSource,
1466 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1467 break;
1468 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1472 try {
1473 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001474 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001475 cb.onError(
1476 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1477 ar.exception.getClass().getName(),
1478 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001479 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001481 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 } else {
1483 // use the result as returned
1484 cb.onCellInfo((List<CellInfo>) ar.result);
1485 }
1486 } catch (RemoteException re) {
1487 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1488 }
1489 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001490 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 request = (MainThreadRequest) msg.obj;
1492 WorkSource ws = (WorkSource) request.argument;
1493 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001494 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001496 }
1497 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
1500 if (ar.exception == null) {
1501 request.result = ar.result;
1502 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001503 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001505 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001506 }
1507
1508 synchronized (request) {
1509 request.notifyAll();
1510 }
1511 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001512 }
chen xu6dac5ab2018-10-26 17:39:23 -07001513 case CMD_MODEM_REBOOT:
1514 request = (MainThreadRequest) msg.obj;
1515 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001516 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001517 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001518 case EVENT_CMD_MODEM_REBOOT_DONE:
1519 handleNullReturnEvent(msg, "rebootModem");
1520 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001521 case CMD_REQUEST_ENABLE_MODEM:
1522 request = (MainThreadRequest) msg.obj;
1523 boolean enable = (boolean) request.argument;
1524 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001525 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001526 PhoneConfigurationManager.getInstance()
1527 .enablePhone(request.phone, enable, onCompleted);
1528 break;
1529 case EVENT_ENABLE_MODEM_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001533 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001534 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001535 if ((boolean) request.result) {
1536 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1537 updateModemStateMetrics();
1538 } else {
1539 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1540 + ar.exception);
1541 }
1542 notifyRequester(request);
1543 break;
1544 case CMD_GET_MODEM_STATUS:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1547 PhoneConfigurationManager.getInstance()
1548 .getPhoneStatusFromModem(request.phone, onCompleted);
1549 break;
1550 case EVENT_GET_MODEM_STATUS_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 int id = request.phone.getPhoneId();
1554 if (ar.exception == null && ar.result != null) {
1555 request.result = ar.result;
1556 //update the cache as modem status has changed
1557 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1558 (boolean) request.result);
1559 } else {
1560 // Return true if modem status cannot be retrieved. For most cases,
1561 // modem status is on. And for older version modems, GET_MODEM_STATUS
1562 // and disable modem are not supported. Modem is always on.
1563 // TODO: this should be fixed in R to support a third
1564 // status UNKNOWN b/131631629
1565 request.result = true;
1566 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1567 + ar.exception);
1568 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 notifyRequester(request);
1570 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001571 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1574 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1575 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1576 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1577 break;
1578 }
1579 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1583 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1584 args.second.accept(ar.exception == null);
1585 notifyRequester(request);
1586 break;
1587 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001588 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1591 Phone phone = getPhoneFromRequest(request);
1592 if (phone != null) {
1593 phone.getSystemSelectionChannels(onCompleted);
1594 } else {
1595 loge("getSystemSelectionChannels: No phone object");
1596 request.result = new ArrayList<RadioAccessSpecifier>();
1597 notifyRequester(request);
1598 }
1599 break;
1600 }
1601 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception == null && ar.result != null) {
1605 request.result = ar.result;
1606 } else {
1607 request.result = new IllegalArgumentException(
1608 "Failed to retrieve system selection channels");
1609 if (ar.result == null) {
1610 loge("getSystemSelectionChannels: Empty response");
1611 } else {
1612 loge("getSystemSelectionChannels: Unknown exception");
1613 }
1614 }
1615 notifyRequester(request);
1616 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001617 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception == null && ar.result != null) {
1621 request.result = ar.result;
1622 } else {
1623 request.result = -1;
1624 loge("Failed to set Forbidden Plmns");
1625 if (ar.result == null) {
1626 loge("setForbidenPlmns: Empty response");
1627 } else if (ar.exception != null) {
1628 loge("setForbiddenPlmns: Exception: " + ar.exception);
1629 request.result = -1;
1630 } else {
1631 loge("setForbiddenPlmns: Unknown exception");
1632 }
1633 }
1634 notifyRequester(request);
1635 break;
1636 case CMD_SET_FORBIDDEN_PLMNS:
1637 request = (MainThreadRequest) msg.obj;
1638 uiccCard = getUiccCardFromRequest(request);
1639 if (uiccCard == null) {
1640 loge("setForbiddenPlmns: UiccCard is null");
1641 request.result = -1;
1642 notifyRequester(request);
1643 break;
1644 }
1645 Pair<Integer, List<String>> setFplmnsArgs =
1646 (Pair<Integer, List<String>>) request.argument;
1647 appType = setFplmnsArgs.first;
1648 List<String> fplmns = setFplmnsArgs.second;
1649 uiccApp = uiccCard.getApplicationByType(appType);
1650 if (uiccApp == null) {
1651 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1652 request.result = -1;
1653 loge("Failed to get UICC App");
1654 notifyRequester(request);
1655 } else {
1656 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1657 ((SIMRecords) uiccApp.getIccRecords())
1658 .setForbiddenPlmns(onCompleted, fplmns);
1659 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001660 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001661 case CMD_ERASE_MODEM_CONFIG:
1662 request = (MainThreadRequest) msg.obj;
1663 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1664 defaultPhone.eraseModemConfig(onCompleted);
1665 break;
1666 case EVENT_ERASE_MODEM_CONFIG_DONE:
1667 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001668 break;
zoey chene02881a2019-12-30 16:11:23 +08001669
1670 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1673 Pair<String, String> changed = (Pair<String, String>) request.argument;
1674 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1675 changed.first, changed.second, onCompleted);
1676 break;
1677 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 if (ar.exception == null) {
1681 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1682 } else {
1683 request.result = msg.arg1;
1684 }
1685 notifyRequester(request);
1686 break;
1687
1688 case CMD_SET_ICC_LOCK_ENABLED:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1691 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1692 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1693 enabled.first, enabled.second, onCompleted);
1694 break;
1695 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1700 } else {
1701 request.result = msg.arg1;
1702 }
1703 notifyRequester(request);
1704 break;
1705
Peter Wangdafb9ac2020-01-15 14:13:38 -08001706 case MSG_NOTIFY_USER_ACTIVITY:
1707 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001708 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001709 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1710 getDefaultPhone().getContext().sendBroadcastAsUser(
1711 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1712 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001713
1714 case CMD_SET_DATA_THROTTLING: {
1715 request = (MainThreadRequest) msg.obj;
1716 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1717 DataThrottlingRequest dataThrottlingRequest =
1718 (DataThrottlingRequest) request.argument;
1719 Phone phone = getPhoneFromRequest(request);
1720 if (phone != null) {
1721 phone.setDataThrottling(onCompleted,
1722 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1723 dataThrottlingRequest.getCompletionDurationMillis());
1724 } else {
1725 loge("setDataThrottling: No phone object");
1726 request.result =
1727 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1728 notifyRequester(request);
1729 }
1730
1731 break;
1732 }
1733 case EVENT_SET_DATA_THROTTLING_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736
1737 if (ar.exception == null) {
1738 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1739 } else if (ar.exception instanceof CommandException) {
1740 loge("setDataThrottling: CommandException: " + ar.exception);
1741 CommandException.Error error =
1742 ((CommandException) (ar.exception)).getCommandError();
1743
1744 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1745 request.result = TelephonyManager
1746 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1747 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1748 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1749 } else {
1750 request.result =
1751 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1752 }
1753 } else {
1754 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1755 }
1756 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1757 notifyRequester(request);
1758 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001759
1760 case CMD_SET_SIM_POWER: {
1761 request = (MainThreadRequest) msg.obj;
1762 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1763 request = (MainThreadRequest) msg.obj;
1764 int stateToSet =
1765 ((Pair<Integer, IIntegerConsumer>)
1766 request.argument).first;
1767 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1768 break;
1769 }
1770 case EVENT_SET_SIM_POWER_DONE: {
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 IIntegerConsumer callback =
1774 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1775 if (ar.exception != null) {
1776 loge("setSimPower exception: " + ar.exception);
1777 int errorCode = TelephonyManager.CallForwardingInfoCallback
1778 .RESULT_ERROR_UNKNOWN;
1779 if (ar.exception instanceof CommandException) {
1780 CommandException.Error error =
1781 ((CommandException) (ar.exception)).getCommandError();
1782 if (error == CommandException.Error.SIM_ERR) {
1783 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1784 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1785 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1786 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1787 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1788 } else {
1789 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1790 }
1791 }
1792 try {
1793 callback.accept(errorCode);
1794 } catch (RemoteException e) {
1795 // Ignore if the remote process is no longer available to call back.
1796 Log.w(LOG_TAG, "setSimPower: callback not available.");
1797 }
1798 } else {
1799 try {
1800 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1801 } catch (RemoteException e) {
1802 // Ignore if the remote process is no longer available to call back.
1803 Log.w(LOG_TAG, "setSimPower: callback not available.");
1804 }
1805 }
1806 break;
1807 }
1808
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 default:
1810 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1811 break;
1812 }
1813 }
Jake Hambye994d462014-02-03 13:10:13 -08001814
Pengquan Menga1bb6272018-09-06 09:59:22 -07001815 private void notifyRequester(MainThreadRequest request) {
1816 synchronized (request) {
1817 request.notifyAll();
1818 }
1819 }
1820
Jake Hambye994d462014-02-03 13:10:13 -08001821 private void handleNullReturnEvent(Message msg, String command) {
1822 AsyncResult ar = (AsyncResult) msg.obj;
1823 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null) {
1825 request.result = true;
1826 } else {
1827 request.result = false;
1828 if (ar.exception instanceof CommandException) {
1829 loge(command + ": CommandException: " + ar.exception);
1830 } else {
1831 loge(command + ": Unknown exception");
1832 }
1833 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001834 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 }
1837
1838 /**
1839 * Posts the specified command to be executed on the main thread,
1840 * waits for the request to complete, and returns the result.
1841 * @see #sendRequestAsync
1842 */
1843 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001844 return sendRequest(
1845 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001846 }
1847
1848 /**
1849 * Posts the specified command to be executed on the main thread,
1850 * waits for the request to complete, and returns the result.
1851 * @see #sendRequestAsync
1852 */
1853 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1854 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001855 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001856 }
1857
1858 /**
1859 * Posts the specified command to be executed on the main thread,
1860 * waits for the request to complete, and returns the result.
1861 * @see #sendRequestAsync
1862 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001863 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001864 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001865 }
1866
1867 /**
1868 * Posts the specified command to be executed on the main thread,
1869 * waits for the request to complete, and returns the result.
1870 * @see #sendRequestAsync
1871 */
Nathan Harold92bed182018-10-12 18:16:49 -07001872 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1873 return sendRequest(command, argument, subId, null, workSource);
1874 }
1875
1876 /**
1877 * Posts the specified command to be executed on the main thread,
1878 * waits for the request to complete, and returns the result.
1879 * @see #sendRequestAsync
1880 */
1881 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1882 return sendRequest(
1883 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1884 }
1885
1886 /**
1887 * Posts the specified command to be executed on the main thread,
1888 * waits for the request to complete, and returns the result.
1889 * @see #sendRequestAsync
1890 */
1891 private Object sendRequest(
1892 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1894 throw new RuntimeException("This method will deadlock if called from the main thread.");
1895 }
1896
Nathan Harold92bed182018-10-12 18:16:49 -07001897 MainThreadRequest request = null;
1898 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1899 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1900 } else if (phone != null) {
1901 request = new MainThreadRequest(argument, phone, workSource);
1902 } else {
1903 request = new MainThreadRequest(argument, subId, workSource);
1904 }
1905
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 Message msg = mMainThreadHandler.obtainMessage(command, request);
1907 msg.sendToTarget();
1908
1909 // Wait for the request to complete
1910 synchronized (request) {
1911 while (request.result == null) {
1912 try {
1913 request.wait();
1914 } catch (InterruptedException e) {
1915 // Do nothing, go back and wait until the request is complete
1916 }
1917 }
1918 }
1919 return request.result;
1920 }
1921
1922 /**
1923 * Asynchronous ("fire and forget") version of sendRequest():
1924 * Posts the specified command to be executed on the main thread, and
1925 * returns immediately.
1926 * @see #sendRequest
1927 */
1928 private void sendRequestAsync(int command) {
1929 mMainThreadHandler.sendEmptyMessage(command);
1930 }
1931
1932 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001933 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001934 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001935 */
1936 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001937 sendRequestAsync(command, argument, null, null);
1938 }
1939
1940 /**
1941 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1942 * @see {@link #sendRequest(int,Object)}
1943 */
1944 private void sendRequestAsync(
1945 int command, Object argument, Phone phone, WorkSource workSource) {
1946 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001947 Message msg = mMainThreadHandler.obtainMessage(command, request);
1948 msg.sendToTarget();
1949 }
1950
1951 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 * Initialize the singleton PhoneInterfaceManager instance.
1953 * This is only done once, at startup, from PhoneApp.onCreate().
1954 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001955 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 synchronized (PhoneInterfaceManager.class) {
1957 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001958 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 } else {
1960 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1961 }
1962 return sInstance;
1963 }
1964 }
1965
1966 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001967 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001970 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001971 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1973 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001974 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001975 mTelephonySharedPreferences =
1976 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001977 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001978 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001979 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 publish();
1982 }
1983
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001984 private Phone getDefaultPhone() {
1985 Phone thePhone = getPhone(getDefaultSubscription());
1986 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1987 }
1988
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 private void publish() {
1990 if (DBG) log("publish: " + this);
1991
Peter Wangc035ce42020-01-08 21:00:22 -08001992 TelephonyFrameworkInitializer
1993 .getTelephonyServiceManager()
1994 .getTelephonyServiceRegisterer()
1995 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
Stuart Scott584921c2015-01-15 17:10:34 -08001998 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001999 if (request.phone != null) {
2000 return request.phone;
2001 } else {
2002 return getPhoneFromSubId(request.subId);
2003 }
2004 }
2005
2006 private Phone getPhoneFromSubId(int subId) {
2007 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2008 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002009 }
2010
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002011 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2012 Phone phone = getPhoneFromRequest(request);
2013 return phone == null ? null :
2014 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2015 }
2016
Wink Saville36469e72014-06-11 15:17:00 -07002017 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002019 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021
Naina Nallurid63128d2019-09-17 14:10:30 -07002022 private void sendEraseModemConfig(Phone phone) {
2023 if (phone != null) {
2024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2025 mApp, phone.getSubId(), "eraseModemConfig");
2026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2029 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
2033 }
2034 }
2035
Peter Wang44b186e2020-01-13 23:33:09 -08002036 private boolean isImsAvailableOnDevice() {
2037 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2038 if (pm == null) {
2039 // For some reason package manger is not available.. This will fail internally anyway,
2040 // so do not throw error and allow.
2041 return true;
2042 }
2043 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2044 }
2045
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002047 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002048 }
2049
Wink Savilleb564aae2014-10-23 10:18:09 -07002050 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 if (DBG) log("dial: " + number);
2052 // No permission check needed here: This is just a wrapper around the
2053 // ACTION_DIAL intent, which is available to any app since it puts up
2054 // the UI before it does anything.
2055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 String url = createTelUrl(number);
2059 if (url == null) {
2060 return;
2061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 // PENDING: should we just silently fail if phone is offhook or ringing?
2064 PhoneConstants.State state = mCM.getState(subId);
2065 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2066 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2067 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2068 mApp.startActivity(intent);
2069 }
2070 } finally {
2071 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
2073 }
2074
2075 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002076 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002077 }
2078
Wink Savilleb564aae2014-10-23 10:18:09 -07002079 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 if (DBG) log("call: " + number);
2081
2082 // This is just a wrapper around the ACTION_CALL intent, but we still
2083 // need to do a permission check since we're calling startActivity()
2084 // from the context of the phone app.
2085 enforceCallPermission();
2086
Jordan Liu1617b712019-07-10 15:06:26 -07002087 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 != AppOpsManager.MODE_ALLOWED) {
2089 return;
2090 }
2091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002092 final long identity = Binder.clearCallingIdentity();
2093 try {
2094 String url = createTelUrl(number);
2095 if (url == null) {
2096 return;
2097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 boolean isValid = false;
2100 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2101 if (slist != null) {
2102 for (SubscriptionInfo subInfoRecord : slist) {
2103 if (subInfoRecord.getSubscriptionId() == subId) {
2104 isValid = true;
2105 break;
2106 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002107 }
Wink Saville08874612014-08-31 19:19:58 -07002108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002109 if (!isValid) {
2110 return;
2111 }
Wink Saville08874612014-08-31 19:19:58 -07002112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2114 intent.putExtra(SUBSCRIPTION_KEY, subId);
2115 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2116 mApp.startActivity(intent);
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002123 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002124 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2125 }
2126
Wink Savilleb564aae2014-10-23 10:18:09 -07002127 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002128 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002129 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2130 }
2131
Wink Savilleb564aae2014-10-23 10:18:09 -07002132 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2138 checkSimPin.start();
2139 return checkSimPin.unlockSim(null, pin);
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
Wink Savilleb564aae2014-10-23 10:18:09 -07002145 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2151 checkSimPuk.start();
2152 return checkSimPuk.unlockSim(puk, pin);
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157
2158 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002159 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 * a synchronous one.
2161 */
2162 private static class UnlockSim extends Thread {
2163
2164 private final IccCard mSimCard;
2165
2166 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002167 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2168 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169
2170 // For replies from SimCard interface
2171 private Handler mHandler;
2172
2173 // For async handler to identify request type
2174 private static final int SUPPLY_PIN_COMPLETE = 100;
2175
2176 public UnlockSim(IccCard simCard) {
2177 mSimCard = simCard;
2178 }
2179
2180 @Override
2181 public void run() {
2182 Looper.prepare();
2183 synchronized (UnlockSim.this) {
2184 mHandler = new Handler() {
2185 @Override
2186 public void handleMessage(Message msg) {
2187 AsyncResult ar = (AsyncResult) msg.obj;
2188 switch (msg.what) {
2189 case SUPPLY_PIN_COMPLETE:
2190 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2191 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002192 mRetryCount = msg.arg1;
2193 if (ar.exception != null) {
2194 if (ar.exception instanceof CommandException &&
2195 ((CommandException)(ar.exception)).getCommandError()
2196 == CommandException.Error.PASSWORD_INCORRECT) {
2197 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002198 } //When UiccCardApp dispose,handle message and return exception
2199 else if (ar.exception instanceof CommandException &&
2200 ((CommandException) (ar.exception)).getCommandError()
2201 == CommandException.Error.ABORTED) {
2202 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002203 } else {
2204 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2205 }
2206 } else {
2207 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 mDone = true;
2210 UnlockSim.this.notifyAll();
2211 }
2212 break;
2213 }
2214 }
2215 };
2216 UnlockSim.this.notifyAll();
2217 }
2218 Looper.loop();
2219 }
2220
2221 /*
2222 * Use PIN or PUK to unlock SIM card
2223 *
2224 * If PUK is null, unlock SIM card with PIN
2225 *
2226 * If PUK is not null, unlock SIM card with PUK and set PIN code
2227 */
Wink Saville9de0f752013-10-22 19:04:03 -07002228 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229
2230 while (mHandler == null) {
2231 try {
2232 wait();
2233 } catch (InterruptedException e) {
2234 Thread.currentThread().interrupt();
2235 }
2236 }
2237 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2238
2239 if (puk == null) {
2240 mSimCard.supplyPin(pin, callback);
2241 } else {
2242 mSimCard.supplyPuk(puk, pin, callback);
2243 }
2244
2245 while (!mDone) {
2246 try {
2247 Log.d(LOG_TAG, "wait for done");
2248 wait();
2249 } catch (InterruptedException e) {
2250 // Restore the interrupted status
2251 Thread.currentThread().interrupt();
2252 }
2253 }
2254 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002255 int[] resultArray = new int[2];
2256 resultArray[0] = mResult;
2257 resultArray[1] = mRetryCount;
2258 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260 }
2261
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002262 /**
2263 * This method has been removed due to privacy and stability concerns.
2264 */
2265 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002267 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2268 return;
Wink Saville36469e72014-06-11 15:17:00 -07002269 }
2270
Nathan Harold1f889d82020-06-04 17:05:26 -07002271 @Override
2272 public void updateServiceLocationWithPackageName(String callingPackage) {
2273 mApp.getSystemService(AppOpsManager.class)
2274 .checkPackage(Binder.getCallingUid(), callingPackage);
2275
Nathan Haroldf096d982020-11-18 17:18:06 -08002276 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002277 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2278 // Callers targeting S have no business invoking this method.
2279 return;
2280 }
2281
2282 LocationAccessPolicy.LocationPermissionResult locationResult =
2283 LocationAccessPolicy.checkLocationPermission(mApp,
2284 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2285 .setCallingPackage(callingPackage)
2286 .setCallingFeatureId(null)
2287 .setCallingPid(Binder.getCallingPid())
2288 .setCallingUid(Binder.getCallingUid())
2289 .setMethod("updateServiceLocation")
2290 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2291 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2292 .build());
2293 // Apps that lack location permission have no business calling this method;
2294 // however, because no permission was declared in the public API, denials must
2295 // all be "soft".
2296 switch (locationResult) {
2297 case DENIED_HARD: /* fall through */
2298 case DENIED_SOFT:
2299 return;
2300 }
2301
2302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 final long identity = Binder.clearCallingIdentity();
2304 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002305 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002307 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 }
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002314 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 @Override
2316 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002317 return isRadioOnWithFeature(callingPackage, null);
2318 }
2319
2320
2321 @Override
2322 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2323 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2324 callingFeatureId);
2325 }
2326
2327 @Deprecated
2328 @Override
2329 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2330 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002334 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2335 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002337 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 return false;
2339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 return isRadioOnForSubscriber(subId);
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
2346 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 }
2348
2349 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 if (phone != null) {
2354 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2355 } else {
2356 return false;
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 }
2362
2363 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002364 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 }
Wink Saville36469e72014-06-11 15:17:00 -07002366
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369
2370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = getPhone(subId);
2373 if (phone != null) {
2374 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 }
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
2381 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002382 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Wink Savilleb564aae2014-10-23 10:18:09 -07002385 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002386 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone == null) {
2392 return false;
2393 }
2394 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2395 toggleRadioOnOffForSubscriber(subId);
2396 }
2397 return true;
2398 } finally {
2399 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
Wink Saville36469e72014-06-11 15:17:00 -07002402
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002403 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002404 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002405 /*
2406 * If any of the Radios are available, it will need to be
2407 * shutdown. So return true if any Radio is available.
2408 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2412 Phone phone = PhoneFactory.getPhone(i);
2413 if (phone != null && phone.isRadioAvailable()) return true;
2414 }
2415 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2416 return false;
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002419 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002420 }
2421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002423 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 enforceModifyPermission();
2425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2429 logv("Shutting down Phone " + i);
2430 shutdownRadioUsingPhoneId(i);
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002434 }
2435 }
2436
2437 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002438 Phone phone = PhoneFactory.getPhone(phoneId);
2439 if (phone != null && phone.isRadioAvailable()) {
2440 phone.shutdownRadio();
2441 }
2442 }
2443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2450 if (defaultPhone != null) {
2451 defaultPhone.setRadioPower(turnOn);
2452 return true;
2453 } else {
2454 loge("There's no default phone.");
2455 return false;
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002459 }
Wink Saville36469e72014-06-11 15:17:00 -07002460 }
2461
Wink Savilleb564aae2014-10-23 10:18:09 -07002462 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 final Phone phone = getPhone(subId);
2468 if (phone != null) {
2469 phone.setRadioPower(turnOn);
2470 return true;
2471 } else {
2472 return false;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Wink Saville36469e72014-06-11 15:17:00 -07002479 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 public boolean enableDataConnectivity() {
2482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483
2484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 int subId = mSubscriptionController.getDefaultDataSubId();
2487 final Phone phone = getPhone(subId);
2488 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002489 phone.getDataEnabledSettings().setDataEnabled(
2490 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 return true;
2492 } else {
2493 return false;
2494 }
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 }
2499
Wink Saville36469e72014-06-11 15:17:00 -07002500 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 public boolean disableDataConnectivity() {
2503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 int subId = mSubscriptionController.getDefaultDataSubId();
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002510 phone.getDataEnabledSettings().setDataEnabled(
2511 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 return true;
2513 } else {
2514 return false;
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002522 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 final Phone phone = getPhone(subId);
2526 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002527 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528 } else {
2529 return false;
2530 }
2531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 }
2535
2536 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002537 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
2539
pkanwarae03a6b2016-11-06 20:37:09 -08002540 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 enforceCallPermission();
2542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2546 return;
2547 }
2548 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2549 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
pkanwar32d516d2016-10-14 19:37:38 -07002553 };
2554
Wink Savilleb564aae2014-10-23 10:18:09 -07002555 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2561 return false;
2562 }
2563 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002570 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002571 }
2572
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002573 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 Phone phone = PhoneFactory.getPhone(slotIndex);
2577 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2578 PhoneConstantConversions.convertCallState(phone.getState());
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
Sanket Padawe356d7632015-06-22 14:03:32 -07002584 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002585 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002586 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2587 }
2588
2589 @Override
2590 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591 final long identity = Binder.clearCallingIdentity();
2592 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002593 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594 if (phone != null) {
2595 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2596 } else {
2597 return PhoneConstantConversions.convertDataState(
2598 PhoneConstants.DataState.DISCONNECTED);
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002606 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002607 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2608 }
2609
2610 @Override
2611 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002614 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 if (phone != null) {
2616 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2617 } else {
2618 return TelephonyManager.DATA_ACTIVITY_NONE;
2619 }
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 }
2624
2625 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002626 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002628 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002629
2630 LocationAccessPolicy.LocationPermissionResult locationResult =
2631 LocationAccessPolicy.checkLocationPermission(mApp,
2632 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2633 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002634 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002635 .setCallingPid(Binder.getCallingPid())
2636 .setCallingUid(Binder.getCallingUid())
2637 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002638 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2640 .build());
2641 switch (locationResult) {
2642 case DENIED_HARD:
2643 throw new SecurityException("Not allowed to access cell location");
2644 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002645 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2646 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002649 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002653 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002654 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Svetoslav64fad262015-04-14 14:35:21 -07002658 }
2659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002661 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002662 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2663 // registered cell info, so return a NULL country instead.
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002666 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2667 // Get default phone in this case.
2668 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2669 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002670 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002672 if (phone == null) return "";
2673 ServiceStateTracker sst = phone.getServiceStateTracker();
2674 if (sst == null) return "";
2675 LocaleTracker lt = sst.getLocaleTracker();
2676 if (lt == null) return "";
2677 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2678 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2679 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002683 }
2684
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002685 /**
2686 * This method was removed due to potential issues caused by performing partial
2687 * updates of service state, and lack of a credible use case.
2688 *
2689 * This has the ability to break the telephony implementation by disabling notification of
2690 * changes in device connectivity. DO NOT USE THIS!
2691 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002692 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 public void enableLocationUpdates() {
2694 mApp.enforceCallingOrSelfPermission(
2695 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
2697
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002698 /**
2699 * This method was removed due to potential issues caused by performing partial
2700 * updates of service state, and lack of a credible use case.
2701 *
2702 * This has the ability to break the telephony implementation by disabling notification of
2703 * changes in device connectivity. DO NOT USE THIS!
2704 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 @Override
2706 public void disableLocationUpdates() {
2707 mApp.enforceCallingOrSelfPermission(
2708 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 }
2710
2711 @Override
2712 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002713 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2714 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002715 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002716 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2717 throw new SecurityException(
2718 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2719 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002720
Jordan Liu1617b712019-07-10 15:06:26 -07002721 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2723 return null;
2724 }
Svetoslav64fad262015-04-14 14:35:21 -07002725
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002726 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002728 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002729 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730
Nathan Haroldf180aac2018-06-01 18:43:55 -07002731 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2732 for (CellInfo ci : info) {
2733 if (ci instanceof CellInfoGsm) {
2734 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2735 } else if (ci instanceof CellInfoWcdma) {
2736 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002739 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 }
2741
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002742 private List<CellInfo> getCachedCellInfo() {
2743 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2744 for (Phone phone : PhoneFactory.getPhones()) {
2745 List<CellInfo> info = phone.getAllCellInfo();
2746 if (info != null) cellInfos.addAll(info);
2747 }
2748 return cellInfos;
2749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750
2751 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002752 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002753 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002754 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002755
2756 LocationAccessPolicy.LocationPermissionResult locationResult =
2757 LocationAccessPolicy.checkLocationPermission(mApp,
2758 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2759 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002760 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002761 .setCallingPid(Binder.getCallingPid())
2762 .setCallingUid(Binder.getCallingUid())
2763 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002764 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002765 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2766 .build());
2767 switch (locationResult) {
2768 case DENIED_HARD:
2769 throw new SecurityException("Not allowed to access cell info");
2770 case DENIED_SOFT:
2771 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Nathan Haroldf096d982020-11-18 17:18:06 -08002774 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002775 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2776 return getCachedCellInfo();
2777 }
2778
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002779 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2784 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002785 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002786 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 if (info != null) cellInfos.addAll(info);
2788 }
2789 return cellInfos;
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793 }
2794
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002795 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002796 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2797 String callingFeatureId) {
2798 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2799 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002800 }
2801
2802 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002803 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2804 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002805 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002806 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002807 }
2808
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002809 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2810 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002811 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002812 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002813
2814 LocationAccessPolicy.LocationPermissionResult locationResult =
2815 LocationAccessPolicy.checkLocationPermission(mApp,
2816 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2817 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002818 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002819 .setCallingPid(Binder.getCallingPid())
2820 .setCallingUid(Binder.getCallingUid())
2821 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002822 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2823 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002824 .build());
2825 switch (locationResult) {
2826 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002827 if (TelephonyPermissions
2828 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002829 // Safetynet logging for b/154934934
2830 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2831 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002832 throw new SecurityException("Not allowed to access cell info");
2833 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002834 if (TelephonyPermissions
2835 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002836 // Safetynet logging for b/154934934
2837 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2838 }
Nathan Harold5320c422019-05-09 10:26:08 -07002839 try {
2840 cb.onCellInfo(new ArrayList<CellInfo>());
2841 } catch (RemoteException re) {
2842 // Drop without consequences
2843 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002844 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002845 }
2846
Nathan Harolda939a962019-05-09 10:13:47 -07002847
2848 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002849 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2850
2851 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2852 }
2853
2854 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002856 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002857 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Shishir Agrawala9f32182016-04-12 12:00:16 -07002867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002868 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002869 Phone phone = PhoneFactory.getPhone(slotIndex);
2870 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002871 return null;
2872 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002873 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002874 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002876 return null;
2877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 return phone.getImei();
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002885 }
2886
2887 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002888 public String getTypeAllocationCodeForSlot(int slotIndex) {
2889 Phone phone = PhoneFactory.getPhone(slotIndex);
2890 String tac = null;
2891 if (phone != null) {
2892 String imei = phone.getImei();
2893 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2894 }
2895 return tac;
2896 }
2897
2898 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002899 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002900 Phone phone = PhoneFactory.getPhone(slotIndex);
2901 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002902 return null;
2903 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002904
Jeff Davidson913390f2018-02-23 17:11:49 -08002905 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002906 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002907 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002908 return null;
2909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 return phone.getMeid();
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
Jack Yu2af8d712017-03-15 17:14:14 -07002917 }
2918
2919 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002920 public String getManufacturerCodeForSlot(int slotIndex) {
2921 Phone phone = PhoneFactory.getPhone(slotIndex);
2922 String manufacturerCode = null;
2923 if (phone != null) {
2924 String meid = phone.getMeid();
2925 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2926 }
2927 return manufacturerCode;
2928 }
2929
2930 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002931 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2932 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002933 Phone phone = PhoneFactory.getPhone(slotIndex);
2934 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002935 return null;
2936 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002937 int subId = phone.getSubId();
2938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002939 mApp, subId, callingPackage, callingFeatureId,
2940 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002941 return null;
2942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 return phone.getDeviceSvn();
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002950 }
2951
fionaxu43304da2017-11-27 22:51:16 -08002952 @Override
2953 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = getPhone(subId);
2957 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
fionaxu43304da2017-11-27 22:51:16 -08002961 }
2962
2963 @Override
2964 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 final Phone phone = getPhone(subId);
2968 return phone == null ? null : phone.getCarrierName();
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
fionaxu43304da2017-11-27 22:51:16 -08002972 }
2973
calvinpanffe225e2018-11-01 19:43:06 +08002974 @Override
chen xu0026ca62019-03-06 15:28:50 -08002975 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 final Phone phone = getPhone(subId);
2979 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002980 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 }
2985
2986 @Override
chen xu0026ca62019-03-06 15:28:50 -08002987 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002991 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
chen xu651eec72018-11-11 19:03:44 -08002997 @Override
chen xu864e11c2018-12-06 22:10:03 -08002998 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2999 if (!isSubscriptionMccMnc) {
3000 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3001 }
chen xu651eec72018-11-11 19:03:44 -08003002 final Phone phone = PhoneFactory.getPhone(slotIndex);
3003 if (phone == null) {
3004 return TelephonyManager.UNKNOWN_CARRIER_ID;
3005 }
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 //
3015 // Internal helper methods.
3016 //
3017
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003018 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3020 *
3021 * @throws SecurityException if the caller does not have the required permission
3022 */
3023 private void enforceModifyPermission() {
3024 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3025 }
3026
Shuo Qiancd19c462020-01-16 20:51:11 -08003027 /**
3028 * Make sure the caller is system.
3029 *
3030 * @throws SecurityException if the caller is not system.
3031 */
3032 private void enforceSystemCaller() {
3033 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3034 throw new SecurityException("Caller must be system");
3035 }
3036 }
3037
Shuo Qian3b6ee772019-11-13 17:43:31 -08003038 private void enforceActiveEmergencySessionPermission() {
3039 mApp.enforceCallingOrSelfPermission(
3040 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3041 }
3042
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 /**
3044 * Make sure the caller has the CALL_PHONE permission.
3045 *
3046 * @throws SecurityException if the caller does not have the required permission
3047 */
3048 private void enforceCallPermission() {
3049 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3050 }
3051
paulhu5a773602019-08-23 19:17:33 +08003052 private void enforceSettingsPermission() {
3053 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003054 }
3055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 private String createTelUrl(String number) {
3057 if (TextUtils.isEmpty(number)) {
3058 return null;
3059 }
3060
Jake Hambye994d462014-02-03 13:10:13 -08003061 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
3063
Ihab Awadf9e92732013-12-05 18:02:52 -08003064 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3066 }
3067
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003068 private static void logv(String msg) {
3069 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3070 }
3071
Ihab Awadf9e92732013-12-05 18:02:52 -08003072 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3074 }
3075
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003076 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003078 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003079 }
3080
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003082 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 final Phone phone = PhoneFactory.getPhone(slotIndex);
3086 if (phone == null) {
3087 return PhoneConstants.PHONE_TYPE_NONE;
3088 } else {
3089 return phone.getPhoneType();
3090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
3095
3096 /**
3097 * Returns the CDMA ERI icon index to display
3098 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003100 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3101 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3102 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003103 }
3104
Sanket Padawe356d7632015-06-22 14:03:32 -07003105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003106 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3107 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003109 mApp, subId, callingPackage, callingFeatureId,
3110 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003111 return -1;
3112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 final Phone phone = getPhone(subId);
3117 if (phone != null) {
3118 return phone.getCdmaEriIconIndex();
3119 } else {
3120 return -1;
3121 }
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 }
3126
3127 /**
3128 * Returns the CDMA ERI icon mode,
3129 * 0 - ON
3130 * 1 - FLASHING
3131 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003133 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3134 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3135 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003136 }
3137
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3140 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 mApp, subId, callingPackage, callingFeatureId,
3143 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003144 return -1;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 final Phone phone = getPhone(subId);
3150 if (phone != null) {
3151 return phone.getCdmaEriIconMode();
3152 } else {
3153 return -1;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
3160 /**
3161 * Returns the CDMA ERI text,
3162 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003164 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3165 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3166 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003167 }
3168
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003170 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3171 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003173 mApp, subId, callingPackage, callingFeatureId,
3174 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003175 return null;
3176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 final Phone phone = getPhone(subId);
3181 if (phone != null) {
3182 return phone.getCdmaEriText();
3183 } else {
3184 return null;
3185 }
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
3191 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003192 * Returns the CDMA MDN.
3193 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003195 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3197 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003202 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 return phone.getLine1Number();
3204 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 return null;
3207 }
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003210 }
3211 }
3212
3213 /**
3214 * Returns the CDMA MIN.
3215 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003217 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3219 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3225 return phone.getCdmaMin();
3226 } else {
3227 return null;
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003231 }
3232 }
3233
Hall Liud892bec2018-11-30 14:51:45 -08003234 @Override
3235 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3236 INumberVerificationCallback callback, String callingPackage) {
3237 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3238 != PERMISSION_GRANTED) {
3239 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3240 }
3241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3242
3243 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3244 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3245 throw new SecurityException("Calling package must be configured in the device config");
3246 }
3247
3248 if (range == null) {
3249 throw new NullPointerException("Range must be non-null");
3250 }
3251
3252 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003253 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003254
3255 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3256 }
3257
Junda Liuca05d5d2014-08-14 22:36:34 -07003258 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 * Returns true if CDMA provisioning needs to run.
3260 */
3261 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
3270 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003271 * Sets the voice mail number of a given subId.
3272 */
3273 @Override
3274 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003275 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3276 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3281 new Pair<String, String>(alphaTag, number), new Integer(subId));
3282 return success;
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003286 }
3287
Ta-wei Yen87c49842016-05-13 21:19:52 -07003288 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003289 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003291 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3292 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003293 if (!TextUtils.equals(callingPackage, systemDialer)) {
3294 throw new SecurityException("caller must be system dialer");
3295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3300 if (phoneAccountHandle == null) {
3301 return null;
3302 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003303 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003306 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003307 }
3308
3309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003310 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3311 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003312 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 mApp, subId, callingPackage, callingFeatureId,
3315 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003316 return null;
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003319 final long identity = Binder.clearCallingIdentity();
3320 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003325 }
3326
3327 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003328 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3329 VisualVoicemailSmsFilterSettings settings) {
3330 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003339 }
3340
3341 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003342 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3343 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003352 }
3353
3354 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003355 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3356 String callingPackage, int subId) {
3357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003366 }
3367
3368 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003369 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003375 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003379 }
3380
3381 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003382 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3383 String callingAttributionTag, int subId, String number, int port, String text,
3384 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003385 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003386 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003387 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003388 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003389 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3390 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003391 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003392
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003393 /**
fionaxu0152e512016-11-14 13:36:14 -08003394 * Sets the voice activation state of a given subId.
3395 */
3396 @Override
3397 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3399 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 final Phone phone = getPhone(subId);
3404 if (phone != null) {
3405 phone.setVoiceActivationState(activationState);
3406 } else {
3407 loge("setVoiceActivationState fails with invalid subId: " + subId);
3408 }
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003411 }
3412 }
3413
3414 /**
3415 * Sets the data activation state of a given subId.
3416 */
3417 @Override
3418 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3420 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
3425 if (phone != null) {
3426 phone.setDataActivationState(activationState);
3427 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003428 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003432 }
3433 }
3434
3435 /**
3436 * Returns the voice activation state of a given subId.
3437 */
3438 @Override
3439 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003441
fionaxu0152e512016-11-14 13:36:14 -08003442 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 if (phone != null) {
3446 return phone.getVoiceActivationState();
3447 } else {
3448 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3449 }
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003452 }
3453 }
3454
3455 /**
3456 * Returns the data activation state of a given subId.
3457 */
3458 @Override
3459 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461
fionaxu0152e512016-11-14 13:36:14 -08003462 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 if (phone != null) {
3466 return phone.getDataActivationState();
3467 } else {
3468 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3469 }
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003472 }
3473 }
3474
3475 /**
Wink Saville36469e72014-06-11 15:17:00 -07003476 * Returns the unread count of voicemails for a subId
3477 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003479 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3480 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003482 mApp, subId, callingPackage, callingFeatureId,
3483 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003484 return 0;
3485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 final Phone phone = getPhone(subId);
3489 if (phone != null) {
3490 return phone.getVoiceMessageCount();
3491 } else {
3492 return 0;
3493 }
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
3499 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003500 * returns true, if the device is in a state where both voice and data
3501 * are supported simultaneously. This can change based on location or network condition.
3502 */
3503 @Override
3504 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 final Phone phone = getPhone(subId);
3508 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003512 }
3513
3514 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003515 * Send the dialer code if called from the current default dialer or the caller has
3516 * carrier privilege.
3517 * @param inputCode The dialer code to send
3518 */
3519 @Override
3520 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003523 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3524 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003525 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003526 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003532 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
fionaxu235cc5e2017-03-06 22:25:57 -08003536 }
3537
Pengquan Menga1bb6272018-09-06 09:59:22 -07003538 @Override
3539 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003540 TelephonyPermissions
3541 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3542 mApp, subId, "getNetworkSelectionMode");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 if (!isActiveSubscription(subId)) {
3546 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3547 }
3548 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003552 }
3553
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003555 public boolean isInEmergencySmsMode() {
3556 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 for (Phone phone : PhoneFactory.getPhones()) {
3560 if (phone.isInEmergencySmsMode()) {
3561 return true;
3562 }
3563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
3567 return false;
3568 }
3569
shilu366312e2019-12-17 09:28:10 -08003570 /**
3571 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3572 * @param subId The subscription to use to check the configuration.
3573 * @param c The callback that will be used to send the result.
3574 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003575 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003576 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3577 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003578 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3579 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003580
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003581 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3583 "IMS not available on device.");
3584 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 final long token = Binder.clearCallingIdentity();
3586 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003590 } catch (ImsException e) {
3591 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 } finally {
3593 Binder.restoreCallingIdentity(token);
3594 }
3595 }
3596
shilu366312e2019-12-17 09:28:10 -08003597 /**
3598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3599 * @param subId The subscription to use to check the configuration.
3600 * @param c The callback that will be used to send the result.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003603 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003604 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3605 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003606 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3607 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3608 }
Meng Wangafbc5852019-09-19 17:37:13 -07003609 final long token = Binder.clearCallingIdentity();
3610 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003611 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003612 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3613 .removeRegistrationCallbackForSubscription(c, subId);
3614 } catch (ImsException e) {
3615 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3616 + "is inactive, ignoring unregister.");
3617 // If the subscription is no longer active, just return, since the callback
3618 // will already have been removed internally.
3619 } finally {
3620 Binder.restoreCallingIdentity(token);
3621 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 }
3623
Brad Ebingera34a6c22019-10-22 17:36:18 -07003624 /**
3625 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3626 */
3627 @Override
3628 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3629 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3630 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3632 "IMS not available on device.");
3633 }
3634 final long token = Binder.clearCallingIdentity();
3635 try {
3636 Phone phone = getPhone(subId);
3637 if (phone == null) {
3638 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3639 + subId + "'");
3640 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3641 }
3642 phone.getImsRegistrationState(regState -> {
3643 try {
3644 consumer.accept((regState == null)
3645 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3646 } catch (RemoteException e) {
3647 // Ignore if the remote process is no longer available to call back.
3648 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3649 }
3650 });
3651 } finally {
3652 Binder.restoreCallingIdentity(token);
3653 }
3654 }
3655
3656 /**
3657 * Get the transport type for the IMS service registration state.
3658 */
3659 @Override
3660 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003661 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3662 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003663 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3665 "IMS not available on device.");
3666 }
3667 final long token = Binder.clearCallingIdentity();
3668 try {
3669 Phone phone = getPhone(subId);
3670 if (phone == null) {
3671 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3672 + subId + "'");
3673 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3674 }
3675 phone.getImsRegistrationTech(regTech -> {
3676 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3677 int regTechConverted = (regTech == null)
3678 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3679 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3680 regTechConverted);
3681 try {
3682 consumer.accept(regTechConverted);
3683 } catch (RemoteException e) {
3684 // Ignore if the remote process is no longer available to call back.
3685 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3686 }
3687 });
3688 } finally {
3689 Binder.restoreCallingIdentity(token);
3690 }
3691 }
3692
shilu366312e2019-12-17 09:28:10 -08003693 /**
3694 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3695 * @param subId The subscription to use to check the configuration.
3696 * @param c The callback that will be used to send the result.
3697 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003699 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3700 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003701 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3702 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003703 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3704 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3705 "IMS not available on device.");
3706 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3708 final long token = Binder.clearCallingIdentity();
3709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003710 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003712 } catch (ImsException e) {
3713 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 } finally {
3715 Binder.restoreCallingIdentity(token);
3716 }
3717 }
3718
shilu366312e2019-12-17 09:28:10 -08003719 /**
3720 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3721 * @param subId The subscription to use to check the configuration.
3722 * @param c The callback that will be used to send the result.
3723 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003725 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003726 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3727 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003728 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3729 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3730 }
Meng Wangafbc5852019-09-19 17:37:13 -07003731
3732 final long token = Binder.clearCallingIdentity();
3733 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003734 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003735 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003736 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003737 } catch (ImsException e) {
3738 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3739 + "is inactive, ignoring unregister.");
3740 // If the subscription is no longer active, just return, since the callback
3741 // will already have been removed internally.
3742 } finally {
3743 Binder.restoreCallingIdentity(token);
3744 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 }
3746
3747 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003748 public boolean isCapable(int subId, int capability, int regTech) {
3749 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3751 final long token = Binder.clearCallingIdentity();
3752 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3757 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003759 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3760 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 } finally {
3762 Binder.restoreCallingIdentity(token);
3763 }
3764 }
3765
3766 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003767 public boolean isAvailable(int subId, int capability, int regTech) {
3768 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 final long token = Binder.clearCallingIdentity();
3770 try {
3771 Phone phone = getPhone(subId);
3772 if (phone == null) return false;
3773 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003774 } catch (com.android.ims.ImsException e) {
3775 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3776 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(token);
3779 }
3780 }
3781
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003782 /**
3783 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3784 * subscription.
3785 * @param subId The subscription to use to check the configuration.
3786 * @param callback The callback that will be used to send the result.
3787 * @param capability The MmTelFeature capability that will be used to send the result.
3788 * @param transportType The transport type of the MmTelFeature capability.
3789 */
3790 @Override
3791 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3792 int transportType) {
3793 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3794 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3795 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3796 "IMS not available on device.");
3797 }
3798 final long token = Binder.clearCallingIdentity();
3799 try {
3800 int slotId = getSlotIndex(subId);
3801 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3802 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3803 + subId + "'");
3804 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3805 }
3806 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3807 transportType, aBoolean -> {
3808 try {
3809 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3810 } catch (RemoteException e) {
3811 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3812 + "running. Ignore");
3813 }
3814 });
3815 } finally {
3816 Binder.restoreCallingIdentity(token);
3817 }
3818 }
3819
shilu366312e2019-12-17 09:28:10 -08003820 /**
3821 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3822 * @param subId The subscription to use to check the configuration.
3823 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 @Override
3825 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003826 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3827 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003828
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3830 final long token = Binder.clearCallingIdentity();
3831 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003832 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003834 } catch (ImsException e) {
3835 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 } finally {
3837 Binder.restoreCallingIdentity(token);
3838 }
3839 }
3840
3841 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003842 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003844 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003848 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003850 } catch (ImsException e) {
3851 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 } finally {
3853 Binder.restoreCallingIdentity(identity);
3854 }
3855 }
3856
shilu366312e2019-12-17 09:28:10 -08003857 /**
3858 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3859 * @param subId The subscription to use to check the configuration.
3860 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003862 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003863 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3864 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003868 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3869 } catch (ImsException e) {
3870 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874 }
3875
3876 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003877 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003879 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003883 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003884 } catch (ImsException e) {
3885 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
3889 }
3890
shilu366312e2019-12-17 09:28:10 -08003891 /**
3892 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3893 * @param subId The subscription to use to check the configuration.
3894 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 @Override
3896 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003897 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3898 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 } catch (ImsException e) {
3905 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 } finally {
3907 Binder.restoreCallingIdentity(identity);
3908 }
3909 }
3910
3911 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003912 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003914 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003918 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (ImsException e) {
3920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
3924 }
3925
shilu366312e2019-12-17 09:28:10 -08003926 /**
3927 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3928 * @param subId The subscription to use to check the configuration.
3929 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 @Override
3931 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003932 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3933 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003937 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003939 } catch (ImsException e) {
3940 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
3944 }
3945
3946 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003947 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003949 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003955 } catch (ImsException e) {
3956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
3960 }
3961
3962 @Override
3963 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3965 "setVoWiFiNonPersistent");
3966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003970 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003971 } catch (ImsException e) {
3972 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
3976 }
3977
shilu366312e2019-12-17 09:28:10 -08003978 /**
3979 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3980 * @param subId The subscription to use to check the configuration.
3981 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 @Override
3983 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003984 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3985 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003991 } catch (ImsException e) {
3992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
3996 }
3997
3998 @Override
3999 public void setVoWiFiModeSetting(int subId, int mode) {
4000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4001 "setVoWiFiModeSetting");
4002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004005 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004007 } catch (ImsException e) {
4008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012 }
4013
4014 @Override
4015 public int getVoWiFiRoamingModeSetting(int subId) {
4016 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (ImsException e) {
4023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
4027 }
4028
4029 @Override
4030 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4032 "setVoWiFiRoamingModeSetting");
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004036 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 } catch (ImsException e) {
4039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043 }
4044
4045 @Override
4046 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4048 "setRttCapabilityEnabled");
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004052 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4053 } catch (ImsException e) {
4054 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
4058 }
4059
shilu366312e2019-12-17 09:28:10 -08004060 /**
4061 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4062 * @param subId The subscription to use to check the configuration.
4063 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 @Override
4065 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004066 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4067 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004071 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 } catch (ImsException e) {
4074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
4078 }
4079
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004080 @Override
4081 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4082 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004085 if (!isImsAvailableOnDevice()) {
4086 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4087 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004088 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004090 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004091 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004092 } catch (ImsException e) {
4093 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
4097 }
4098
4099 @Override
4100 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4101 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4102 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004103 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4104 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4105 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004106 try {
4107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004108 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004109 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004110 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004111 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4112 + "is inactive, ignoring unregister.");
4113 // If the subscription is no longer active, just return, since the callback will already
4114 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
4118 }
4119
allenwtsu99c623b2020-01-03 18:24:23 +08004120
4121 private void checkModifyPhoneStatePermission(int subId, String message) {
4122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4123 message);
4124 }
4125
4126 private boolean isImsProvisioningRequired(int subId, int capability,
4127 boolean isMmtelCapability) {
4128 Phone phone = getPhone(subId);
4129 if (phone == null) {
4130 loge("phone instance null for subid " + subId);
4131 return false;
4132 }
4133 if (isMmtelCapability) {
4134 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4135 return false;
4136 }
4137 } else {
4138 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4139 return false;
4140 }
4141 }
4142 return true;
4143 }
4144
4145 @Override
4146 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4147 boolean isProvisioned) {
4148 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4149
4150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4153 if (!isImsProvisioningRequired(subId, capability, false)) {
4154 return;
4155 }
4156
4157 // this capability requires provisioning, route to the correct API.
4158 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4159 switch (capability) {
4160 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4161 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4162 ims.setEabProvisioned(isProvisioned);
4163 break;
4164 default: {
4165 throw new IllegalArgumentException("Tried to set provisioning for "
4166 + "rcs capability '" + capability + "', which does not require "
4167 + "provisioning.");
4168 }
4169 }
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173
4174 }
4175
4176
4177 @Override
4178 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4179 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4183 if (!isImsProvisioningRequired(subId, capability, false)) {
4184 return true;
4185 }
4186
4187 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4188 switch (capability) {
4189 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4190 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4191 return ims.isEabProvisionedOnDevice();
4192
4193 default: {
4194 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4195 + "capability '" + capability + "', which does not require "
4196 + "provisioning.");
4197 }
4198 }
4199
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004205 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004206 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4207 boolean isProvisioned) {
4208 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4209 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4210 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4211 }
allenwtsu99c623b2020-01-03 18:24:23 +08004212 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004216 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004217 return;
4218 }
4219
4220 // this capability requires provisioning, route to the correct API.
4221 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4222 switch (capability) {
4223 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4224 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4225 ims.setVolteProvisioned(isProvisioned);
4226 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4227 ims.setWfcProvisioned(isProvisioned);
4228 }
4229 break;
4230 }
4231 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4232 // There is currently no difference in VT provisioning type.
4233 ims.setVtProvisioned(isProvisioned);
4234 break;
4235 }
4236 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4237 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4238 // change the capability of the feature instead if needed.
4239 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4240 == isProvisioned) {
4241 // No change in provisioning.
4242 return;
4243 }
4244 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4245 try {
4246 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004247 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004248 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4249 + ", Exception" + e.getMessage());
4250 }
4251 break;
4252 }
4253 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004254 throw new IllegalArgumentException("Tried to set provisioning for "
4255 + "MmTel capability '" + capability + "', which does not require "
4256 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004257 }
4258 }
4259
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
4263 }
4264
4265 @Override
4266 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4267 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4268 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4269 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4270 }
4271 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004275 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004276 return true;
4277 }
4278
4279 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4280 switch (capability) {
4281 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4282 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4283 return ims.isVolteProvisionedOnDevice();
4284 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4285 return ims.isWfcProvisionedOnDevice();
4286 }
4287 // This should never happen, since we are checking tech above to make sure it
4288 // is either LTE or IWLAN.
4289 throw new IllegalArgumentException("Invalid radio technology for voice "
4290 + "capability.");
4291 }
4292 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4293 // There is currently no difference in VT provisioning type.
4294 return ims.isVtProvisionedOnDevice();
4295 }
4296 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4297 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4298 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4299 }
4300 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004301 throw new IllegalArgumentException(
4302 "Tried to get provisioning for MmTel capability '" + capability
4303 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004304 }
4305 }
4306
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 }
4311
4312 @Override
4313 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4314 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4315 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4316 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4317 }
4318 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4319 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4320 return (provisionedBits & capability) > 0;
4321 }
4322
4323 @Override
4324 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4325 boolean isProvisioned) {
4326 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4327 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4328 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4329 }
4330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4331 "setProvisioningStatusForCapability");
4332 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4333 // If the current provisioning status for capability already matches isProvisioned,
4334 // do nothing.
4335 if (((provisionedBits & capability) > 0) == isProvisioned) {
4336 return;
4337 }
4338 if (isProvisioned) {
4339 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4340 } else {
4341 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4342 }
4343 }
4344
4345 /**
4346 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4347 * technology. The bitfield should mirror the bitfield defined by
4348 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4349 */
4350 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4351 String key = getMmTelProvisioningKey(subId, tech);
4352 // Default is no capabilities are provisioned.
4353 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4354 }
4355
4356 /**
4357 * Sets the MmTel capability provisioning bitfield (defined by
4358 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4359 * technology specified.
4360 *
4361 * Note: This is a synchronous command and should not be called on UI thread.
4362 */
4363 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4364 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4365 String key = getMmTelProvisioningKey(subId, tech);
4366 editor.putInt(key, newField);
4367 editor.commit();
4368 }
4369
4370 private static String getMmTelProvisioningKey(int subId, int tech) {
4371 // resulting key is provision_ims_mmtel_{subId}_{tech}
4372 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4373 }
4374
4375 /**
4376 * Query CarrierConfig to see if the specified capability requires provisioning for the
4377 * carrier associated with the subscription id.
4378 */
4379 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4380 int capability) {
4381 CarrierConfigManager configManager = new CarrierConfigManager(context);
4382 PersistableBundle c = configManager.getConfigForSubId(subId);
4383 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004384 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004385 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4386 false);
4387 boolean requireVoiceVtProvisioning = c.getBoolean(
4388 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4389
4390 // First check to make sure that the capability requires provisioning.
4391 switch (capability) {
4392 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4393 // intentional fallthrough
4394 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4395 if (requireVoiceVtProvisioning) {
4396 // Voice and Video requires provisioning
4397 return true;
4398 }
4399 break;
4400 }
4401 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4402 if (requireUtProvisioning) {
4403 // UT requires provisioning
4404 return true;
4405 }
4406 break;
4407 }
4408 }
4409 return false;
4410 }
4411
allenwtsu99c623b2020-01-03 18:24:23 +08004412 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4413 int capability) {
4414 CarrierConfigManager configManager = new CarrierConfigManager(context);
4415 PersistableBundle c = configManager.getConfigForSubId(subId);
4416
4417 boolean requireRcsProvisioning = c.getBoolean(
4418 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4419
4420 // First check to make sure that the capability requires provisioning.
4421 switch (capability) {
4422 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4423 // intentional fallthrough
4424 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4425 if (requireRcsProvisioning) {
4426 // OPTION or PRESENCE requires provisioning
4427 return true;
4428 }
4429 break;
4430 }
4431 }
4432 return false;
4433 }
4434
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004435 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004436 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4438 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4439 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004440 enforceReadPrivilegedPermission("getImsProvisioningInt");
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
4443 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004444 int slotId = getSlotIndex(subId);
4445 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4446 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4447 + subId + "' for key:" + key);
4448 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4449 }
4450 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004451 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004452 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4453 + subId + "' for key:" + key);
4454 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
4460 @Override
4461 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004462 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4463 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4464 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004465 enforceReadPrivilegedPermission("getImsProvisioningString");
4466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004469 int slotId = getSlotIndex(subId);
4470 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4471 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4472 + subId + "' for key:" + key);
4473 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4474 }
4475 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004476 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004477 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4478 + subId + "' for key:" + key);
4479 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484
4485 @Override
4486 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004487 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4488 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4489 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4491 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004495 int slotId = getSlotIndex(subId);
4496 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4497 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4498 + subId + "' for key:" + key);
4499 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4500 }
4501 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004502 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004503 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4504 + "' for key:" + key);
4505 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
4511 @Override
4512 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4514 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4515 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4517 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 int slotId = getSlotIndex(subId);
4522 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4523 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4524 + subId + "' for key:" + key);
4525 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4526 }
4527 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004529 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4530 + "' for key:" + key);
4531 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004532 } finally {
4533 Binder.restoreCallingIdentity(identity);
4534 }
4535 }
4536
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004538 int slotId = SubscriptionManager.getSlotIndex(subId);
4539 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004540 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4541 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 }
4543 return slotId;
4544 }
4545
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004546 private int getSlotIndex(int subId) {
4547 int slotId = SubscriptionManager.getSlotIndex(subId);
4548 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4549 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4550 }
4551 return slotId;
4552 }
4553
Wink Saville36469e72014-06-11 15:17:00 -07004554 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004555 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004556 */
4557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004558 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4559 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004560 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004561 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004562 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004563 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004564 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004565 mApp, subId, callingPackage, callingFeatureId,
4566 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004567 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4568 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
4572 final Phone phone = getPhone(subId);
4573 if (phone != null) {
4574 return phone.getServiceState().getDataNetworkType();
4575 } else {
4576 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4577 }
4578 } finally {
4579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004581 }
4582
4583 /**
4584 * Returns the data network type
4585 */
4586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004587 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4588 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4589 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004590 }
4591
4592 /**
4593 * Returns the data network type for a subId
4594 */
4595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004596 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4597 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004599 mApp, subId, callingPackage, callingFeatureId,
4600 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004601 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4602 }
4603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 final Phone phone = getPhone(subId);
4607 if (phone != null) {
4608 return phone.getServiceState().getDataNetworkType();
4609 } else {
4610 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4611 }
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004615 }
4616
4617 /**
Wink Saville36469e72014-06-11 15:17:00 -07004618 * Returns the Voice network type for a subId
4619 */
4620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004621 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4622 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004624 mApp, subId, callingPackage, callingFeatureId,
4625 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004626 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4627 }
4628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 final long identity = Binder.clearCallingIdentity();
4630 try {
4631 final Phone phone = getPhone(subId);
4632 if (phone != null) {
4633 return phone.getServiceState().getVoiceNetworkType();
4634 } else {
4635 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4636 }
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004640 }
4641
4642 /**
4643 * @return true if a ICC card is present
4644 */
4645 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004646 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004647 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4648 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004649 }
4650
4651 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004652 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004653 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004654 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004655 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 final long identity = Binder.clearCallingIdentity();
4657 try {
4658 final Phone phone = PhoneFactory.getPhone(slotIndex);
4659 if (phone != null) {
4660 return phone.getIccCard().hasIccCard();
4661 } else {
4662 return false;
4663 }
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004667 }
4668
4669 /**
4670 * Return if the current radio is LTE on CDMA. This
4671 * is a tri-state return value as for a period of time
4672 * the mode may be unknown.
4673 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004674 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004675 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004676 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004677 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004679 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4680 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4681 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004682 }
4683
Sanket Padawe356d7632015-06-22 14:03:32 -07004684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004685 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4686 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004687 try {
4688 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4689 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004690 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4691 }
4692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 final Phone phone = getPhone(subId);
4696 if (phone == null) {
4697 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4698 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004699 return TelephonyProperties.lte_on_cdma_device()
4700 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 }
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004704 }
Wink Saville36469e72014-06-11 15:17:00 -07004705 }
4706
Wink Saville36469e72014-06-11 15:17:00 -07004707 /**
4708 * {@hide}
4709 * Returns Default subId, 0 in the case of single standby.
4710 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004711 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004712 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004713 }
4714
Shishir Agrawala9f32182016-04-12 12:00:16 -07004715 private int getSlotForDefaultSubscription() {
4716 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4717 }
4718
Wink Savilleb564aae2014-10-23 10:18:09 -07004719 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004720 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004721 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004722
Pengquan Menge92a50d2018-09-21 15:54:48 -07004723 private boolean isActiveSubscription(int subId) {
4724 return mSubscriptionController.isActiveSubId(subId);
4725 }
4726
Ihab Awadf2177b72013-11-25 13:33:23 -08004727 /**
4728 * @see android.telephony.TelephonyManager.WifiCallingChoices
4729 */
4730 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004733 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4735 getWhenToMakeWifiCallsDefaultPreference());
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004739 }
4740
4741 /**
4742 * @see android.telephony.TelephonyManager.WifiCallingChoices
4743 */
4744 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004748 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004753 }
4754
Sailesh Nepald1e68152013-12-12 19:08:02 -08004755 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004756 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004757 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004758 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004759
Jordan Liu4c733742019-02-28 12:03:40 -08004760 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4761 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4762 if (phoneId == -1) {
4763 throw new IllegalArgumentException("Given slot index: " + slotIndex
4764 + " does not correspond to an active phone");
4765 }
4766 return PhoneFactory.getPhone(phoneId);
4767 }
4768
Shishir Agrawal566b7612013-10-28 14:41:00 -07004769 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004770 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4771 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4773 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004775 if (DBG) {
4776 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4777 }
4778 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4779 p2);
4780 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004781
Jordan Liu4c733742019-02-28 12:03:40 -08004782
4783 @Override
4784 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4785 int slotIndex, String callingPackage, String aid, int p2) {
4786 enforceModifyPermission();
4787 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4788 if (DBG) {
4789 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4790 }
4791 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4792 callingPackage, aid, p2);
4793 }
4794
4795 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4796 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 final long identity = Binder.clearCallingIdentity();
4798 try {
4799 if (TextUtils.equals(ISDR_AID, aid)) {
4800 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004801 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4802 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 if (bestComponent == null
4804 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4805 loge("The calling package is not allowed to access ISD-R.");
4806 throw new SecurityException(
4807 "The calling package is not allowed to access ISD-R.");
4808 }
Derek Tan740e1672017-06-27 14:56:27 -07004809 }
Derek Tan740e1672017-06-27 14:56:27 -07004810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004812 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4813 null /* workSource */);
4814 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 return response;
4816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004819 }
4820
4821 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004822 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4824 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004825 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4826 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004828
Jordan Liu4c733742019-02-28 12:03:40 -08004829 @Override
4830 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4831 enforceModifyPermission();
4832 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4833 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4834 channel);
4835 }
4836
4837 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 final long identity = Binder.clearCallingIdentity();
4839 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004840 if (channel < 0) {
4841 return false;
4842 }
Jordan Liu4c733742019-02-28 12:03:40 -08004843 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4844 null /* workSource */);
4845 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 return success;
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004850 }
4851
4852 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004853 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004854 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4856 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004857 if (DBG) {
4858 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4859 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4860 + p3 + " data=" + data);
4861 }
4862 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4863 command, p1, p2, p3, data);
4864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004865
Jordan Liu4c733742019-02-28 12:03:40 -08004866 @Override
4867 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4868 int command, int p1, int p2, int p3, String data) {
4869 enforceModifyPermission();
4870 if (DBG) {
4871 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4872 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4873 + p3 + " data=" + data);
4874 }
4875 return iccTransmitApduLogicalChannelWithPermission(
4876 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4877 data);
4878 }
4879
4880 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4881 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004884 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885 return "";
4886 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004889 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4890 null /* workSource */);
4891 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 // Append the returned status code to the end of the response payload.
4894 String s = Integer.toHexString(
4895 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4896 if (response.payload != null) {
4897 s = IccUtils.bytesToHexString(response.payload) + s;
4898 }
4899 return s;
4900 } finally {
4901 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004902 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004903 }
Jake Hambye994d462014-02-03 13:10:13 -08004904
Evan Charltonc66da362014-05-16 14:06:40 -07004905 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004906 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4907 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4909 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004911 if (DBG) {
4912 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4913 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4914 }
4915 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4916 cla, command, p1, p2, p3, data);
4917 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004918
Jordan Liu4c733742019-02-28 12:03:40 -08004919 @Override
4920 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4921 int command, int p1, int p2, int p3, String data) {
4922 enforceModifyPermission();
4923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4924 if (DBG) {
4925 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4926 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4927 + " data=" + data);
4928 }
4929
4930 return iccTransmitApduBasicChannelWithPermission(
4931 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4932 p2, p3, data);
4933 }
4934
4935 // open APDU basic channel assuming the caller has sufficient permissions
4936 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4937 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4941 && TextUtils.equals(ISDR_AID, data)) {
4942 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004943 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4944 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 if (bestComponent == null
4946 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4947 loge("The calling package is not allowed to select ISD-R.");
4948 throw new SecurityException(
4949 "The calling package is not allowed to select ISD-R.");
4950 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004951 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004954 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4955 null /* workSource */);
4956 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 // Append the returned status code to the end of the response payload.
4959 String s = Integer.toHexString(
4960 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4961 if (response.payload != null) {
4962 s = IccUtils.bytesToHexString(response.payload) + s;
4963 }
4964 return s;
4965 } finally {
4966 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004967 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004968 }
4969
4970 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004971 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004972 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 if (DBG) {
4979 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4980 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4981 }
4982
4983 IccIoResult response =
4984 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4985 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4986 subId);
4987
4988 if (DBG) {
4989 log("Exchange SIM_IO [R]" + response);
4990 }
4991
4992 byte[] result = null;
4993 int length = 2;
4994 if (response.payload != null) {
4995 length = 2 + response.payload.length;
4996 result = new byte[length];
4997 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4998 } else {
4999 result = new byte[length];
5000 }
5001
5002 result[length - 1] = (byte) response.sw2;
5003 result[length - 2] = (byte) response.sw1;
5004 return result;
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005007 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005008 }
5009
Nathan Haroldb3014052017-01-25 15:57:32 -08005010 /**
5011 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5012 * on a particular subscription
5013 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005014 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5015 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005017 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005018 return null;
5019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 if (appType != TelephonyManager.APPTYPE_USIM
5024 && appType != TelephonyManager.APPTYPE_SIM) {
5025 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5026 return null;
5027 }
5028 Object response = sendRequest(
5029 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5030 if (response instanceof String[]) {
5031 return (String[]) response;
5032 }
yincheng zhao2737e882019-09-06 17:06:54 -07005033 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005035 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005038 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005039 }
5040
yincheng zhao2737e882019-09-06 17:06:54 -07005041 /**
5042 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5043 * subscription.
5044 *
5045 * @param subId the id of the subscription.
5046 * @param appType the uicc app type, must be USIM or SIM.
5047 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5048 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005049 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005050 * @return number of fplmns that is successfully written to the SIM.
5051 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5053 String callingFeatureId) {
5054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5055 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005056 if (DBG) logv("no permissions for setForbiddenplmns");
5057 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5058 }
5059 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5060 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5061 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5062 }
5063 if (fplmns == null) {
5064 throw new IllegalArgumentException("Fplmn List provided is null");
5065 }
5066 for (String fplmn : fplmns) {
5067 if (!CellIdentity.isValidPlmn(fplmn)) {
5068 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5069 }
5070 }
5071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 Object response = sendRequest(
5074 CMD_SET_FORBIDDEN_PLMNS,
5075 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5076 subId);
5077 return (int) response;
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
5081 }
5082
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005083 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005084 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5086 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5091 if (response.payload == null) {
5092 return "";
5093 }
Evan Charltonc66da362014-05-16 14:06:40 -07005094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 // Append the returned status code to the end of the response payload.
5096 String s = Integer.toHexString(
5097 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5098 s = IccUtils.bytesToHexString(response.payload) + s;
5099 return s;
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Evan Charltonc66da362014-05-16 14:06:40 -07005103 }
5104
Jake Hambye994d462014-02-03 13:10:13 -08005105 /**
5106 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5107 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5108 *
5109 * @param itemID the ID of the item to read
5110 * @return the NV item as a String, or null on error.
5111 */
5112 @Override
5113 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5116 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005121 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5123 return value;
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
Jake Hambye994d462014-02-03 13:10:13 -08005127 }
5128
5129 /**
5130 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5131 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5132 *
5133 * @param itemID the ID of the item to read
5134 * @param itemValue the value to write, as a String
5135 * @return true on success; false on any failure
5136 */
5137 @Override
5138 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005139 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5141 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142
5143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5146 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005147 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5149 return success;
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Jake Hambye994d462014-02-03 13:10:13 -08005153 }
5154
5155 /**
5156 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5157 * Used for device configuration by some CDMA operators.
5158 *
5159 * @param preferredRoamingList byte array containing the new PRL
5160 * @return true on success; false on any failure
5161 */
5162 @Override
5163 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5165 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5170 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5171 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5172 return success;
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
Jake Hambye994d462014-02-03 13:10:13 -08005176 }
5177
5178 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005179 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005180 * Used for device configuration by some CDMA operators.
5181 *
chen xu6dac5ab2018-10-26 17:39:23 -07005182 * @param slotIndex - device slot.
5183 *
Jake Hambye994d462014-02-03 13:10:13 -08005184 * @return true on success; false on any failure
5185 */
5186 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005187 public boolean resetModemConfig(int slotIndex) {
5188 Phone phone = PhoneFactory.getPhone(slotIndex);
5189 if (phone != null) {
5190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5191 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192
chen xu6dac5ab2018-10-26 17:39:23 -07005193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5196 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5197 return success;
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 }
chen xu6dac5ab2018-10-26 17:39:23 -07005202 return false;
5203 }
5204
5205 /**
5206 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5207 *
5208 * @param slotIndex - device slot.
5209 *
5210 * @return true on success; false on any failure
5211 */
5212 @Override
5213 public boolean rebootModem(int slotIndex) {
5214 Phone phone = PhoneFactory.getPhone(slotIndex);
5215 if (phone != null) {
5216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5217 mApp, phone.getSubId(), "rebootModem");
5218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5222 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5223 return success;
5224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
5227 }
5228 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005229 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005230
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005231 public String[] getPcscfAddress(String apnType, String callingPackage,
5232 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005233 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5235 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005236 return new String[0];
5237 }
5238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005241 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Wink Saville36469e72014-06-11 15:17:00 -07005245 }
5246
Brad Ebinger51f743a2017-01-23 13:50:20 -08005247 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005248 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5249 * {@link #disableIms(int)}.
5250 * @param slotIndex device slot.
5251 */
5252 public void resetIms(int slotIndex) {
5253 enforceModifyPermission();
5254
5255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 if (mImsResolver == null) {
5258 // may happen if the does not support IMS.
5259 return;
5260 }
5261 mImsResolver.disableIms(slotIndex);
5262 mImsResolver.enableIms(slotIndex);
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
5266 }
5267
5268 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005269 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5270 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005271 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005272 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274
5275 final long identity = Binder.clearCallingIdentity();
5276 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005277 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005278 // may happen if the device does not support IMS.
5279 return;
5280 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005281 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005285 }
5286
5287 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005288 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5289 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005290 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005291 public void disableIms(int slotId) {
5292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293
5294 final long identity = Binder.clearCallingIdentity();
5295 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005296 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005297 // may happen if the device does not support IMS.
5298 return;
5299 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005300 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005304 }
5305
5306 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005307 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5308 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005309 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005310 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005311 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005312 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313
5314 final long identity = Binder.clearCallingIdentity();
5315 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005316 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5318 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005319 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005320 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005324 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005325 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005326 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5327 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005328 @Override
5329 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005330 enforceModifyPermission();
5331
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005335 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
5339 }
5340
5341 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005342 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005343 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005344 */
5345 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5346 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347
5348 final long identity = Binder.clearCallingIdentity();
5349 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005350 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005351 // may happen if the device does not support IMS.
5352 return null;
5353 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005354 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005358 }
5359
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005360 /**
5361 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005362 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005363 */
5364 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5365 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366
5367 final long identity = Binder.clearCallingIdentity();
5368 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005369 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005370 // may happen if the device does not support IMS.
5371 return null;
5372 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005373 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005377 }
5378
Brad Ebinger884c07b2018-02-15 16:17:40 -08005379 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005380 * Sets the ImsService Package Name that Telephony will bind to.
5381 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005382 * @param slotIndex the slot ID that the ImsService should bind for.
5383 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005384 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005385 * @param featureTypes An integer array of feature types associated with a packageName.
5386 * @param packageName The name of the package that the current configuration will be replaced
5387 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005388 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005389 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005390 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5391 int[] featureTypes, String packageName) {
5392 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5395 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005396 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005400 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005401 // may happen if the device does not support IMS.
5402 return false;
5403 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005404 Map<Integer, String> featureConfig = new HashMap<>();
5405 for (int featureType : featureTypes) {
5406 featureConfig.put(featureType, packageName);
5407 }
5408 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5409 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 } finally {
5411 Binder.restoreCallingIdentity(identity);
5412 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005413 }
5414
5415 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005416 * Clears any carrier ImsService overrides for the slot index specified that were previously
5417 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5418 *
5419 * This should only be used for testing.
5420 *
5421 * @param slotIndex the slot ID that the ImsService should bind for.
5422 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5423 */
5424 @Override
5425 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5426 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5427 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5428 "clearCarrierImsServiceOverride");
5429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5430 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5431 "clearCarrierImsServiceOverride");
5432
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 if (mImsResolver == null) {
5436 // may happen if the device does not support IMS.
5437 return false;
5438 }
5439 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
5443 }
5444
5445 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005446 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005447 *
5448 * @param slotId The slot that the ImsService is associated with.
5449 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5450 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005451 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005452 * @return the package name of the ImsService configuration.
5453 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005454 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5455 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005456 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005457 TelephonyPermissions
5458 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5459 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5460 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 final long identity = Binder.clearCallingIdentity();
5463 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005464 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005465 // may happen if the device does not support IMS.
5466 return "";
5467 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005468 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005469 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5470 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005474 }
5475
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005476 /**
5477 * Get the MmTelFeature state associated with the requested subscription id.
5478 * @param subId The subscription that the MmTelFeature is associated with.
5479 * @param callback A callback with an integer containing the
5480 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5481 */
5482 @Override
5483 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5484 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5485 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5486 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5487 "IMS not available on device.");
5488 }
5489 final long token = Binder.clearCallingIdentity();
5490 try {
5491 int slotId = getSlotIndex(subId);
5492 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5493 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5494 + subId + "'");
5495 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5496 }
5497 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5498 try {
5499 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5500 } catch (RemoteException e) {
5501 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5502 + "Ignore");
5503 }
5504 });
5505 } finally {
5506 Binder.restoreCallingIdentity(token);
5507 }
5508 }
5509
Wink Saville36469e72014-06-11 15:17:00 -07005510 public void setImsRegistrationState(boolean registered) {
5511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005515 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Wink Saville36469e72014-06-11 15:17:00 -07005519 }
5520
5521 /**
Stuart Scott54788802015-03-30 13:18:01 -07005522 * Set the network selection mode to automatic.
5523 *
5524 */
5525 @Override
5526 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5528 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529
5530 final long identity = Binder.clearCallingIdentity();
5531 try {
shilufc958392020-01-20 11:36:01 -08005532 if (!isActiveSubscription(subId)) {
5533 return;
5534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5536 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Stuart Scott54788802015-03-30 13:18:01 -07005540 }
5541
Jack Yud10cdd42020-09-28 20:28:01 -07005542 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005543 * Ask the radio to connect to the input network and change selection mode to manual.
5544 *
5545 * @param subId the id of the subscription.
5546 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5547 * the operator to attach to.
5548 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5549 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5550 * normal network selection next time.
5551 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005552 */
5553 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005554 public boolean setNetworkSelectionModeManual(
5555 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5557 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005558
5559 if (!isActiveSubscription(subId)) {
5560 return false;
5561 }
5562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 final long identity = Binder.clearCallingIdentity();
5564 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005565 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005567 if (DBG) {
5568 log("setNetworkSelectionModeManual: subId: " + subId
5569 + " operator: " + operatorInfo);
5570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005575 }
shilu84f6e8b2019-12-19 13:58:01 -08005576 /**
5577 * Get the manual network selection
5578 *
5579 * @param subId the id of the subscription.
5580 *
5581 * @return the previously saved user selected PLMN
5582 */
5583 @Override
5584 public String getManualNetworkSelectionPlmn(int subId) {
5585 TelephonyPermissions
5586 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5587 mApp, subId, "getManualNetworkSelectionPlmn");
5588
5589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005592 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005593 }
5594
5595 final Phone phone = getPhone(subId);
5596 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005597 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005598 }
5599 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5600 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5601 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
5605 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005606
5607 /**
5608 * Scans for available networks.
5609 */
5610 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005611 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5612 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5614 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005615 LocationAccessPolicy.LocationPermissionResult locationResult =
5616 LocationAccessPolicy.checkLocationPermission(mApp,
5617 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5618 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005619 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005620 .setCallingPid(Binder.getCallingPid())
5621 .setCallingUid(Binder.getCallingUid())
5622 .setMethod("getCellNetworkScanResults")
5623 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005624 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5625 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005626 .build());
5627 switch (locationResult) {
5628 case DENIED_HARD:
5629 throw new SecurityException("Not allowed to access scan results -- location");
5630 case DENIED_SOFT:
5631 return null;
5632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
Pengquan Menga1bb6272018-09-06 09:59:22 -07005634 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 try {
5636 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005637 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005642 }
5643
5644 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005645 * Get the call forwarding info, given the call forwarding reason.
5646 */
5647 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005648 public void getCallForwarding(int subId, int callForwardingReason,
5649 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005650 enforceReadPrivilegedPermission("getCallForwarding");
5651 long identity = Binder.clearCallingIdentity();
5652 try {
5653 if (DBG) {
5654 log("getCallForwarding: subId " + subId
5655 + " callForwardingReason" + callForwardingReason);
5656 }
Hall Liu27d24262020-09-18 19:04:59 -07005657
5658 Phone phone = getPhone(subId);
5659 if (phone == null) {
5660 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005661 callback.onError(
5662 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005663 } catch (RemoteException e) {
5664 // ignore
5665 }
5666 return;
5667 }
5668
5669 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5670 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5671 @Override
5672 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5673 try {
5674 callback.onCallForwardingInfoAvailable(info);
5675 } catch (RemoteException e) {
5676 // ignore
5677 }
5678 }
5679
5680 @Override
5681 public void onError(int error) {
5682 try {
5683 callback.onError(error);
5684 } catch (RemoteException e) {
5685 // ignore
5686 }
5687 }
5688 });
5689 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
5693 }
5694
5695 /**
5696 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5697 * reason, the number to forward, and the timeout before the forwarding is attempted.
5698 */
5699 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005700 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5701 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005702 enforceModifyPermission();
5703 long identity = Binder.clearCallingIdentity();
5704 try {
5705 if (DBG) {
5706 log("setCallForwarding: subId " + subId
5707 + " callForwardingInfo" + callForwardingInfo);
5708 }
Hall Liu27d24262020-09-18 19:04:59 -07005709
5710 Phone phone = getPhone(subId);
5711 if (phone == null) {
5712 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005713 callback.accept(
5714 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005715 } catch (RemoteException e) {
5716 // ignore
5717 }
5718 return;
5719 }
5720
5721 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5722 FunctionalUtils.ignoreRemoteException(callback::accept));
5723
5724 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
5728 }
5729
5730 /**
Hall Liu27d24262020-09-18 19:04:59 -07005731 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005732 */
5733 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005734 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005735 enforceReadPrivilegedPermission("getCallForwarding");
5736 long identity = Binder.clearCallingIdentity();
5737 try {
Hall Liu27d24262020-09-18 19:04:59 -07005738
5739 Phone phone = getPhone(subId);
5740 if (phone == null) {
5741 try {
5742 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5743 } catch (RemoteException e) {
5744 // ignore
5745 }
5746 return;
5747 }
5748
5749 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5750
Shuo Qian4a594052020-01-23 11:59:30 -08005751 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005752 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
5756 }
5757
5758 /**
Hall Liu27d24262020-09-18 19:04:59 -07005759 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005760 */
5761 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005762 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005763 enforceModifyPermission();
5764 long identity = Binder.clearCallingIdentity();
5765 try {
Hall Liu27d24262020-09-18 19:04:59 -07005766 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5767
5768 Phone phone = getPhone(subId);
5769 if (phone == null) {
5770 try {
5771 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5772 } catch (RemoteException e) {
5773 // ignore
5774 }
5775 return;
5776 }
5777
5778 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5779 FunctionalUtils.ignoreRemoteException(callback::accept));
5780
5781 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
5787 /**
yinxub1bed742017-04-17 11:45:04 -07005788 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005789 *
yinxub1bed742017-04-17 11:45:04 -07005790 * @param subId id of the subscription
5791 * @param request contains the radio access networks with bands/channels to scan
5792 * @param messenger callback messenger for scan results or errors
5793 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005794 * @return the id of the requested scan which can be used to stop the scan.
5795 */
5796 @Override
5797 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005798 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5800 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005801 LocationAccessPolicy.LocationPermissionResult locationResult =
5802 LocationAccessPolicy.checkLocationPermission(mApp,
5803 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5804 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005805 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005806 .setCallingPid(Binder.getCallingPid())
5807 .setCallingUid(Binder.getCallingUid())
5808 .setMethod("requestNetworkScan")
5809 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005810 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5811 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005812 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005813 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005814 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5815 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005816 if (e != null) {
5817 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5818 throw e;
5819 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005820 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005821 return TelephonyScanManager.INVALID_SCAN_ID;
5822 }
5823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 }
Hall Liu912dfd32019-04-25 14:02:26 -07005825 int callingUid = Binder.getCallingUid();
5826 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005827 final long identity = Binder.clearCallingIdentity();
5828 try {
5829 return mNetworkScanRequestTracker.startNetworkScan(
5830 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005831 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
yinxu504e1392017-04-12 16:03:22 -07005835 }
5836
Hall Liub2ac8ef2019-02-28 15:56:23 -08005837 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005838 NetworkScanRequest request, int subId, String callingPackage) {
5839 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005840 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5841 boolean hasNetworkScanPermission =
5842 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5843 == PERMISSION_GRANTED;
5844
5845 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5846 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5847 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005848 }
5849
5850 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5851 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005852 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5853 return new SecurityException("Specific channels must not be"
5854 + " scanned without location access.");
5855 }
5856 }
5857 }
5858
Hall Liub2ac8ef2019-02-28 15:56:23 -08005859 return null;
5860 }
5861
yinxu504e1392017-04-12 16:03:22 -07005862 /**
5863 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005864 *
5865 * @param subId id of the subscription
5866 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005867 */
5868 @Override
5869 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5871 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872
Hall Liu912dfd32019-04-25 14:02:26 -07005873 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005876 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
yinxu504e1392017-04-12 16:03:22 -07005880 }
5881
5882 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005883 * Get the calculated preferred network type.
5884 * Used for debugging incorrect network type.
5885 *
5886 * @return the preferred network type, defined in RILConstants.java.
5887 */
5888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005889 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005890 final Phone defaultPhone = getDefaultPhone();
5891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005892 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005893 return RILConstants.PREFERRED_NETWORK_MODE;
5894 }
5895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 final long identity = Binder.clearCallingIdentity();
5897 try {
5898 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005899 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Junda Liu84d15a22014-07-02 11:21:04 -07005903 }
5904
5905 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005906 * Get the preferred network type.
5907 * Used for device configuration by some CDMA operators.
5908 *
5909 * @return the preferred network type, defined in RILConstants.java.
5910 */
5911 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005912 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005913 TelephonyPermissions
5914 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5915 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 if (DBG) log("getPreferredNetworkType");
5920 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5921 int networkType = (result != null ? result[0] : -1);
5922 if (DBG) log("getPreferredNetworkType: " + networkType);
5923 return networkType;
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005927 }
5928
5929 /**
5930 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005931 *
5932 * @param networkType the preferred network type, defined in RILConstants.java.
5933 * @return true on success; false on any failure.
5934 */
5935 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005936 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5938 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
calvinpan8ed33732020-03-12 14:17:55 +08005942 Boolean success = (Boolean) sendRequest(
5943 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005944
5945 if (success) {
5946 Settings.Global.putInt(mApp.getContentResolver(),
5947 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5948 }
calvinpan8ed33732020-03-12 14:17:55 +08005949 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5950 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 } finally {
5952 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005953 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005954 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005955
5956 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005957 * Get the allowed network types that store in the telephony provider.
5958 *
5959 * @param subId the id of the subscription.
5960 * @return allowedNetworkTypes the allowed network types.
5961 */
5962 @Override
5963 public long getAllowedNetworkTypes(int subId) {
5964 TelephonyPermissions
5965 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5966 mApp, subId, "getAllowedNetworkTypes");
5967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 return SubscriptionManager.getLongSubscriptionProperty(
5971 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
5975 }
5976
5977 /**
5978 * Set the allowed network types.
5979 *
5980 * @param subId the id of the subscription.
5981 * @param allowedNetworkTypes the allowed network types.
5982 * @return true on success; false on any failure.
5983 */
5984 @Override
5985 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5987 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005988
calvinpan8ed33732020-03-12 14:17:55 +08005989 SubscriptionManager.setSubscriptionProperty(subId,
5990 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5991 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005992
calvinpan8ed33732020-03-12 14:17:55 +08005993 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5994 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5995 RILConstants.PREFERRED_NETWORK_MODE);
5996 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005997 }
5998
5999 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006000 * Get the allowed network types for certain reason.
6001 *
6002 * @param subId the id of the subscription.
6003 * @param reason the reason the allowed network type change is taking place
6004 * @return the allowed network types.
6005 */
6006 @Override
6007 public long getAllowedNetworkTypesForReason(int subId,
6008 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6009 TelephonyPermissions
6010 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6011 mApp, subId, "getAllowedNetworkTypesForReason");
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
6014 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
6018 }
6019
6020 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006021 * Enable/Disable E-UTRA-NR Dual Connectivity
6022 * @param subId subscription id of the sim card
6023 * @param nrDualConnectivityState expected NR dual connectivity state
6024 * This can be passed following states
6025 * <ol>
6026 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6027 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6028 * <li>Disable NR dual connectivity and force secondary cell to be released
6029 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6030 * </ol>
6031 * @return operation result.
6032 */
6033 @Override
6034 public int setNrDualConnectivityState(int subId,
6035 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6037 mApp, subId, "enableNRDualConnectivity");
6038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6039 final long identity = Binder.clearCallingIdentity();
6040 try {
6041 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6042 nrDualConnectivityState, subId,
6043 workSource);
6044 if (DBG) log("enableNRDualConnectivity result: " + result);
6045 return result;
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
6049 }
6050
6051 /**
6052 * Is E-UTRA-NR Dual Connectivity enabled
6053 * @return true if dual connectivity is enabled else false
6054 */
6055 @Override
6056 public boolean isNrDualConnectivityEnabled(int subId) {
6057 TelephonyPermissions
6058 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6059 mApp, subId, "isNRDualConnectivityEnabled");
6060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6064 null, subId, workSource);
6065 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6066 return isEnabled;
6067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
6070 }
6071
6072 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006073 * get carrier bandwidth per primary and secondary carrier
6074 * @param subId subscription id of the sim card
6075 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6076 */
6077 @Override
6078 public CarrierBandwidth getCarrierBandwidth(int subId) {
6079 TelephonyPermissions
6080 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6081 mApp, subId, "isNRDualConnectivityEnabled");
6082 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 CarrierBandwidth carrierBandwidth =
6086 getPhoneFromSubId(subId).getCarrierBandwidth();
6087 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6088 return carrierBandwidth;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
6092 }
6093
6094 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006095 * Get the effective allowed network types on the device.
6096 * This API will return an intersection of allowed network types for all reasons,
6097 * including the configuration done through setAllowedNetworkTypes
6098 *
6099 * @param subId the id of the subscription.
6100 * @return the allowed network types
6101 */
6102 @Override
6103 public long getEffectiveAllowedNetworkTypes(int subId) {
6104 TelephonyPermissions
6105 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6106 mApp, subId, "getEffectiveAllowedNetworkTypes");
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
6113 }
6114
6115 /**
6116 * Set the allowed network types of the device and
6117 * provide the reason triggering the allowed network change.
6118 *
6119 * @param subId the id of the subscription.
6120 * @param reason the reason the allowed network type change is taking place
6121 * @param allowedNetworkTypes the allowed network types.
6122 * @return true on success; false on any failure.
6123 */
6124 @Override
6125 public boolean setAllowedNetworkTypesForReason(int subId,
6126 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6128 mApp, subId, "setAllowedNetworkTypesForReason");
6129 final long identity = Binder.clearCallingIdentity();
6130 try {
6131 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6132 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6133 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6134 RILConstants.PREFERRED_NETWORK_MODE);
6135 return setPreferredNetworkType(subId, preferredNetworkMode);
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
Miaoa84611c2019-03-15 09:21:10 +08006142 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006143 *
Miaoa84611c2019-03-15 09:21:10 +08006144 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006145 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006146 * @hide
6147 */
6148 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006149 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006152 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 try {
Miaoa84611c2019-03-15 09:21:10 +08006154 if (phone != null) {
6155 return phone.hasMatchedTetherApnSetting();
6156 } else {
6157 return false;
6158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 } finally {
6160 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006161 }
Junda Liu475951f2014-11-07 16:45:03 -08006162 }
6163
6164 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006165 * Enable or disable always reporting signal strength changes from radio.
6166 *
6167 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6168 */
6169 @Override
6170 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6171 enforceModifyPermission();
6172 enforceSystemCaller();
6173
6174 final long identity = Binder.clearCallingIdentity();
6175 final Phone phone = getPhone(subId);
6176 try {
6177 if (phone != null) {
6178 if (DBG) {
6179 log("setAlwaysReportSignalStrength: subId=" + subId
6180 + " isEnable=" + isEnable);
6181 }
6182 phone.setAlwaysReportSignalStrength(isEnable);
6183 } else {
6184 loge("setAlwaysReportSignalStrength: no phone found for subId="
6185 + subId);
6186 }
6187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006193 * Get the user enabled state of Mobile Data.
6194 *
6195 * TODO: remove and use isUserDataEnabled.
6196 * This can't be removed now because some vendor codes
6197 * calls through ITelephony directly while they should
6198 * use TelephonyManager.
6199 *
6200 * @return true on enabled
6201 */
6202 @Override
6203 public boolean getDataEnabled(int subId) {
6204 return isUserDataEnabled(subId);
6205 }
6206
6207 /**
6208 * Get whether mobile data is enabled per user setting.
6209 *
6210 * There are other factors deciding whether mobile data is actually enabled, but they are
6211 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006212 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006213 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006214 *
6215 * @return {@code true} if data is enabled else {@code false}
6216 */
6217 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006218 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006219 try {
6220 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6221 null);
6222 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6224 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 int phoneId = mSubscriptionController.getPhoneId(subId);
6230 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6231 Phone phone = PhoneFactory.getPhone(phoneId);
6232 if (phone != null) {
6233 boolean retVal = phone.isUserDataEnabled();
6234 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6235 return retVal;
6236 } else {
6237 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6238 return false;
6239 }
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006242 }
6243 }
6244
6245 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006246 * Checks if the device is capable of mobile data by considering whether whether the
6247 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6248 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006249 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006250 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006251 */
6252 @Override
6253 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006254 try {
6255 try {
6256 mApp.enforceCallingOrSelfPermission(
6257 android.Manifest.permission.ACCESS_NETWORK_STATE,
6258 null);
6259 } catch (Exception e) {
6260 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6261 "isDataEnabled");
6262 }
6263 } catch (Exception e) {
6264 enforceReadPrivilegedPermission("isDataEnabled");
6265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 int phoneId = mSubscriptionController.getPhoneId(subId);
6270 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6271 Phone phone = PhoneFactory.getPhone(phoneId);
6272 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006273 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6275 return retVal;
6276 } else {
6277 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6278 return false;
6279 }
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006282 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006283 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006284
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006285 /**
6286 * Check if data is enabled for a specific reason
6287 * @param subId Subscription index
6288 * @param reason the reason the data enable change is taking place
6289 * @return {@code true} if the overall data is enabled; {@code false} if not.
6290 */
6291 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006292 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006293 @TelephonyManager.DataEnabledReason int reason) {
6294 try {
6295 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6296 null);
6297 } catch (Exception e) {
6298 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006299 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006300 }
6301
6302
6303 final long identity = Binder.clearCallingIdentity();
6304 try {
6305 int phoneId = mSubscriptionController.getPhoneId(subId);
6306 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006307 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006308 + " reason=" + reason);
6309 }
6310 Phone phone = PhoneFactory.getPhone(phoneId);
6311 if (phone != null) {
6312 boolean retVal;
6313 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6314 retVal = phone.isUserDataEnabled();
6315 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006316 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006317 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006318 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006319 return retVal;
6320 } else {
6321 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006322 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006323 + subId + " retVal=false");
6324 }
6325 return false;
6326 }
6327 } finally {
6328 Binder.restoreCallingIdentity(identity);
6329 }
6330 }
6331
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006332 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006333 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006334 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6335 // Skip the check if it's one of these special uids
6336 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6337 }
6338
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006339 //load access rules from carrier configs, and check those as well: b/139133814
6340 SubscriptionController subController = SubscriptionController.getInstance();
6341 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6342 || subController == null) return privilegeFromSim;
6343
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006344 PackageManager pkgMgr = phone.getContext().getPackageManager();
6345 String[] packages = pkgMgr.getPackagesForUid(uid);
6346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006349 int subId = phone.getSubId();
6350 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6351 // A test override is in place for the privileges for this subId, so don't try to
6352 // read the subscription privileges.
6353 return privilegeFromSim;
6354 }
6355 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006356 SubscriptionManager subManager = (SubscriptionManager)
6357 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6358 for (String pkg : packages) {
6359 if (subManager.canManageSubscription(subInfo, pkg)) {
6360 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6361 }
6362 }
6363 return privilegeFromSim;
6364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
6367 }
6368
6369 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6370 String pkgName) {
6371 //load access rules from carrier configs, and check those as well: b/139133814
6372 SubscriptionController subController = SubscriptionController.getInstance();
6373 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6374 || subController == null) return privilegeFromSim;
6375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006378 int subId = phone.getSubId();
6379 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6380 // A test override is in place for the privileges for this subId, so don't try to
6381 // read the subscription privileges.
6382 return privilegeFromSim;
6383 }
6384 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006385 SubscriptionManager subManager = (SubscriptionManager)
6386 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6387 return subManager.canManageSubscription(subInfo, pkgName)
6388 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
6392 }
6393
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006394 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006395 public int getCarrierPrivilegeStatus(int subId) {
6396 final Phone phone = getPhone(subId);
6397 if (phone == null) {
6398 loge("getCarrierPrivilegeStatus: Invalid subId");
6399 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6400 }
6401 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006402 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006403 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006404 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6405 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006406
6407 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6408 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006409 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006410 }
Junda Liu29340342014-07-10 15:23:27 -07006411
6412 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006413 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006414 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006415 final Phone phone = getPhone(subId);
6416 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006417 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6419 }
6420 UiccProfile profile =
6421 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6422 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006423 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006424 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6425 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006426 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006427 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006428 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006429 }
6430
6431 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006432 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6433 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006434 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006435 }
6436
6437 int phoneId = SubscriptionManager.getPhoneId(subId);
6438 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006439 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006440 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006441 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6442 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006443 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6444 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6445 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006446 }
6447
6448 @Override
6449 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006450 if (TextUtils.isEmpty(pkgName))
6451 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006452 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6453 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6454 UiccCard card = UiccController.getInstance().getUiccCard(i);
6455 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006456 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006457 continue;
6458 }
6459
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006460 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6461 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6462 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006463 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6464 break;
6465 }
6466 }
6467
6468 return result;
Junda Liu29340342014-07-10 15:23:27 -07006469 }
Derek Tan89e89d42014-07-08 17:00:10 -07006470
6471 @Override
Junda Liue64de782015-04-16 17:19:16 -07006472 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6473 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6474 loge("phoneId " + phoneId + " is not valid.");
6475 return null;
6476 }
6477 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006478 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006479 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006480 return null ;
6481 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006482 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006483 }
6484
Amith Yamasani6e118872016-02-19 12:53:51 -08006485 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006486 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006487 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006488 List<String> privilegedPackages = new ArrayList<>();
6489 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006490 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6491 // has UICC in that slot.
6492 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006493 if (card.hasCarrierPrivilegeRules()) {
6494 if (packages == null) {
6495 // Only check packages in user 0 for now
6496 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006497 PackageManager.MATCH_DISABLED_COMPONENTS
6498 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006499 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006500 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006501 }
6502 for (int p = packages.size() - 1; p >= 0; p--) {
6503 PackageInfo pkgInfo = packages.get(p);
6504 if (pkgInfo != null && pkgInfo.packageName != null
6505 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006506 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006507 privilegedPackages.add(pkgInfo.packageName);
6508 }
6509 }
6510 }
6511 }
6512 return privilegedPackages;
6513 }
6514
chen xuf7e9fe82019-05-09 19:31:02 -07006515 @Override
6516 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006517 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6518
6519 final long identity = Binder.clearCallingIdentity();
6520
chen xuf7e9fe82019-05-09 19:31:02 -07006521 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006522 try {
6523 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6524 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6525 }
6526 } finally {
6527 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006528 }
6529 return privilegedPackages;
6530 }
6531
Wink Savilleb564aae2014-10-23 10:18:09 -07006532 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006533 final Phone phone = getPhone(subId);
6534 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006535 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006536 return null;
6537 }
6538 String iccId = card.getIccId();
6539 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006540 return null;
6541 }
6542 return iccId;
6543 }
6544
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006545 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006546 public void setCallComposerStatus(int subId, int status) {
6547 enforceModifyPermission();
6548
6549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 Phone phone = getPhone(subId);
6552 if (phone != null) {
6553 Phone defaultPhone = phone.getImsPhone();
6554 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6555 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6556 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006557 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6558 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006559 }
6560 }
Shuo Qian284ae752020-12-22 19:10:14 -08006561 } catch (ImsException e) {
6562 throw new ServiceSpecificException(e.getCode());
6563 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 @Override
6569 public int getCallComposerStatus(int subId) {
6570 enforceReadPrivilegedPermission("getCallComposerStatus");
6571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 Phone phone = getPhone(subId);
6575 if (phone != null) {
6576 Phone defaultPhone = phone.getImsPhone();
6577 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6578 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6579 return imsPhone.getCallComposerStatus();
6580 }
6581 }
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
6585 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6586 }
6587
6588 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006589 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6590 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006591 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006592 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 final String iccId = getIccId(subId);
6597 final Phone phone = getPhone(subId);
6598 if (phone == null) {
6599 return false;
6600 }
6601 final String subscriberId = phone.getSubscriberId();
6602
6603 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006604 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 + subscriberId + " to " + number);
6606 }
6607
6608 if (TextUtils.isEmpty(iccId)) {
6609 return false;
6610 }
6611
6612 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6613
6614 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6615 if (alphaTag == null) {
6616 editor.remove(alphaTagPrefKey);
6617 } else {
6618 editor.putString(alphaTagPrefKey, alphaTag);
6619 }
6620
6621 // Record both the line number and IMSI for this ICCID, since we need to
6622 // track all merged IMSIs based on line number
6623 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6624 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6625 if (number == null) {
6626 editor.remove(numberPrefKey);
6627 editor.remove(subscriberPrefKey);
6628 } else {
6629 editor.putString(numberPrefKey, number);
6630 editor.putString(subscriberPrefKey, subscriberId);
6631 }
6632
6633 editor.commit();
6634 return true;
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006637 }
Derek Tan7226c842014-07-02 17:42:23 -07006638 }
6639
6640 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006641 public String getLine1NumberForDisplay(int subId, String callingPackage,
6642 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006643 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006645 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006646 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006647 return null;
6648 }
Derek Tan97ebb422014-09-05 16:55:38 -07006649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 String iccId = getIccId(subId);
6653 if (iccId != null) {
6654 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6655 if (DBG_MERGE) {
6656 log("getLine1NumberForDisplay returning "
6657 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6658 }
6659 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6662 return null;
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006665 }
Derek Tan7226c842014-07-02 17:42:23 -07006666 }
6667
6668 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006669 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6670 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006672 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006673 return null;
6674 }
Derek Tan97ebb422014-09-05 16:55:38 -07006675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 final long identity = Binder.clearCallingIdentity();
6677 try {
6678 String iccId = getIccId(subId);
6679 if (iccId != null) {
6680 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6681 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6682 }
6683 return null;
6684 } finally {
6685 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006686 }
Derek Tan7226c842014-07-02 17:42:23 -07006687 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006688
6689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006690 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6691 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006692 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6693 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006695 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006696 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006697 return null;
6698 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006699
Jordan Liub49b04b2019-05-06 14:45:15 -07006700 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6701 // the process, where TelephonyManager was instantiated.
6702 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006703 final long identity = Binder.clearCallingIdentity();
6704 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006705 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final TelephonyManager tele = TelephonyManager.from(context);
6707 final SubscriptionManager sub = SubscriptionManager.from(context);
6708
6709 // Figure out what subscribers are currently active
6710 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711
Jordan Liub49b04b2019-05-06 14:45:15 -07006712 // Only consider subs which match the current subId
6713 // This logic can be simplified. See b/131189269 for progress.
6714 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006715 activeSubscriberIds.add(tele.getSubscriberId(subId));
6716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717
6718 // First pass, find a number override for an active subscriber
6719 String mergeNumber = null;
6720 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6721 for (String key : prefs.keySet()) {
6722 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6723 final String subscriberId = (String) prefs.get(key);
6724 if (activeSubscriberIds.contains(subscriberId)) {
6725 final String iccId = key.substring(
6726 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6727 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6728 mergeNumber = (String) prefs.get(numberKey);
6729 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006730 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 + " for active subscriber " + subscriberId);
6732 }
6733 if (!TextUtils.isEmpty(mergeNumber)) {
6734 break;
6735 }
6736 }
6737 }
6738 }
6739
6740 // Shortcut when no active merged subscribers
6741 if (TextUtils.isEmpty(mergeNumber)) {
6742 return null;
6743 }
6744
6745 // Second pass, find all subscribers under that line override
6746 final ArraySet<String> result = new ArraySet<>();
6747 for (String key : prefs.keySet()) {
6748 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6749 final String number = (String) prefs.get(key);
6750 if (mergeNumber.equals(number)) {
6751 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6752 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6753 final String subscriberId = (String) prefs.get(subscriberKey);
6754 if (!TextUtils.isEmpty(subscriberId)) {
6755 result.add(subscriberId);
6756 }
6757 }
6758 }
6759 }
6760
6761 final String[] resultArray = result.toArray(new String[result.size()]);
6762 Arrays.sort(resultArray);
6763 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006764 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6766 }
6767 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006770 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006771 }
6772
6773 @Override
zoey chen38003472019-12-13 17:16:31 +08006774 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6775 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006776
6777 final long identity = Binder.clearCallingIdentity();
6778 try {
6779 final TelephonyManager telephonyManager = mApp.getSystemService(
6780 TelephonyManager.class);
6781 String subscriberId = telephonyManager.getSubscriberId(subId);
6782 if (subscriberId == null) {
6783 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006784 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006785 + subId);
6786 }
6787 return null;
6788 }
6789
6790 final SubscriptionInfo info = SubscriptionController.getInstance()
6791 .getSubscriptionInfo(subId);
6792 final ParcelUuid groupUuid = info.getGroupUuid();
6793 // If it doesn't belong to any group, return just subscriberId of itself.
6794 if (groupUuid == null) {
6795 return new String[]{subscriberId};
6796 }
6797
6798 // Get all subscriberIds from the group.
6799 final List<String> mergedSubscriberIds = new ArrayList<>();
6800 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006801 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006802 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006803 for (SubscriptionInfo subInfo : groupInfos) {
6804 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6805 if (subscriberId != null) {
6806 mergedSubscriberIds.add(subscriberId);
6807 }
6808 }
6809
6810 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813
6814 }
6815 }
6816
6817 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006818 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006819 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006820 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 final Phone phone = getPhone(subId);
6825 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
6828 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006829 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006830
6831 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006832 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006833 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6834 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006835 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6836 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837
6838 final long identity = Binder.clearCallingIdentity();
6839 try {
6840 final Phone phone = getPhone(subId);
6841 if (phone == null) {
6842 return false;
6843 }
6844 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6845 cdmaNonRoamingList);
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006848 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006849 }
6850
6851 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006852 @Deprecated
6853 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6854 enforceModifyPermission();
6855
6856 int returnValue = 0;
6857 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006858 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006859 if(result.exception == null) {
6860 if (result.result != null) {
6861 byte[] responseData = (byte[])(result.result);
6862 if(responseData.length > oemResp.length) {
6863 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6864 responseData.length + "bytes. Buffer Size is " +
6865 oemResp.length + "bytes.");
6866 }
6867 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6868 returnValue = responseData.length;
6869 }
6870 } else {
6871 CommandException ex = (CommandException) result.exception;
6872 returnValue = ex.getCommandError().ordinal();
6873 if(returnValue > 0) returnValue *= -1;
6874 }
6875 } catch (RuntimeException e) {
6876 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6877 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6878 if(returnValue > 0) returnValue *= -1;
6879 }
6880
6881 return returnValue;
6882 }
6883
6884 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006885 public void setRadioCapability(RadioAccessFamily[] rafs) {
6886 try {
6887 ProxyController.getInstance().setRadioCapability(rafs);
6888 } catch (RuntimeException e) {
6889 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6890 }
6891 }
6892
6893 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006894 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006895 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006896 try {
6897 TelephonyPermissions
6898 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6899 mApp, phone.getSubId(), "getRadioAccessFamily");
6900 } catch (SecurityException e) {
6901 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6902 throw e;
6903 }
chen xub97461a2018-10-26 14:17:57 -07006904 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006905 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006906 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 final long identity = Binder.clearCallingIdentity();
6909 try {
chen xub97461a2018-10-26 14:17:57 -07006910 TelephonyPermissions
6911 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6912 mApp, phone.getSubId(), "getRadioAccessFamily");
6913 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
chen xub97461a2018-10-26 14:17:57 -07006917 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006918 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006919
6920 @Override
6921 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006922 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006923 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924
6925 final long identity = Binder.clearCallingIdentity();
6926 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006927 ImsManager.getInstance(defaultPhone.getContext(),
6928 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006932 }
6933
6934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006935 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006936 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6938 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006939 return false;
6940 }
Svet Ganovb320e182015-04-16 12:30:10 -07006941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 final long identity = Binder.clearCallingIdentity();
6943 try {
6944 // Check the user preference and the system-level IMS setting. Even if the user has
6945 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6946 // In the long run, we may instead need to check if there exists a connection service
6947 // which can support video calling.
6948 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006949 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 return imsManager.isVtEnabledByPlatform()
6951 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6952 && imsManager.isVtEnabledByUser();
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006956 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006957
Andrew Leea1239f22015-03-02 17:44:07 -08006958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006959 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6960 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006962 mApp, subId, callingPackage, callingFeatureId,
6963 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 return false;
6965 }
6966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 CarrierConfigManager configManager =
6970 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006971 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
Andrew Leea1239f22015-03-02 17:44:07 -08006976 }
6977
6978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006979 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006981 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 return false;
6983 }
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 CarrierConfigManager configManager =
6988 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006989 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
6993 }
Andrew Leea1239f22015-03-02 17:44:07 -08006994 }
6995
Andrew Lee9431b832015-03-09 18:46:45 -07006996 @Override
6997 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006998 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006999 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007000 }
7001
7002 @Override
7003 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 final long identity = Binder.clearCallingIdentity();
7005 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007006 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
Andrew Lee9431b832015-03-09 18:46:45 -07007010 }
7011
Hall Liuf6668912018-10-31 17:05:23 -07007012 /**
7013 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7014 * support for the feature and device firmware support.
7015 *
7016 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7017 */
7018 @Override
7019 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007021 final Phone phone = getPhone(subscriptionId);
7022 if (phone == null) {
7023 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7024 return false;
7025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007027 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7029 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 return isCarrierSupported && isDeviceSupported;
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
Hall Liu98187582018-01-22 19:15:32 -08007035 }
7036
Hall Liuf6668912018-10-31 17:05:23 -07007037 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007038 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7039 * RTT setting, will return true if the device and carrier both support RTT.
7040 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007041 */
7042 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 final long identity = Binder.clearCallingIdentity();
7044 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007045 boolean isRttSupported = isRttSupported(subscriptionId);
7046 boolean isUserRttSettingOn = Settings.Secure.getInt(
7047 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7048 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7049 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7050 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007054 }
7055
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007056 @Deprecated
7057 @Override
7058 public String getDeviceId(String callingPackage) {
7059 return getDeviceIdWithFeature(callingPackage, null);
7060 }
7061
Sanket Padawe7310cc72015-01-14 09:53:20 -08007062 /**
7063 * Returns the unique device ID of phone, for example, the IMEI for
7064 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7065 *
7066 * <p>Requires Permission:
7067 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7068 */
7069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007070 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007071 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007072 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007073 return null;
7074 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007075 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007076 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007077 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007078 return null;
7079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080
7081 final long identity = Binder.clearCallingIdentity();
7082 try {
7083 return phone.getDeviceId();
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007087 }
7088
Ping Sunc67b7c22016-03-02 19:16:45 +08007089 /**
7090 * {@hide}
7091 * Returns the IMS Registration Status on a particular subid
7092 *
7093 * @param subId
7094 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007095 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007096 Phone phone = getPhone(subId);
7097 if (phone != null) {
7098 return phone.isImsRegistered();
7099 } else {
7100 return false;
7101 }
7102 }
7103
Santos Cordon7a1885b2015-02-03 11:15:19 -08007104 @Override
7105 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
7111 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007112 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007113
Tyler Gunnf70ed162019-04-03 15:28:53 -07007114 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007115 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007116 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007119 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7120 }
7121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
7127 }
7128
7129 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007130 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007131 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7132 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 Phone phone = getPhone(subscriptionId);
7136 if (phone == null) {
7137 return null;
7138 }
7139 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
7143 }
7144
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007145 /**
7146 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007147 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007148 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 Phone phone = getPhone(subId);
7152 if (phone != null) {
7153 return phone.isWifiCallingEnabled();
7154 } else {
7155 return false;
7156 }
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007159 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007160 }
7161
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007162 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007163 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007164 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007165 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 Phone phone = getPhone(subId);
7169 if (phone != null) {
7170 return phone.isVideoEnabled();
7171 } else {
7172 return false;
7173 }
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007176 }
7177 }
7178
7179 /**
7180 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7181 * defined in {@link ImsRegistrationImplBase}.
7182 */
7183 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 final long identity = Binder.clearCallingIdentity();
7185 try {
7186 Phone phone = getPhone(subId);
7187 if (phone != null) {
7188 return phone.getImsRegistrationTech();
7189 } else {
7190 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7191 }
7192 } finally {
7193 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007194 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007195 }
7196
Stuart Scott8eef64f2015-04-08 15:13:54 -07007197 @Override
7198 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007199 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007200 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7201 return;
7202 }
7203
Svet Ganovcc087f82015-05-12 20:35:54 -07007204 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007205
Svet Ganovcc087f82015-05-12 20:35:54 -07007206 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007207 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7208 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007209 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007210 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007211 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007212 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007213 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7214 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007215 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007216 // There has been issues when Sms raw table somehow stores orphan
7217 // fragments. They lead to garbled message when new fragments come
7218 // in and combined with those stale ones. In case this happens again,
7219 // user can reset all network settings which will clean up this table.
7220 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007221 // Clean up IMS settings as well here.
7222 int slotId = getSlotIndex(subId);
7223 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7224 ImsManager.getInstance(mApp, slotId).factoryReset();
7225 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007226
7227 // Erase modem config if erase modem on network setting is enabled.
7228 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7229 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7230 if (configValue != null && Boolean.parseBoolean(configValue)) {
7231 sendEraseModemConfig(getDefaultPhone());
7232 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007233 } finally {
7234 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007235 }
7236 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007237
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007238 private void cleanUpSmsRawTable(Context context) {
7239 ContentResolver resolver = context.getContentResolver();
7240 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7241 resolver.delete(uri, null, null);
7242 }
7243
Narayan Kamath1c496c22015-04-16 14:40:19 +01007244 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007245 public String getSimLocaleForSubscriber(int subId) {
7246 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7247 final Phone phone = getPhone(subId);
7248 if (phone == null) {
7249 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007250 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 final long identity = Binder.clearCallingIdentity();
7253 try {
chen xu5d3637b2019-01-21 23:31:38 -08007254 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007255 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007256 if (info == null) {
7257 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7258 return null;
7259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 // Try and fetch the locale from the carrier properties or from the SIM language
7261 // preferences (EF-PL and EF-LI)...
7262 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007264 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7265 if (localeFromDefaultSim != null) {
7266 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7267 if (DBG) log("Using locale from subId: " + subId + " locale: "
7268 + localeFromDefaultSim);
7269 return localeFromDefaultSim.toLanguageTag();
7270 } else {
7271 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 }
7273 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 // The SIM language preferences only store a language (e.g. fr = French), not an
7276 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7277 // the SIM and carrier preferences does not include a country we add the country
7278 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007279 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007281 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 return mccLocale.toLanguageTag();
7283 }
7284
7285 if (DBG) log("No locale found - returning null");
7286 return null;
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007290 }
7291
7292 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007293 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007294 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007295 }
7296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 /**
7298 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7299 */
7300 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007301 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007302 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007303 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007304
Chenjie Yu1ba97252018-01-11 18:16:20 -08007305 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007306 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007307
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007308 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007309 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7310 * representing the state of the modem.
7311 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007312 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7313 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007314 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007315 */
7316 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007317 public void requestModemActivityInfo(ResultReceiver result) {
7318 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320
7321 final long identity = Binder.clearCallingIdentity();
7322 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007323 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007326 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007327 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007328
Siddharth Rayb8114062018-06-17 15:02:38 -07007329 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7330 // less than total activity duration.
7331 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7332 if (info == null) {
7333 return false;
7334 }
7335 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007336 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7337 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7338
Siddharth Rayb8114062018-06-17 15:02:38 -07007339 return (info.isValid()
7340 && (info.getSleepTimeMillis() <= activityDurationMs)
7341 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007342 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007343 && (totalTxTimeMs <= activityDurationMs));
7344 }
7345
Jack Yu85bd38a2015-11-09 11:34:32 -08007346 /**
7347 * {@hide}
7348 * Returns the service state information on specified subscription.
7349 */
7350 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007351 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7352 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007354 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007355 return null;
7356 }
7357
Hall Liuf19c44f2018-11-27 14:38:17 -08007358 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7359 LocationAccessPolicy.checkLocationPermission(mApp,
7360 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7361 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007362 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007363 .setCallingPid(Binder.getCallingPid())
7364 .setCallingUid(Binder.getCallingUid())
7365 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007366 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007367 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007368 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7369 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007370 .build());
7371
7372 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7373 LocationAccessPolicy.checkLocationPermission(mApp,
7374 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7375 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007376 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007377 .setCallingPid(Binder.getCallingPid())
7378 .setCallingUid(Binder.getCallingUid())
7379 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007380 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007381 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007382 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7383 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007384 .build());
7385 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7386 boolean hasFinePermission =
7387 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7388 boolean hasCoarsePermission =
7389 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7390
Jack Yu479f40e2020-10-27 21:29:25 -07007391 final Phone phone = getPhone(subId);
7392 if (phone == null) {
7393 return null;
7394 }
7395
Jordan Liu0f2bc442020-11-18 16:47:37 -08007396 final long identity = Binder.clearCallingIdentity();
7397
Jack Yu479f40e2020-10-27 21:29:25 -07007398 boolean isCallingPackageDataService = phone.getDataServicePackages()
7399 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007401 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7402 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7403 Rlog.d(LOG_TAG,
7404 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7405 return null;
7406 }
7407
Hall Liuf19c44f2018-11-27 14:38:17 -08007408 ServiceState ss = phone.getServiceState();
7409
7410 // Scrub out the location info in ServiceState depending on what level of access
7411 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007412 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007413 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7414 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007418 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007419
7420 /**
7421 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7422 *
7423 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7424 * voicemail ringtone.
7425 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7426 * PhoneAccount.
7427 */
7428 @Override
7429 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 final long identity = Binder.clearCallingIdentity();
7431 try {
7432 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7433 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007434 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007441 }
7442
7443 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007444 * Sets the per-account voicemail ringtone.
7445 *
7446 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7447 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7448 *
7449 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7450 * voicemail ringtone.
7451 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7452 * PhoneAccount.
7453 */
7454 @Override
7455 public void setVoicemailRingtoneUri(String callingPackage,
7456 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007457 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007459 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7460 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7462 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7463 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7469 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007470 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 }
7472 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007475 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007476 }
7477
7478 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007479 * Returns whether vibration is set for voicemail notification in Phone settings.
7480 *
7481 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7482 * voicemail vibration setting.
7483 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7484 */
7485 @Override
7486 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7490 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007491 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007498 }
7499
Youhan Wange64578a2016-05-02 15:32:42 -07007500 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007501 * Sets the per-account voicemail vibration.
7502 *
7503 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7504 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7505 *
7506 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7507 * voicemail vibration setting.
7508 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7509 * specific PhoneAccount.
7510 */
7511 @Override
7512 public void setVoicemailVibrationEnabled(String callingPackage,
7513 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007514 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007516 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7517 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7519 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7520 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007521 }
7522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7526 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 }
7529 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007532 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007533 }
7534
7535 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007536 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7537 *
7538 * @throws SecurityException if the caller does not have the required permission
7539 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007540 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007541 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007542 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007543 }
7544
7545 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007546 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7547 * permission.
7548 *
7549 * @throws SecurityException if the caller does not have the required permission
7550 */
7551 private void enforceSendSmsPermission() {
7552 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7553 }
7554
7555 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007556 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007557 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007558 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007559 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007560 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 final long identity = Binder.clearCallingIdentity();
7562 try {
7563 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 if (componentName == null) {
7566 throw new SecurityException(
7567 "Caller not current active visual voicemail package[null]");
7568 }
7569 String vvmPackage = componentName.getPackageName();
7570 if (!callingPackage.equals(vvmPackage)) {
7571 throw new SecurityException("Caller not current active visual voicemail package["
7572 + vvmPackage + "]");
7573 }
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007576 }
7577 }
7578
7579 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007580 * Return the application ID for the app type.
7581 *
7582 * @param subId the subscription ID that this request applies to.
7583 * @param appType the uicc app type.
7584 * @return Application ID for specificied app type, or null if no uicc.
7585 */
7586 @Override
7587 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007588 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007589 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590
7591 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007592 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 if (phone == null) {
7594 return null;
7595 }
7596 String aid = null;
7597 try {
7598 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7599 .getApplicationByType(appType).getAid();
7600 } catch (Exception e) {
7601 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7602 }
7603 return aid;
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007606 }
Youhan Wange64578a2016-05-02 15:32:42 -07007607 }
7608
Youhan Wang4001d252016-05-11 10:29:41 -07007609 /**
7610 * Return the Electronic Serial Number.
7611 *
7612 * @param subId the subscription ID that this request applies to.
7613 * @return ESN or null if error.
7614 */
7615 @Override
7616 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007617 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007618 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619
7620 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007621 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 if (phone == null) {
7623 return null;
7624 }
7625 String esn = null;
7626 try {
7627 esn = phone.getEsn();
7628 } catch (Exception e) {
7629 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7630 }
7631 return esn;
7632 } finally {
7633 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007634 }
Youhan Wang4001d252016-05-11 10:29:41 -07007635 }
7636
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007637 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007638 * Return the Preferred Roaming List Version.
7639 *
7640 * @param subId the subscription ID that this request applies to.
7641 * @return PRLVersion or null if error.
7642 */
7643 @Override
7644 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007645 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007646 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647
7648 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007649 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 if (phone == null) {
7651 return null;
7652 }
7653 String cdmaPrlVersion = null;
7654 try {
7655 cdmaPrlVersion = phone.getCdmaPrlVersion();
7656 } catch (Exception e) {
7657 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7658 }
7659 return cdmaPrlVersion;
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007662 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007663 }
7664
7665 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007666 * Get snapshot of Telephony histograms
7667 * @return List of Telephony histograms
7668 * @hide
7669 */
7670 @Override
7671 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7673 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 return RIL.getTelephonyRILTimingHistograms();
7678 } finally {
7679 Binder.restoreCallingIdentity(identity);
7680 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007681 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007682
7683 /**
7684 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007685 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7686 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007687 * Require system privileges. In the future we may add this to carrier APIs.
7688 *
Michele Berionne482f8202018-11-27 18:57:59 -08007689 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007690 */
7691 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007692 @TelephonyManager.SetCarrierRestrictionResult
7693 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007694 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007695 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007696
Michele Berionne482f8202018-11-27 18:57:59 -08007697 if (carrierRestrictionRules == null) {
7698 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007699 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 final long identity = Binder.clearCallingIdentity();
7702 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007703 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007704 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705 } finally {
7706 Binder.restoreCallingIdentity(identity);
7707 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007708 }
7709
7710 /**
7711 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007712 * Get the allowed carrier list and the excluded carrier list, including the priority between
7713 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007714 * Require system privileges. In the future we may add this to carrier APIs.
7715 *
Michele Berionne482f8202018-11-27 18:57:59 -08007716 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007717 */
7718 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007719 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007720 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007725 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7726 if (response instanceof CarrierRestrictionRules) {
7727 return (CarrierRestrictionRules) response;
7728 }
7729 // Response is an Exception of some kind,
7730 // which is signalled to the user as a NULL retval
7731 return null;
7732 } catch (Exception e) {
7733 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7734 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 }
7739
fionaxu59545b42016-05-25 15:53:37 -07007740 /**
fionaxu59545b42016-05-25 15:53:37 -07007741 * Action set from carrier signalling broadcast receivers to enable/disable radio
7742 * @param subId the subscription ID that this action applies to.
7743 * @param enabled control enable or disable radio.
7744 * {@hide}
7745 */
7746 @Override
7747 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7748 enforceModifyPermission();
7749 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750
7751 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007752 if (phone == null) {
7753 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7754 return;
7755 }
7756 try {
7757 phone.carrierActionSetRadioEnabled(enabled);
7758 } catch (Exception e) {
7759 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 } finally {
7761 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007762 }
7763 }
7764
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007765 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007766 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7767 * network status based on which carrier apps could apply actions accordingly,
7768 * enable/disable default url handler for example.
7769 *
7770 * @param subId the subscription ID that this action applies to.
7771 * @param report control start/stop reporting the default network status.
7772 * {@hide}
7773 */
7774 @Override
7775 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7776 enforceModifyPermission();
7777 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778
7779 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007780 if (phone == null) {
7781 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7782 return;
7783 }
7784 try {
7785 phone.carrierActionReportDefaultNetworkStatus(report);
7786 } catch (Exception e) {
7787 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 } finally {
7789 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007790 }
7791 }
7792
7793 /**
fionaxud9622282017-07-17 17:51:30 -07007794 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7795 * @param subId the subscription ID that this action applies to.
7796 * {@hide}
7797 */
7798 @Override
7799 public void carrierActionResetAll(int subId) {
7800 enforceModifyPermission();
7801 final Phone phone = getPhone(subId);
7802 if (phone == null) {
7803 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7804 return;
7805 }
7806 try {
7807 phone.carrierActionResetAll();
7808 } catch (Exception e) {
7809 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7810 }
7811 }
7812
7813 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007814 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7815 * bug report is being generated.
7816 */
7817 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007818 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007819 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7820 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007821 writer.println("Permission Denial: can't dump Phone from pid="
7822 + Binder.getCallingPid()
7823 + ", uid=" + Binder.getCallingUid()
7824 + "without permission "
7825 + android.Manifest.permission.DUMP);
7826 return;
7827 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007828 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007829 }
Jack Yueb89b242016-06-22 13:27:47 -07007830
Brad Ebingerdac2f002018-04-03 15:17:52 -07007831 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007832 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7833 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7834 @NonNull String[] args) {
7835 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7836 this, in.getFileDescriptor(), out.getFileDescriptor(),
7837 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007838 }
7839
Jack Yueb89b242016-06-22 13:27:47 -07007840 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007841 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007842 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007843 * @param reason the reason the data enable change is taking place
7844 * @param enabled True if enabling the data, otherwise disabling.
7845 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007846 */
7847 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007848 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007849 boolean enabled) {
7850 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7851 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7852 try {
7853 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007854 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007855 } catch (SecurityException se) {
7856 enforceModifyPermission();
7857 }
7858 } else {
7859 enforceModifyPermission();
7860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861
7862 final long identity = Binder.clearCallingIdentity();
7863 try {
7864 Phone phone = getPhone(subId);
7865 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007866 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7867 phone.carrierActionSetMeteredApnsEnabled(enabled);
7868 } else {
7869 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 }
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007874 }
7875 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007876
7877 /**
7878 * Get Client request stats
7879 * @return List of Client Request Stats
7880 * @hide
7881 */
7882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007883 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7884 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007887 return null;
7888 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007889 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 if (phone != null) {
7894 return phone.getClientRequestStats();
7895 }
7896
7897 return null;
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
7900 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007901 }
7902
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007903 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007904 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007905 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007906 }
Jack Yueb4124c2017-02-16 15:32:43 -08007907
7908 /**
Grace Chen70990072017-03-24 17:21:30 -07007909 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007910 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007911 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007912 * @param state State of SIM (power down, power up, pass through)
7913 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7914 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7915 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007916 *
7917 **/
7918 @Override
Grace Chen70990072017-03-24 17:21:30 -07007919 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007920 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007921 Phone phone = PhoneFactory.getPhone(slotIndex);
7922
vagdeviaf9a5b92018-08-15 16:01:53 -07007923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 final long identity = Binder.clearCallingIdentity();
7926 try {
7927 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08007928 phone.setSimPowerState(state, null, workSource);
7929 }
7930 } finally {
7931 Binder.restoreCallingIdentity(identity);
7932 }
7933 }
7934
7935 /**
7936 * Set SIM card power state.
7937 *
7938 * @param slotIndex SIM slot id.
7939 * @param state State of SIM (power down, power up, pass through)
7940 * @param callback callback to trigger after success or failure
7941 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7942 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7943 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7944 *
7945 **/
7946 @Override
7947 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7948 IIntegerConsumer callback) {
7949 enforceModifyPermission();
7950 Phone phone = PhoneFactory.getPhone(slotIndex);
7951
7952 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7953
7954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 if (phone != null) {
7957 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7958 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 }
7960 } finally {
7961 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007962 }
7963 }
Shuo Qiandd210312017-04-12 22:11:33 +00007964
Tyler Gunn65d45c22017-06-05 11:22:26 -07007965 private boolean isUssdApiAllowed(int subId) {
7966 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007967 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007968 if (configManager == null) {
7969 return false;
7970 }
7971 PersistableBundle pb = configManager.getConfigForSubId(subId);
7972 if (pb == null) {
7973 return false;
7974 }
7975 return pb.getBoolean(
7976 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7977 }
7978
Shuo Qiandd210312017-04-12 22:11:33 +00007979 /**
7980 * Check if phone is in emergency callback mode
7981 * @return true if phone is in emergency callback mode
7982 * @param subId sub id
7983 */
goneil9c5f4872017-12-05 14:07:56 -08007984 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007985 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007986 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988
7989 final long identity = Binder.clearCallingIdentity();
7990 try {
7991 if (phone != null) {
7992 return phone.isInEcm();
7993 } else {
7994 return false;
7995 }
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007998 }
7999 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008000
8001 /**
8002 * Get the current signal strength information for the given subscription.
8003 * Because this information is not updated when the device is in a low power state
8004 * it should not be relied-upon to be current.
8005 * @param subId Subscription index
8006 * @return the most recent cached signal strength info from the modem
8007 */
8008 @Override
8009 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 Phone p = getPhone(subId);
8013 if (p == null) {
8014 return null;
8015 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 return p.getSignalStrength();
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
8020 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008021 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008022
Pengquan Meng77b7f132018-08-22 14:49:57 -07008023 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008024 * Get the current modem radio state for the given slot.
8025 * @param slotIndex slot index.
8026 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008027 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008028 * @return the current radio power state from the modem
8029 */
8030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008031 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008032 Phone phone = PhoneFactory.getPhone(slotIndex);
8033 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8035 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008036 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8037 }
8038
8039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 return phone.getRadioPowerState();
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
8044 }
8045 }
8046 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8047 }
8048
8049 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008050 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8051 *
8052 * <p>Requires one of the following permissions:
8053 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8054 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8055 * privileges.
8056 *
8057 * @param subId subscription id
8058 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8059 * {@code false}.
8060 */
8061 @Override
8062 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008063 try {
8064 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8065 null);
8066 } catch (Exception e) {
8067 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8068 mApp, subId, "isDataRoamingEnabled");
8069 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008070
Pengquan Menga1bb6272018-09-06 09:59:22 -07008071 boolean isEnabled = false;
8072 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008073 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008074 Phone phone = getPhone(subId);
8075 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008076 } finally {
8077 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008078 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008079 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008080 }
8081
8082
8083 /**
8084 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8085 *
8086 * <p> Requires permission:
8087 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8088 * privileges.
8089 *
8090 * @param subId subscription id
8091 * @param isEnabled {@code true} means enable, {@code false} means disable.
8092 */
8093 @Override
8094 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8096 mApp, subId, "setDataRoamingEnabled");
8097
Pengquan Menga1bb6272018-09-06 09:59:22 -07008098 final long identity = Binder.clearCallingIdentity();
8099 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008100 Phone phone = getPhone(subId);
8101 if (phone != null) {
8102 phone.setDataRoamingEnabled(isEnabled);
8103 }
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008106 }
8107 }
8108
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008109 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008110 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008111 TelephonyPermissions
8112 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008113 mApp, subId, "isManualNetworkSelectionAllowed");
8114
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008115 boolean isAllowed = true;
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008118 Phone phone = getPhone(subId);
8119 if (phone != null) {
8120 isAllowed = phone.isCspPlmnEnabled();
8121 }
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
8124 }
8125 return isAllowed;
8126 }
8127
8128 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008129 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008130 // Verify that tha callingPackage belongs to the calling UID
8131 mApp.getSystemService(AppOpsManager.class)
8132 .checkPackage(Binder.getCallingUid(), callingPackage);
8133
Jordan Liu1e142fc2019-04-22 15:10:43 -07008134 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008135 try {
8136 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008137 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008138 } catch (SecurityException e) {
8139 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8140 // has carrier privileges on an active UICC
8141 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8142 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008143 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008144 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008145 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008146
8147 final long identity = Binder.clearCallingIdentity();
8148 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008149 UiccController uiccController = UiccController.getInstance();
8150 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008151 if (hasReadPermission) {
8152 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008153 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008154
8155 // Remove private info if the caller doesn't have access
8156 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8157 for (UiccCardInfo cardInfo : cardInfos) {
8158 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8159 // is available
8160 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8161 if (card == null || card.getUiccProfile() == null) {
8162 // assume no access if the card or profile is unavailable
8163 filteredInfos.add(cardInfo.getUnprivileged());
8164 continue;
8165 }
8166 UiccProfile profile = card.getUiccProfile();
8167 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8168 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8169 filteredInfos.add(cardInfo);
8170 } else {
8171 filteredInfos.add(cardInfo.getUnprivileged());
8172 }
8173 }
8174 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008175 } finally {
8176 Binder.restoreCallingIdentity(identity);
8177 }
8178 }
8179
8180 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008181 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008182 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 final long identity = Binder.clearCallingIdentity();
8185 try {
8186 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8187 if (slots == null) {
8188 Rlog.i(LOG_TAG, "slots is null.");
8189 return null;
8190 }
8191
8192 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8193 for (int i = 0; i < slots.length; i++) {
8194 UiccSlot slot = slots[i];
8195 if (slot == null) {
8196 continue;
8197 }
8198
Jordan Liu7be7e652019-05-06 18:55:02 +00008199 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 UiccCard card = slot.getUiccCard();
8201 if (card != null) {
8202 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008203 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008204 cardId = slot.getEid();
8205 if (TextUtils.isEmpty(cardId)) {
8206 cardId = slot.getIccId();
8207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 }
8209
Jordan Liu857451f2019-05-09 16:35:35 -07008210 if (cardId != null) {
8211 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8212 // if cardId is an EID, it's all digits so this is fine
8213 cardId = IccUtils.stripTrailingFs(cardId);
8214 }
8215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008216 int cardState = 0;
8217 switch (slot.getCardState()) {
8218 case CARDSTATE_ABSENT:
8219 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8220 break;
8221 case CARDSTATE_PRESENT:
8222 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8223 break;
8224 case CARDSTATE_ERROR:
8225 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8226 break;
8227 case CARDSTATE_RESTRICTED:
8228 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8229 break;
8230 default:
8231 break;
8232
8233 }
8234
8235 infos[i] = new UiccSlotInfo(
8236 slot.isActive(),
8237 slot.isEuicc(),
8238 cardId,
8239 cardState,
8240 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008241 slot.isExtendedApduSupported(),
8242 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 }
8244 return infos;
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008247 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008248 }
8249
8250 @Override
8251 public boolean switchSlots(int[] physicalSlots) {
8252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253
8254 final long identity = Binder.clearCallingIdentity();
8255 try {
8256 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008260 }
Jack Yu4c988042018-02-27 15:30:01 -08008261
8262 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008263 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008264 final long identity = Binder.clearCallingIdentity();
8265 try {
8266 return UiccController.getInstance().getCardIdForDefaultEuicc();
8267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
8270 }
8271
Pengquan Meng85728fb2018-03-12 16:31:21 -07008272 /**
goneil47ffb6e2018-04-06 15:40:58 -07008273 * A test API to reload the UICC profile.
8274 *
8275 * <p>Requires that the calling app has permission
8276 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8277 * @hide
8278 */
8279 @Override
8280 public void refreshUiccProfile(int subId) {
8281 enforceModifyPermission();
8282
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 Phone phone = getPhone(subId);
8286 if (phone == null) {
8287 return;
8288 }
8289 UiccCard uiccCard = phone.getUiccCard();
8290 if (uiccCard == null) {
8291 return;
8292 }
8293 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8294 if (uiccProfile == null) {
8295 return;
8296 }
8297 uiccProfile.refresh();
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
8301 }
8302
8303 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008304 * Returns false if the mobile data is disabled by default, otherwise return true.
8305 */
8306 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008307 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008308 }
8309
8310 /**
8311 * Returns true if the data roaming is enabled by default, i.e the system property
8312 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8313 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8314 */
8315 private boolean getDefaultDataRoamingEnabled(int subId) {
8316 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008317 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008318 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008319 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8320 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8321 return isDataRoamingEnabled;
8322 }
8323
8324 /**
8325 * Returns the default network type for the given {@code subId}, if the default network type is
8326 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8327 */
8328 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008329 List<Integer> list = TelephonyProperties.default_network();
8330 int phoneId = mSubscriptionController.getPhoneId(subId);
8331 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8332 return list.get(phoneId);
8333 }
8334 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008335 }
fionaxua13278b2018-03-21 00:08:13 -07008336
8337 @Override
8338 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008339 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008340 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341
8342 final long identity = Binder.clearCallingIdentity();
8343 try {
8344 final Phone phone = getPhone(subId);
8345 if (phone == null) {
8346 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8347 return;
8348 }
chen xueaba88a2019-03-15 13:15:10 -07008349 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8350 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008351 if (carrierPrivilegeRules == null) {
8352 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8353 } else {
8354 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 } finally {
8357 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008358 }
fionaxua13278b2018-03-21 00:08:13 -07008359 }
8360
8361 @Override
8362 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008363 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364
8365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 final Phone phone = getPhone(subId);
8368 if (phone == null) {
8369 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8370 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8371 }
8372 return phone.getCarrierIdListVersion();
8373 } finally {
8374 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008375 }
fionaxua13278b2018-03-21 00:08:13 -07008376 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008377
8378 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008379 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8380 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008382 mApp, subId, callingPackage, callingFeatureId,
8383 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008384 return -1;
8385 }
8386
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8390 } finally {
8391 Binder.restoreCallingIdentity(identity);
8392 }
8393 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008394
8395 @Override
8396 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008397 TelephonyPermissions
8398 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008399 mApp, subId, "getCdmaRoamingMode");
8400
8401 final long identity = Binder.clearCallingIdentity();
8402 try {
8403 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
8408
8409 @Override
8410 public boolean setCdmaRoamingMode(int subId, int mode) {
8411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8412 mApp, subId, "setCdmaRoamingMode");
8413
8414 final long identity = Binder.clearCallingIdentity();
8415 try {
8416 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
8419 }
8420 }
8421
8422 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008423 public int getCdmaSubscriptionMode(int subId) {
8424 TelephonyPermissions
8425 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8426 mApp, subId, "getCdmaSubscriptionMode");
8427
8428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
8434 }
8435
8436 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008437 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8439 mApp, subId, "setCdmaSubscriptionMode");
8440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
8447 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008448
sqianc5eccab2018-10-19 18:46:41 -07008449 @Override
sqian8c685422019-02-22 15:55:18 -08008450 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008451 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008453 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8454 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008455 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8456 }
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
sqian854d44b2018-12-12 16:48:18 -08008459 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8460 for (Phone phone: PhoneFactory.getPhones()) {
8461 if (phone.getEmergencyNumberTracker() != null
8462 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8463 emergencyNumberListInternal.put(
8464 phone.getSubId(),
8465 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8466 }
sqian11b7a0e2018-12-05 18:48:28 -08008467 }
sqian854d44b2018-12-12 16:48:18 -08008468 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008469 } finally {
8470 Binder.restoreCallingIdentity(identity);
8471 }
sqianc5eccab2018-10-19 18:46:41 -07008472 }
8473
8474 @Override
sqian8c685422019-02-22 15:55:18 -08008475 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008476 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008477 if (!exactMatch) {
8478 TelephonyPermissions
8479 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008480 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008481 }
8482 final long identity = Binder.clearCallingIdentity();
8483 try {
sqian854d44b2018-12-12 16:48:18 -08008484 for (Phone phone: PhoneFactory.getPhones()) {
8485 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008486 && phone.getEmergencyNumberTracker()
8487 .isEmergencyNumber(number, exactMatch)) {
8488 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008489 }
sqian11b7a0e2018-12-05 18:48:28 -08008490 }
8491 return false;
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
8494 }
8495 }
8496
sqianf4ca7ed2019-01-15 18:32:07 -08008497 /**
8498 * Update emergency number list for test mode.
8499 */
8500 @Override
8501 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8502 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8503 "updateEmergencyNumberListTestMode");
8504
8505 final long identity = Binder.clearCallingIdentity();
8506 try {
8507 for (Phone phone: PhoneFactory.getPhones()) {
8508 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8509 if (tracker != null) {
8510 tracker.executeEmergencyNumberTestModeCommand(action, num);
8511 }
8512 }
8513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
8516 }
8517
8518 /**
8519 * Get the full emergency number list for test mode.
8520 */
8521 @Override
8522 public List<String> getEmergencyNumberListTestMode() {
8523 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8524 "getEmergencyNumberListTestMode");
8525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 Set<String> emergencyNumbers = new HashSet<>();
8529 for (Phone phone: PhoneFactory.getPhones()) {
8530 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8531 if (tracker != null) {
8532 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8533 emergencyNumbers.add(num.getNumber());
8534 }
8535 }
8536 }
8537 return new ArrayList<>(emergencyNumbers);
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
8540 }
8541 }
8542
chen xud6b45bd2018-10-30 22:27:10 -07008543 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008544 public int getEmergencyNumberDbVersion(int subId) {
8545 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8546
8547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 final Phone phone = getPhone(subId);
8550 if (phone == null) {
8551 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8552 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8553 }
8554 return phone.getEmergencyNumberDbVersion();
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
8558 }
8559
8560 @Override
8561 public void notifyOtaEmergencyNumberDbInstalled() {
8562 enforceModifyPermission();
8563
8564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 for (Phone phone: PhoneFactory.getPhones()) {
8567 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8568 if (tracker != null) {
8569 tracker.updateOtaEmergencyNumberDatabase();
8570 }
8571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
8574 }
8575 }
8576
8577 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008578 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008579 enforceActiveEmergencySessionPermission();
8580
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 for (Phone phone: PhoneFactory.getPhones()) {
8584 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8585 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008586 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8587 }
8588 }
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593
8594 @Override
8595 public void resetOtaEmergencyNumberDbFilePath() {
8596 enforceActiveEmergencySessionPermission();
8597
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 for (Phone phone: PhoneFactory.getPhones()) {
8601 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8602 if (tracker != null) {
8603 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008604 }
8605 }
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
8609 }
8610
8611 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008612 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8613 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8614 Phone phone = getPhone(subId);
8615 if (phone == null) {
8616 return null;
8617 }
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 UiccProfile profile = UiccController.getInstance()
8621 .getUiccProfileForPhone(phone.getPhoneId());
8622 if (profile != null) {
8623 return profile.getCertsFromCarrierPrivilegeAccessRules();
8624 }
8625 } finally {
8626 Binder.restoreCallingIdentity(identity);
8627 }
8628 return null;
8629 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008630
8631 /**
8632 * Enable or disable a modem stack.
8633 */
8634 @Override
8635 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8636 enforceModifyPermission();
8637
8638 final long identity = Binder.clearCallingIdentity();
8639 try {
8640 Phone phone = PhoneFactory.getPhone(slotIndex);
8641 if (phone == null) {
8642 return false;
8643 } else {
8644 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8645 }
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
Michelecea4cf22018-12-21 15:00:11 -08008650
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008651 /**
8652 * Whether a modem stack is enabled or not.
8653 */
8654 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008655 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8656 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008657 Phone phone = PhoneFactory.getPhone(slotIndex);
8658 if (phone == null) return false;
8659
8660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008661 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8662 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008663 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8664 }
8665
8666 final long identity = Binder.clearCallingIdentity();
8667 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008668 try {
8669 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8670 } catch (NoSuchElementException ex) {
8671 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8672 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
8676 }
8677
Michelecea4cf22018-12-21 15:00:11 -08008678 @Override
Michele0ea7d782019-03-19 14:58:42 -07008679 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008680 enforceModifyPermission();
8681
8682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008685 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008686 .commit();
8687 } finally {
8688 Binder.restoreCallingIdentity(identity);
8689 }
8690 }
8691
8692 @Override
Michele0ea7d782019-03-19 14:58:42 -07008693 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008694 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008696 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8697 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008698 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008699 }
Michelecea4cf22018-12-21 15:00:11 -08008700
8701 final long identity = Binder.clearCallingIdentity();
8702 try {
Michele0ea7d782019-03-19 14:58:42 -07008703 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008704 } finally {
8705 Binder.restoreCallingIdentity(identity);
8706 }
8707 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008708
Michele0ea7d782019-03-19 14:58:42 -07008709 @TelephonyManager.IsMultiSimSupportedResult
8710 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008711 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8712 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8713 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008714 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8715 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008716 }
8717 // Check if the hardware supports multisim functionality. If usage of multisim is not
8718 // supported by the modem, indicate that it is restricted.
8719 PhoneCapability staticCapability =
8720 mPhoneConfigurationManager.getStaticPhoneCapability();
8721 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008722 loge("isMultiSimSupportedInternal: no static configuration available");
8723 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008724 }
Sarah Chin7caee492020-02-18 20:49:02 +00008725 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008726 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8727 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008728 }
8729 // Check if support of multiple SIMs is restricted by carrier
8730 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008731 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008732 }
8733
Michele0ea7d782019-03-19 14:58:42 -07008734 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008735 }
8736
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008737 /**
8738 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008739 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8740 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8741 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008742 * @param numOfSims number of active sims we want to switch to
8743 */
8744 @Override
8745 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008746 if (numOfSims == 1) {
8747 enforceModifyPermission();
8748 } else {
8749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8750 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8751 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008752 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008753
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008754 try {
Michele30b57b22019-03-01 12:01:14 -08008755 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008756 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008757 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8758 return;
8759 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008760 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 }
8765
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008766 @Override
8767 public boolean isApplicationOnUicc(int subId, int appType) {
8768 enforceReadPrivilegedPermission("isApplicationOnUicc");
8769 Phone phone = getPhone(subId);
8770 if (phone == null) {
8771 return false;
8772 }
8773 final long identity = Binder.clearCallingIdentity();
8774 try {
8775 UiccCard uiccCard = phone.getUiccCard();
8776 if (uiccCard == null) {
8777 return false;
8778 }
8779 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8780 if (uiccProfile == null) {
8781 return false;
8782 }
8783 if (TelephonyManager.APPTYPE_SIM <= appType
8784 && appType <= TelephonyManager.APPTYPE_ISIM) {
8785 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8786 }
8787 return false;
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
8791 }
8792
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008793 /**
chen xub4baa772019-04-03 10:23:41 -07008794 * Get whether making changes to modem configurations will trigger reboot.
8795 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008796 */
8797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008798 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8799 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008801 mApp, subId, callingPackage, callingFeatureId,
8802 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008803 return false;
8804 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008805 final long identity = Binder.clearCallingIdentity();
8806 try {
8807 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 }
8812
Nathan Harold29f5f052019-02-15 13:41:57 -08008813 private void updateModemStateMetrics() {
8814 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8815 // TODO: check the state for each modem if the api is ready.
8816 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8817 }
8818
Pengquan Meng3889a572019-01-23 11:16:29 -08008819 @Override
8820 public int[] getSlotsMapping() {
8821 enforceReadPrivilegedPermission("getSlotsMapping");
8822
8823 final long identity = Binder.clearCallingIdentity();
8824 try {
8825 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8826 // All logical slots should have a mapping to a physical slot.
8827 int[] logicalSlotsMapping = new int[phoneCount];
8828 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8829 for (int i = 0; i < slotInfos.length; i++) {
8830 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8831 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8832 }
8833 }
8834 return logicalSlotsMapping;
8835 } finally {
8836 Binder.restoreCallingIdentity(identity);
8837 }
8838 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008839
8840 /**
8841 * Get the IRadio HAL Version
8842 */
8843 @Override
8844 public int getRadioHalVersion() {
8845 Phone phone = getDefaultPhone();
8846 if (phone == null) return -1;
8847 HalVersion hv = phone.getHalVersion();
8848 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8849 return hv.major * 100 + hv.minor;
8850 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008851
8852 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008853 * Get the current calling package name.
8854 * @return the current calling package name
8855 */
8856 @Override
8857 public String getCurrentPackageName() {
8858 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8859 }
8860
8861 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008862 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8863 * corresponding network requests on a subId.
8864 *
8865 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008866 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008867 * 2) APN is un-metered for this subscription, or
8868 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008869 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008870 *
8871 * @return whether data is allowed for a apn type.
8872 *
8873 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008874 */
8875 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008876 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008877 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8878 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008879
8880 // Now that all security checks passes, perform the operation as ourselves.
8881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 Phone phone = getPhone(subId);
8884 if (phone == null) return false;
8885
Jack Yu41407ee2019-05-13 16:54:09 -07008886 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008887 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
8892
8893 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008894 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008895 enforceReadPrivilegedPermission("isApnMetered");
8896
8897 // Now that all security checks passes, perform the operation as ourselves.
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 Phone phone = getPhone(subId);
8901 if (phone == null) return true; // By default return true.
8902
Jack Yu41407ee2019-05-13 16:54:09 -07008903 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008904 } finally {
8905 Binder.restoreCallingIdentity(identity);
8906 }
8907 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008908
8909 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008910 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8911 int subscriptionId, IBooleanConsumer resultCallback) {
8912 enforceModifyPermission();
8913 long token = Binder.clearCallingIdentity();
8914 try {
8915 Phone phone = getPhone(subscriptionId);
8916 if (phone == null) {
8917 try {
8918 if (resultCallback != null) {
8919 resultCallback.accept(false);
8920 }
8921 } catch (RemoteException e) {
8922 // ignore
8923 }
8924 return;
8925 }
8926 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8927 Pair.create(specifiers, (x) -> {
8928 try {
8929 if (resultCallback != null) {
8930 resultCallback.accept(x);
8931 }
8932 } catch (RemoteException e) {
8933 // ignore
8934 }
8935 });
8936 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8937 } finally {
8938 Binder.restoreCallingIdentity(token);
8939 }
8940 }
8941
8942 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08008943 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8944 TelephonyPermissions
8945 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8946 mApp, subId, "getSystemSelectionChannels");
8947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 List<RadioAccessSpecifier> specifiers =
8951 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8952 null, subId, workSource);
8953 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8954 return specifiers;
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
8958 }
8959
8960 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008961 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008962 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008963 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8964 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8965 if (iccRecords == null) {
8966 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8967 return false;
8968 }
8969 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8970 }
8971
8972 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008973 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8974 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008975 if (callingPackage == null) {
8976 callingPackage = getCurrentPackageName();
8977 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008978 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8979 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008980 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8981 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008982 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8983 }
8984 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8985 Intent intent = new Intent();
8986 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8987 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8988 // Bring up choose default SMS subscription dialog right now
8989 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8990 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8991 mApp.startActivity(intent);
8992 }
chen xud5ca2d52019-05-28 15:20:57 -07008993
8994 @Override
8995 public String getMmsUAProfUrl(int subId) {
8996 //TODO investigate if this API should require proper permission check in R b/133791609
8997 final long identity = Binder.clearCallingIdentity();
8998 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008999 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9000 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9001 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9002 return carrierUAProfUrl;
9003 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009004 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9005 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009006 } finally {
9007 Binder.restoreCallingIdentity(identity);
9008 }
9009 }
9010
9011 @Override
9012 public String getMmsUserAgent(int subId) {
9013 //TODO investigate if this API should require proper permission check in R b/133791609
9014 final long identity = Binder.clearCallingIdentity();
9015 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009016 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9017 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9018 if (!TextUtils.isEmpty(carrierUserAgent)) {
9019 return carrierUserAgent;
9020 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009021 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9022 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
Jack Yub07d4972019-05-28 16:12:25 -07009027
9028 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009029 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9030 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009031
Jack Yub07d4972019-05-28 16:12:25 -07009032 final long identity = Binder.clearCallingIdentity();
9033 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009034 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009035 if (phone == null) return false;
9036
Hall Liua62f5da2020-09-25 10:42:19 -07009037 switch (policy) {
9038 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9039 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9040 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9041 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9042 default:
9043 throw new IllegalArgumentException(policy + " is not a valid policy");
9044 }
Jack Yub07d4972019-05-28 16:12:25 -07009045 } finally {
9046 Binder.restoreCallingIdentity(identity);
9047 }
9048 }
9049
9050 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009051 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9052 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009053 enforceModifyPermission();
9054
changbettyd5c246e2019-12-24 15:40:37 +08009055 final long identity = Binder.clearCallingIdentity();
9056 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009057 Phone phone = getPhone(subscriptionId);
9058 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009059
Hall Liua62f5da2020-09-25 10:42:19 -07009060 switch (policy) {
9061 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9062 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9063 break;
9064 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9065 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9066 break;
9067 default:
9068 throw new IllegalArgumentException(policy + " is not a valid policy");
9069 }
changbettyd5c246e2019-12-24 15:40:37 +08009070 } finally {
9071 Binder.restoreCallingIdentity(identity);
9072 }
9073 }
9074
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009075 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009076 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009077 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9078 * otherwise.
9079 */
9080 @Override
9081 public void setCepEnabled(boolean isCepEnabled) {
9082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9083
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
9086 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9087 for (Phone phone : PhoneFactory.getPhones()) {
9088 Phone defaultPhone = phone.getImsPhone();
9089 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9090 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9091 ImsPhoneCallTracker imsPhoneCallTracker =
9092 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9093 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9094 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9095 + imsPhone.getMsisdn());
9096 }
9097 }
9098 } finally {
9099 Binder.restoreCallingIdentity(identity);
9100 }
9101 }
allenwtsu46dcc572020-01-08 18:24:03 +08009102
9103 /**
9104 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9105 *
9106 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9107 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9108 * before being read.
9109 */
9110 @Override
9111 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9112 isCompressed) {
9113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9114 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009115 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9116 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9117 }
9118 if (!isImsAvailableOnDevice()) {
9119 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9120 "IMS not available on device.");
9121 }
9122
9123 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009124 try {
Hui Wang761a6682020-10-31 05:12:53 +00009125 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9126 } finally {
9127 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009128 }
9129 }
zoey chene02881a2019-12-30 16:11:23 +08009130
9131 @Override
9132 public boolean isIccLockEnabled(int subId) {
9133 enforceReadPrivilegedPermission("isIccLockEnabled");
9134
9135 // Now that all security checks passes, perform the operation as ourselves.
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 Phone phone = getPhone(subId);
9139 if (phone != null && phone.getIccCard() != null) {
9140 return phone.getIccCard().getIccLockEnabled();
9141 } else {
9142 return false;
9143 }
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
9146 }
9147 }
9148
9149 /**
9150 * Set the ICC pin lock enabled or disabled.
9151 *
9152 * @return an integer representing the status of IccLock enabled or disabled in the following
9153 * three cases:
9154 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9155 * successfully.
9156 * - Positive number and zero for remaining password attempts.
9157 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9158 *
9159 */
9160 @Override
9161 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9162 enforceModifyPermission();
9163
9164 Phone phone = getPhone(subId);
9165 if (phone == null) {
9166 return 0;
9167 }
9168 // Now that all security checks passes, perform the operation as ourselves.
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9172 new Pair<Boolean, String>(enabled, password), phone, null);
9173 return attemptsRemaining;
9174
9175 } catch (Exception e) {
9176 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 return 0;
9181 }
9182
9183 /**
9184 * Change the ICC password used in ICC pin lock.
9185 *
9186 * @return an integer representing the status of IccLock changed in the following three cases:
9187 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9188 * - Positive number and zero for remaining password attempts.
9189 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9190 *
9191 */
9192 @Override
9193 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9194 enforceModifyPermission();
9195
9196 Phone phone = getPhone(subId);
9197 if (phone == null) {
9198 return 0;
9199 }
9200 // Now that all security checks passes, perform the operation as ourselves.
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9204 new Pair<String, String>(oldPassword, newPassword), phone, null);
9205 return attemptsRemaining;
9206
9207 } catch (Exception e) {
9208 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 return 0;
9213 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009214
9215 /**
9216 * Request for receiving user activity notification
9217 */
9218 @Override
9219 public void requestUserActivityNotification() {
9220 if (!mNotifyUserActivity.get()
9221 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9222 mNotifyUserActivity.set(true);
9223 }
9224 }
9225
9226 /**
9227 * Called when userActivity is signalled in the power manager.
9228 * This is safe to call from any thread, with any window manager locks held or not.
9229 */
9230 @Override
9231 public void userActivity() {
9232 // ***************************************
9233 // * Inherited from PhoneWindowManager *
9234 // ***************************************
9235 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9236 // WITH ITS LOCKS HELD.
9237 //
9238 // This code must be VERY careful about the locks
9239 // it acquires.
9240 // In fact, the current code acquires way too many,
9241 // and probably has lurking deadlocks.
9242
9243 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9244 throw new SecurityException("Only the OS may call notifyUserActivity()");
9245 }
9246
9247 if (mNotifyUserActivity.getAndSet(false)) {
9248 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9249 USER_ACTIVITY_NOTIFICATION_DELAY);
9250 }
9251 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009252
9253 @Override
9254 public boolean canConnectTo5GInDsdsMode() {
9255 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9256 }
Jack Yud10cdd42020-09-28 20:28:01 -07009257
9258 @Override
9259 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9260 String callingFeatureId) {
9261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9262 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9263 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9264 }
9265
9266 Phone phone = getPhone(subId);
9267 if (phone == null) {
9268 throw new RuntimeException("phone is not available");
9269 }
9270 // Now that all security checks passes, perform the operation as ourselves.
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 return phone.getEquivalentHomePlmns();
9274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 }
Daniel Bright59e67312020-11-13 11:49:37 -08009278
9279 @Override
9280 public boolean isRadioInterfaceCapabilitySupported(
9281 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9282 RadioInterfaceCapabilities radioInterfaceCapabilities =
9283 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9284 if (radioInterfaceCapabilities == null) {
9285 throw new RuntimeException("radio interface capabilities are not available");
9286 } else {
9287 return radioInterfaceCapabilities.isSupported(capability);
9288 }
9289 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009290
Hui Wang641e81c2020-10-12 12:14:23 -07009291 @Override
9292 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9293 UaSecurityProtocolIdentifier securityProtocol,
9294 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9295 throws RemoteException {
9296 enforceModifyPermission();
9297 if (DBG) {
9298 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9299 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9300 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9301 }
9302
9303 if (!SubscriptionManager.isValidSubscriptionId(subId)
9304 || appType < TelephonyManager.APPTYPE_UNKNOWN
9305 || appType > TelephonyManager.APPTYPE_ISIM
9306 || nafUrl == null || securityProtocol == null || callback == null) {
9307 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9308 if (callback != null) {
9309 try {
9310 callback.onAuthenticationFailure(
9311 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9312 } catch (RemoteException exception) {
9313 log("Fail to notify onAuthenticationFailure due to " + exception);
9314 }
9315 return;
9316 }
9317 }
9318
9319 final long token = Binder.clearCallingIdentity();
9320 try {
9321 getGbaManager(subId).bootstrapAuthenticationRequest(
9322 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9323 forceBootStrapping, callback));
9324 } finally {
9325 Binder.restoreCallingIdentity(token);
9326 }
9327 }
9328
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009329 /**
9330 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9331 * requested radio power state will actually be set. See {@link
9332 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9333 *
9334 * @param subId the subscription ID of the phone requesting to set the radio power state.
9335 * @param enable {@code true} if trying to turn radio on.
9336 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9337 * false}.
9338 */
9339 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9340 Phone phone = getPhone(subId);
9341 if (phone != null) {
9342 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9343 return true;
9344 }
9345 return false;
9346 }
9347
9348 private int handleDataThrottlingRequest(int subId,
9349 DataThrottlingRequest dataThrottlingRequest) {
9350 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9351 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9352 if (!setRadioPowerForThermal(subId, true)) {
9353 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9354 }
9355
9356 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9357
9358 int thermalMitigationResult =
9359 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9360 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9361 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9362 }
9363 return thermalMitigationResult;
9364 }
9365
9366 /**
9367 * Thermal mitigation request to control functionalities at modem.
9368 *
9369 * @param subId the id of the subscription.
9370 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9371 *
9372 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9373 */
9374 @Override
9375 @ThermalMitigationResult
9376 public int sendThermalMitigationRequest(
9377 int subId,
9378 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9379 enforceModifyPermission();
9380
9381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9382 final long identity = Binder.clearCallingIdentity();
9383
9384 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9385 try {
9386 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9387 switch (thermalMitigationAction) {
9388 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9389 thermalMitigationResult =
9390 handleDataThrottlingRequest(subId,
9391 thermalMitigationRequest.getDataThrottlingRequest());
9392 break;
9393 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9394 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9395 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9396 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9397 }
9398
9399 // Ensure that radio is on. If not able to power on due to phone being
9400 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9401 if (!setRadioPowerForThermal(subId, true)) {
9402 thermalMitigationResult =
9403 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9404 break;
9405 }
9406
9407 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9408 false);
9409 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9410 break;
9411 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9412 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9413 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9414 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9415 }
9416
9417 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9418 if (registry != null) {
9419 TelephonyConnectionService service =
9420 registry.getTelephonyConnectionService();
9421 Phone phone = getPhone(subId);
9422 if (phone == null) {
9423 thermalMitigationResult =
9424 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9425 break;
9426 }
9427
9428 if (PhoneConstantConversions.convertCallState(phone.getState())
9429 != TelephonyManager.CALL_STATE_IDLE
9430 || phone.isInEmergencySmsMode() || phone.isInEcm()
9431 || (service != null && service.isEmergencyCallPending())) {
9432 String errorMessage = "Phone state is not valid. call state = "
9433 + PhoneConstantConversions.convertCallState(phone.getState())
9434 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9435 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9436 errorMessage += service == null
9437 ? " TelephonyConnectionService is null"
9438 : " isEmergencyCallPending = "
9439 + service.isEmergencyCallPending();
9440 Log.e(LOG_TAG, errorMessage);
9441 thermalMitigationResult =
9442 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9443 break;
9444 }
9445 } else {
9446 thermalMitigationResult =
9447 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9448 break;
9449 }
9450
9451 // Turn radio off. If not able to power off due to phone being unavailable,
9452 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9453 if (!setRadioPowerForThermal(subId, false)) {
9454 thermalMitigationResult =
9455 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9456 break;
9457 }
9458 thermalMitigationResult =
9459 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9460 break;
9461 default:
9462 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9463 + "not exist. Requested action: " + thermalMitigationAction);
9464 }
9465 } catch (IllegalArgumentException e) {
9466 throw e;
9467 } catch (Exception e) {
9468 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9469 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9470 } finally {
9471 Binder.restoreCallingIdentity(identity);
9472 }
9473
9474 if (DBG) {
9475 log("thermalMitigationRequest returning with thermalMitigationResult: "
9476 + thermalMitigationResult);
9477 }
9478
9479 return thermalMitigationResult;
9480 }
Hui Wang641e81c2020-10-12 12:14:23 -07009481
9482 /**
9483 * Set the GbaService Package Name that Telephony will bind to.
9484 *
9485 * @param subId The sim that the GbaService is associated with.
9486 * @param packageName The name of the package to be replaced with.
9487 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9488 */
9489 @Override
9490 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9491 enforceModifyPermission();
9492
9493 final long identity = Binder.clearCallingIdentity();
9494 try {
9495 return getGbaManager(subId).overrideServicePackage(packageName);
9496 } finally {
9497 Binder.restoreCallingIdentity(identity);
9498 }
9499 }
9500
9501 /**
9502 * Return the package name of the currently bound GbaService.
9503 *
9504 * @param subId The sim that the GbaService is associated with.
9505 * @return the package name of the GbaService configuration, null if GBA is not supported.
9506 */
9507 @Override
9508 public String getBoundGbaService(int subId) {
9509 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9510
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
9513 return getGbaManager(subId).getServicePackage();
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
9518
9519 /**
9520 * Set the release time for telephony to unbind GbaService.
9521 *
9522 * @param subId The sim that the GbaService is associated with.
9523 * @param interval The release time to unbind GbaService by millisecond.
9524 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9525 */
9526 @Override
9527 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9528 enforceModifyPermission();
9529
9530 final long identity = Binder.clearCallingIdentity();
9531 try {
9532 return getGbaManager(subId).overrideReleaseTime(interval);
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 /**
9539 * Return the release time for telephony to unbind GbaService.
9540 *
9541 * @param subId The sim that the GbaService is associated with.
9542 * @return The release time to unbind GbaService by millisecond.
9543 */
9544 @Override
9545 public int getGbaReleaseTime(int subId) {
9546 enforceReadPrivilegedPermission("getGbaReleaseTime");
9547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 return getGbaManager(subId).getReleaseTime();
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
9556 private GbaManager getGbaManager(int subId) {
9557 GbaManager instance = GbaManager.getInstance(subId);
9558 if (instance == null) {
9559 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9560 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9561 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9562 }
9563 return instance;
9564 }
Hui Wang761a6682020-10-31 05:12:53 +00009565
9566 /**
9567 * indicate whether the device and the carrier can support
9568 * RCS VoLTE single registration.
9569 */
9570 @Override
9571 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9572 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9573
9574 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9575 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9576 }
9577
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
9580 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9581 if (rpm != null) {
9582 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9583 }
9584 return false;
9585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
9589
9590 /**
9591 * Register RCS provisioning callback.
9592 */
9593 @Override
9594 public void registerRcsProvisioningChangedCallback(int subId,
9595 IRcsConfigCallback callback) {
9596 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9597
9598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9599 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9600 }
9601 if (!isImsAvailableOnDevice()) {
9602 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9603 "IMS not available on device.");
9604 }
9605
9606 final long identity = Binder.clearCallingIdentity();
9607 try {
9608 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9609 .addRcsProvisioningCallbackForSubscription(callback, subId);
9610 } catch (ImsException e) {
9611 throw new ServiceSpecificException(e.getCode());
9612 } finally {
9613 Binder.restoreCallingIdentity(identity);
9614 }
9615 }
9616
9617 /**
9618 * Unregister RCS provisioning callback.
9619 */
9620 @Override
9621 public void unregisterRcsProvisioningChangedCallback(int subId,
9622 IRcsConfigCallback callback) {
9623 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9624
9625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9626 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9627 }
9628 if (!isImsAvailableOnDevice()) {
9629 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9630 "IMS not available on device.");
9631 }
9632
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
9635 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9636 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9637 } catch (ImsException e) {
9638 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9639 + "is inactive, ignoring unregister.");
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
9644
9645 /**
9646 * trigger RCS reconfiguration.
9647 */
9648 public void triggerRcsReconfiguration(int subId) {
9649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9650 mApp, subId, "triggerRcsReconfiguration");
9651
9652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9653 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9654 }
9655 if (!isImsAvailableOnDevice()) {
9656 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9657 "IMS not available on device.");
9658 }
9659
9660 final long identity = Binder.clearCallingIdentity();
9661 try {
9662 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9663 } finally {
9664 Binder.restoreCallingIdentity(identity);
9665 }
9666 }
9667
9668 /**
9669 * Provide the client configuration parameters of the RCS application.
9670 */
9671 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9673 mApp, subId, "setRcsClientConfiguration");
9674
9675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9676 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9677 }
9678 if (!isImsAvailableOnDevice()) {
9679 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9680 "IMS not available on device.");
9681 }
9682
9683 final long identity = Binder.clearCallingIdentity();
9684
9685 try {
9686 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9687 if (configBinder == null) {
9688 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9689 } else {
9690 configBinder.setRcsClientConfiguration(rcc);
9691 }
9692 } catch (RemoteException e) {
9693 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
9699 /**
9700 * Overrides the config of RCS VoLTE single registration enabled for the device.
9701 */
9702 @Override
9703 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9705 "setDeviceSingleRegistrationEnabledOverride");
9706 enforceModifyPermission();
9707
9708 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9709 : Boolean.parseBoolean(enabledStr);
9710 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9711 }
9712
9713 /**
9714 * Gets the config of RCS VoLTE single registration enabled for the device.
9715 */
9716 @Override
9717 public boolean getDeviceSingleRegistrationEnabled() {
9718 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9719 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9720 }
9721
9722 /**
9723 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9724 */
9725 @Override
9726 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9728 "setCarrierSingleRegistrationEnabledOverride");
9729 enforceModifyPermission();
9730
9731 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9732 : Boolean.parseBoolean(enabledStr);
9733 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9734 subId, enabled);
9735 }
9736
9737 /**
9738 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9739 */
9740 @Override
9741 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9742 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9743 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009745}