blob: 29285546b219fd147ab9383b4c7fc6a508f3705a [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;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080068import android.telephony.CallForwardingInfo;
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;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080092import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800114import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800116import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800121import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122
Andrew Lee312e8172014-10-23 17:01:36 -0700123import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800124import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800125import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700127import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700128import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800129import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800132import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800134import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800135import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700136import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800137import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800139import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700141import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700144import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800145import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700146import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700147import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700148import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700149import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700150import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700152import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800154import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
314 private static final String ACTION_USER_ACTIVITY_NOTIFICATION =
315 "android.intent.action.USER_ACTIVITY_NOTIFICATION";
316 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
317
Derek Tan97ebb422014-09-05 16:55:38 -0700318 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
319 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800320 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800321 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700322
Michelecea4cf22018-12-21 15:00:11 -0800323 // String to store multi SIM allowed
324 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
325
Derek Tan740e1672017-06-27 14:56:27 -0700326 // The AID of ISD-R.
327 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
328
yinxub1bed742017-04-17 11:45:04 -0700329 private NetworkScanRequestTracker mNetworkScanRequestTracker;
330
David Kelly5e06a7f2018-03-12 14:10:59 +0000331 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
332 private static final int MANUFACTURER_CODE_LENGTH = 8;
333
Derek Tan89e89d42014-07-08 17:00:10 -0700334 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700335 * Experiment flag to enable erase modem config on reset network, default value is false
336 */
337 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
338 "reset_network_erase_modem_config_enabled";
339
340 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class IccAPDUArgument {
344 public int channel, cla, command, p1, p2, p3;
345 public String data;
346
347 public IccAPDUArgument(int channel, int cla, int command,
348 int p1, int p2, int p3, String data) {
349 this.channel = channel;
350 this.cla = cla;
351 this.command = command;
352 this.p1 = p1;
353 this.p2 = p2;
354 this.p3 = p3;
355 this.data = data;
356 }
357 }
358
359 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700360 * A request object to use for transmitting data to an ICC.
361 */
362 private static final class ManualNetworkSelectionArgument {
363 public OperatorInfo operatorInfo;
364 public boolean persistSelection;
365
366 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
367 this.operatorInfo = operatorInfo;
368 this.persistSelection = persistSelection;
369 }
370 }
371
372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
374 * request after sending. The main thread will notify the request when it is complete.
375 */
376 private static final class MainThreadRequest {
377 /** The argument to use for the request */
378 public Object argument;
379 /** The result of the request that is run on the main thread */
380 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800381 // The subscriber id that this request applies to. Defaults to
382 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
383 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 // In cases where subId is unavailable, the caller needs to specify the phone.
386 public Phone phone;
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 public WorkSource workSource;
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 public MainThreadRequest(Object argument) {
391 this.argument = argument;
392 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
395 this.argument = argument;
396 if (phone != null) {
397 this.phone = phone;
398 }
399 this.workSource = workSource;
400 }
401
vagdeviaf9a5b92018-08-15 16:01:53 -0700402 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800403 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 if (subId != null) {
405 this.subId = subId;
406 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800411 private static final class IncomingThirdPartyCallArgs {
412 public final ComponentName component;
413 public final String callId;
414 public final String callerDisplayName;
415
416 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
417 String callerDisplayName) {
418 this.component = component;
419 this.callId = callId;
420 this.callerDisplayName = callerDisplayName;
421 }
422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /**
425 * A handler that processes messages on the main thread in the phone process. Since many
426 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
427 * inbound binder threads to the main thread in the phone process. The Binder thread
428 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
429 * on, which will be notified when the operation completes and will contain the result of the
430 * request.
431 *
432 * <p>If a MainThreadRequest object is provided in the msg.obj field,
433 * note that request.result must be set to something non-null for the calling thread to
434 * unblock.
435 */
436 private final class MainThreadHandler extends Handler {
437 @Override
438 public void handleMessage(Message msg) {
439 MainThreadRequest request;
440 Message onCompleted;
441 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800444 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
446 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 case CMD_HANDLE_USSD_REQUEST: {
448 request = (MainThreadRequest) msg.obj;
449 final Phone phone = getPhoneFromRequest(request);
450 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
451 String ussdRequest = ussdObject.first;
452 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 if (!isUssdApiAllowed(request.subId)) {
455 // Carrier does not support use of this API, return failure.
456 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
457 UssdResponse response = new UssdResponse(ussdRequest, null);
458 Bundle returnData = new Bundle();
459 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
460 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 request.result = true;
463 notifyRequester(request);
464 return;
465 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 try {
468 request.result = phone != null
469 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
470 } catch (CallStateException cse) {
471 request.result = false;
472 }
473 // Wake up the requesting thread
474 notifyRequester(request);
475 break;
pkanwar32d516d2016-10-14 19:37:38 -0700476 }
477
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 final Phone phone = getPhoneFromRequest(request);
481 request.result = phone != null ?
482 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
483 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduLogicalChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
499 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 iccArgument.channel, iccArgument.cla, iccArgument.command,
502 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800516 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800518 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 } else {
520 loge("iccTransmitApduLogicalChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 break;
525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduBasicChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
536 request);
537 uiccCard.iccTransmitApduBasicChannel(
538 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
539 iccArgument.p3, iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduBasicChannel: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("iccTransmitApduBasicChannel: CommandException: " +
554 ar.exception);
555 } else {
556 loge("iccTransmitApduBasicChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
562 case CMD_EXCHANGE_SIM_IO:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccExchangeSimIO: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
572 request);
573 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
574 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
575 iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_EXCHANGE_SIM_IO_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6f, 0, (byte[])null);
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 break;
589
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 case CMD_SEND_ENVELOPE:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("sendEnvelopeWithStatus: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
599 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
600 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
603 case EVENT_SEND_ENVELOPE_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("sendEnvelopeWithStatus: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("sendEnvelopeWithStatus: CommandException: " +
614 ar.exception);
615 } else {
616 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
617 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 break;
621
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 case CMD_OPEN_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800628 request.result = new IccOpenLogicalChannelResponse(-1,
629 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
634 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_OPEN_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 int[] result = (int[]) ar.result;
644 int channelId = result[0];
645 byte[] selectResponse = null;
646 if (result.length > 1) {
647 selectResponse = new byte[result.length - 1];
648 for (int i = 1; i < result.length; ++i) {
649 selectResponse[i - 1] = (byte) result[i];
650 }
651 }
652 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 if (ar.result == null) {
656 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 if (ar.exception != null) {
659 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
660 }
661
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700663 if (ar.exception instanceof CommandException) {
664 CommandException.Error error =
665 ((CommandException) (ar.exception)).getCommandError();
666 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700668 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 }
672 openChannelResp = new IccOpenLogicalChannelResponse(
673 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700675 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case CMD_CLOSE_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900684 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
688 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800693 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
694 break;
695
696 case CMD_NV_READ_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 request.result = "";
710 if (ar.result == null) {
711 loge("nvReadItem: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("nvReadItem: CommandException: " +
714 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
Jake Hambye994d462014-02-03 13:10:13 -0800722 case CMD_NV_WRITE_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
725 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_ITEM_DONE:
731 handleNullReturnEvent(msg, "nvWriteItem");
732 break;
733
734 case CMD_NV_WRITE_CDMA_PRL:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_WRITE_CDMA_PRL_DONE:
741 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
742 break;
743
chen xu6dac5ab2018-10-26 17:39:23 -0700744 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800745 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case EVENT_RESET_MODEM_CONFIG_DONE:
751 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 case CMD_GET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // Integer
765 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800766 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800767 if (ar.result == null) {
768 loge("getPreferredNetworkType: Empty response");
769 } else if (ar.exception instanceof CommandException) {
770 loge("getPreferredNetworkType: CommandException: " +
771 ar.exception);
772 } else {
773 loge("getPreferredNetworkType: Unknown exception");
774 }
775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800777 break;
778
779 case CMD_SET_PREFERRED_NETWORK_TYPE:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
782 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700783 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800784 break;
785
786 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
787 handleNullReturnEvent(msg, "setPreferredNetworkType");
788 break;
789
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
791 request = (MainThreadRequest)msg.obj;
792 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000794 break;
795
796 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
797 ar = (AsyncResult)msg.obj;
798 request = (MainThreadRequest)ar.userObj;
799 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700800 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000801 break;
802
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800803 case CMD_SET_VOICEMAIL_NUMBER:
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
806 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800807 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
808 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800809 break;
810
811 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
812 handleNullReturnEvent(msg, "setVoicemailNumber");
813 break;
814
Stuart Scott54788802015-03-30 13:18:01 -0700815 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
818 request);
819 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
820 break;
821
822 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
823 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
824 break;
825
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 case CMD_PERFORM_NETWORK_SCAN:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
829 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
830 break;
831
Shuo Qian4a594052020-01-23 11:59:30 -0800832 case CMD_GET_CALL_FORWARDING:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
835 int callForwardingReason = (Integer) request.argument;
836 getPhoneFromRequest(request).getCallForwardingOption(
837 callForwardingReason, onCompleted);
838 break;
839
840 case EVENT_GET_CALL_FORWARDING_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 CallForwardingInfo callForwardingInfo = null;
844 if (ar.exception == null && ar.result != null) {
845 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
846 for (CallForwardInfo callForwardInfo : callForwardInfos) {
847 // Service Class is a bit mask per 3gpp 27.007. Search for
848 // any service for voice call.
849 if ((callForwardInfo.serviceClass
850 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
851 callForwardingInfo = new CallForwardingInfo(
852 callForwardInfo.serviceClass, callForwardInfo.reason,
853 callForwardInfo.number,
854 callForwardInfo.timeSeconds);
855 break;
856 }
857 }
858 // Didn't find a call forward info for voice call.
859 if (callForwardingInfo == null) {
860 callForwardingInfo = new CallForwardingInfo(
861 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
862 0 /* reason */, null /* number */, 0 /* timeout */);
863 }
864 } else {
865 if (ar.result == null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
867 }
868 if (ar.exception != null) {
869 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
870 }
871 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
872 if (ar.exception instanceof CommandException) {
873 CommandException.Error error =
874 ((CommandException) (ar.exception)).getCommandError();
875 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
876 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
877 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
879 }
880 }
881 callForwardingInfo = new CallForwardingInfo(
882 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
883 }
884 request.result = callForwardingInfo;
885 notifyRequester(request);
886 break;
887
888 case CMD_SET_CALL_FORWARDING:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
891 CallForwardingInfo callForwardingInfoToSet =
892 (CallForwardingInfo) request.argument;
893 getPhoneFromRequest(request).setCallForwardingOption(
894 callForwardingInfoToSet.getStatus(),
895 callForwardingInfoToSet.getReason(),
896 callForwardingInfoToSet.getNumber(),
897 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
898 break;
899
900 case EVENT_SET_CALL_FORWARDING_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null) {
904 request.result = true;
905 } else {
906 request.result = false;
907 loge("setCallForwarding exception: " + ar.exception);
908 }
909 notifyRequester(request);
910 break;
911
912 case CMD_GET_CALL_WAITING:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
915 getPhoneFromRequest(request).getCallWaiting(onCompleted);
916 break;
917
918 case EVENT_GET_CALL_WAITING_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
922 if (ar.exception == null && ar.result != null) {
923 ArrayList<Integer> callForwardResults = (ArrayList<Integer>) ar.result;
924 // Service Class is a bit mask per 3gpp 27.007.
925 // Search for any service for voice call.
926 if ((callForwardResults.get(1)
927 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
928 callForwardingStatus = callForwardResults.get(0) == 0
929 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
930 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
931 } else {
932 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
933 }
934 } else {
935 if (ar.result == null) {
936 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
937 }
938 if (ar.exception != null) {
939 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
940 }
941 if (ar.exception instanceof CommandException) {
942 CommandException.Error error =
943 ((CommandException) (ar.exception)).getCommandError();
944 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
945 callForwardingStatus =
946 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
947 }
948 }
949 }
950 request.result = callForwardingStatus;
951 notifyRequester(request);
952 break;
953
954 case CMD_SET_CALL_WAITING:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
957 boolean isEnable = (Boolean) request.argument;
958 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
959 break;
960
961 case EVENT_SET_CALL_WAITING_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception == null) {
965 request.result = true;
966 } else {
967 request.result = false;
968 loge("setCallWaiting exception: " + ar.exception);
969 }
970 notifyRequester(request);
971 break;
972
Shishir Agrawal302c8692015-06-19 13:49:39 -0700973 case EVENT_PERFORM_NETWORK_SCAN_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 CellNetworkScanResult cellScanResult;
977 if (ar.exception == null && ar.result != null) {
978 cellScanResult = new CellNetworkScanResult(
979 CellNetworkScanResult.STATUS_SUCCESS,
980 (List<OperatorInfo>) ar.result);
981 } else {
982 if (ar.result == null) {
983 loge("getCellNetworkScanResults: Empty response");
984 }
985 if (ar.exception != null) {
986 loge("getCellNetworkScanResults: Exception: " + ar.exception);
987 }
988 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
994 } else if (error == CommandException.Error.GENERIC_FAILURE) {
995 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
996 }
997 }
998 cellScanResult = new CellNetworkScanResult(errorCode, null);
999 }
1000 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001001 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001002 break;
1003
1004 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1005 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001006 ManualNetworkSelectionArgument selArg =
1007 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001008 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1009 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001010 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1011 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001012 break;
1013
1014 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null) {
1018 request.result = true;
1019 } else {
1020 request.result = false;
1021 loge("setNetworkSelectionModeManual " + ar.exception);
1022 }
1023 notifyRequester(request);
1024 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001025 break;
1026
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001027 case CMD_GET_MODEM_ACTIVITY_INFO:
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001030 if (defaultPhone != null) {
1031 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1032 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001033 break;
1034
1035 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 if (ar.exception == null && ar.result != null) {
1039 request.result = ar.result;
1040 } else {
1041 if (ar.result == null) {
1042 loge("queryModemActivityInfo: Empty response");
1043 } else if (ar.exception instanceof CommandException) {
1044 loge("queryModemActivityInfo: CommandException: " +
1045 ar.exception);
1046 } else {
1047 loge("queryModemActivityInfo: Unknown exception");
1048 }
1049 }
Amit Mahajand4766222016-01-28 15:28:28 -08001050 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1051 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -08001052 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001053 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001054 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001055 break;
1056
Meng Wang1a7c35a2016-05-05 20:56:15 -07001057 case CMD_SET_ALLOWED_CARRIERS:
1058 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001059 CarrierRestrictionRules argument =
1060 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001061 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001062 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001063 break;
1064
1065 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null && ar.result != null) {
1069 request.result = ar.result;
1070 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001071 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1072 if (ar.exception instanceof CommandException) {
1073 loge("setAllowedCarriers: CommandException: " + ar.exception);
1074 CommandException.Error error =
1075 ((CommandException) (ar.exception)).getCommandError();
1076 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1077 request.result =
1078 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1079 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001080 } else {
1081 loge("setAllowedCarriers: Unknown exception");
1082 }
1083 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001084 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001085 break;
1086
1087 case CMD_GET_ALLOWED_CARRIERS:
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001090 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001091 break;
1092
1093 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null && ar.result != null) {
1097 request.result = ar.result;
1098 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001099 request.result = new IllegalStateException(
1100 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001101 if (ar.result == null) {
1102 loge("getAllowedCarriers: Empty response");
1103 } else if (ar.exception instanceof CommandException) {
1104 loge("getAllowedCarriers: CommandException: " +
1105 ar.exception);
1106 } else {
1107 loge("getAllowedCarriers: Unknown exception");
1108 }
1109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001111 break;
1112
Nathan Haroldb3014052017-01-25 15:57:32 -08001113 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null && ar.result != null) {
1117 request.result = ar.result;
1118 } else {
1119 request.result = new IllegalArgumentException(
1120 "Failed to retrieve Forbidden Plmns");
1121 if (ar.result == null) {
1122 loge("getForbiddenPlmns: Empty response");
1123 } else {
1124 loge("getForbiddenPlmns: Unknown exception");
1125 }
1126 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001127 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001128 break;
1129
1130 case CMD_GET_FORBIDDEN_PLMNS:
1131 request = (MainThreadRequest) msg.obj;
1132 uiccCard = getUiccCardFromRequest(request);
1133 if (uiccCard == null) {
1134 loge("getForbiddenPlmns() UiccCard is null");
1135 request.result = new IllegalArgumentException(
1136 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001137 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001138 break;
1139 }
1140 Integer appType = (Integer) request.argument;
1141 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1142 if (uiccApp == null) {
1143 loge("getForbiddenPlmns() no app with specified type -- "
1144 + appType);
1145 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001146 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001147 break;
1148 } else {
1149 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1150 + " specified type -- " + appType);
1151 }
1152 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1153 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1154 onCompleted);
1155 break;
1156
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001157 case CMD_SWITCH_SLOTS:
1158 request = (MainThreadRequest) msg.obj;
1159 int[] physicalSlots = (int[]) request.argument;
1160 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1161 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1162 break;
1163
1164 case EVENT_SWITCH_SLOTS_DONE:
1165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
1167 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
1169 break;
1170 case CMD_GET_NETWORK_SELECTION_MODE:
1171 request = (MainThreadRequest) msg.obj;
1172 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1173 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1174 break;
1175
1176 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1177 ar = (AsyncResult) msg.obj;
1178 request = (MainThreadRequest) ar.userObj;
1179 if (ar.exception != null) {
1180 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1181 } else {
1182 int mode = ((int[]) ar.result)[0];
1183 if (mode == 0) {
1184 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1185 } else {
1186 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1187 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001188 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001189 notifyRequester(request);
1190 break;
1191 case CMD_GET_CDMA_ROAMING_MODE:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1194 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1195 break;
1196 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
1199 if (ar.exception != null) {
1200 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1201 } else {
1202 request.result = ((int[]) ar.result)[0];
1203 }
1204 notifyRequester(request);
1205 break;
1206 case CMD_SET_CDMA_ROAMING_MODE:
1207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1209 int mode = (int) request.argument;
1210 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1211 break;
1212 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
1215 request.result = ar.exception == null;
1216 notifyRequester(request);
1217 break;
1218 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1221 int subscriptionMode = (int) request.argument;
1222 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1223 break;
1224 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
1227 request.result = ar.exception == null;
1228 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001229 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001230 case CMD_GET_ALL_CELL_INFO:
1231 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001232 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001233 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001234 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001235 case EVENT_GET_ALL_CELL_INFO_DONE:
1236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001238 // If a timeout occurs, the response will be null
1239 request.result = (ar.exception == null && ar.result != null)
1240 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001245 case CMD_REQUEST_CELL_INFO_UPDATE:
1246 request = (MainThreadRequest) msg.obj;
1247 request.phone.requestCellInfoUpdate(request.workSource,
1248 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1249 break;
1250 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1251 ar = (AsyncResult) msg.obj;
1252 request = (MainThreadRequest) ar.userObj;
1253 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1254 try {
1255 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001256 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001257 cb.onError(
1258 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1259 ar.exception.getClass().getName(),
1260 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001261 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001262 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001263 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001264 } else {
1265 // use the result as returned
1266 cb.onCellInfo((List<CellInfo>) ar.result);
1267 }
1268 } catch (RemoteException re) {
1269 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1270 }
1271 break;
1272 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001273 request = (MainThreadRequest) msg.obj;
1274 WorkSource ws = (WorkSource) request.argument;
1275 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001276 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001277 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001278 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001279 ar = (AsyncResult) msg.obj;
1280 request = (MainThreadRequest) ar.userObj;
1281 if (ar.exception == null) {
1282 request.result = ar.result;
1283 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001284 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001285 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001286 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001287 }
1288
1289 synchronized (request) {
1290 request.notifyAll();
1291 }
1292 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001293 case CMD_MODEM_REBOOT:
1294 request = (MainThreadRequest) msg.obj;
1295 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001296 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001297 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001298 case EVENT_CMD_MODEM_REBOOT_DONE:
1299 handleNullReturnEvent(msg, "rebootModem");
1300 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001301 case CMD_REQUEST_ENABLE_MODEM:
1302 request = (MainThreadRequest) msg.obj;
1303 boolean enable = (boolean) request.argument;
1304 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001305 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001306 PhoneConfigurationManager.getInstance()
1307 .enablePhone(request.phone, enable, onCompleted);
1308 break;
1309 case EVENT_ENABLE_MODEM_DONE:
1310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001313 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001314 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001315 if ((boolean) request.result) {
1316 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1317 updateModemStateMetrics();
1318 } else {
1319 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1320 + ar.exception);
1321 }
1322 notifyRequester(request);
1323 break;
1324 case CMD_GET_MODEM_STATUS:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1327 PhoneConfigurationManager.getInstance()
1328 .getPhoneStatusFromModem(request.phone, onCompleted);
1329 break;
1330 case EVENT_GET_MODEM_STATUS_DONE:
1331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
1333 int id = request.phone.getPhoneId();
1334 if (ar.exception == null && ar.result != null) {
1335 request.result = ar.result;
1336 //update the cache as modem status has changed
1337 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1338 (boolean) request.result);
1339 } else {
1340 // Return true if modem status cannot be retrieved. For most cases,
1341 // modem status is on. And for older version modems, GET_MODEM_STATUS
1342 // and disable modem are not supported. Modem is always on.
1343 // TODO: this should be fixed in R to support a third
1344 // status UNKNOWN b/131631629
1345 request.result = true;
1346 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1347 + ar.exception);
1348 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001349 notifyRequester(request);
1350 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001351 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1352 request = (MainThreadRequest) msg.obj;
1353 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1354 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1355 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1356 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1357 break;
1358 }
1359 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1360 ar = (AsyncResult) msg.obj;
1361 request = (MainThreadRequest) ar.userObj;
1362 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1363 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1364 args.second.accept(ar.exception == null);
1365 notifyRequester(request);
1366 break;
1367 }
yincheng zhao2737e882019-09-06 17:06:54 -07001368 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1369 ar = (AsyncResult) msg.obj;
1370 request = (MainThreadRequest) ar.userObj;
1371 if (ar.exception == null && ar.result != null) {
1372 request.result = ar.result;
1373 } else {
1374 request.result = -1;
1375 loge("Failed to set Forbidden Plmns");
1376 if (ar.result == null) {
1377 loge("setForbidenPlmns: Empty response");
1378 } else if (ar.exception != null) {
1379 loge("setForbiddenPlmns: Exception: " + ar.exception);
1380 request.result = -1;
1381 } else {
1382 loge("setForbiddenPlmns: Unknown exception");
1383 }
1384 }
1385 notifyRequester(request);
1386 break;
1387 case CMD_SET_FORBIDDEN_PLMNS:
1388 request = (MainThreadRequest) msg.obj;
1389 uiccCard = getUiccCardFromRequest(request);
1390 if (uiccCard == null) {
1391 loge("setForbiddenPlmns: UiccCard is null");
1392 request.result = -1;
1393 notifyRequester(request);
1394 break;
1395 }
1396 Pair<Integer, List<String>> setFplmnsArgs =
1397 (Pair<Integer, List<String>>) request.argument;
1398 appType = setFplmnsArgs.first;
1399 List<String> fplmns = setFplmnsArgs.second;
1400 uiccApp = uiccCard.getApplicationByType(appType);
1401 if (uiccApp == null) {
1402 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1403 request.result = -1;
1404 loge("Failed to get UICC App");
1405 notifyRequester(request);
1406 } else {
1407 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1408 ((SIMRecords) uiccApp.getIccRecords())
1409 .setForbiddenPlmns(onCompleted, fplmns);
1410 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001411 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001412 case CMD_ERASE_MODEM_CONFIG:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1415 defaultPhone.eraseModemConfig(onCompleted);
1416 break;
1417 case EVENT_ERASE_MODEM_CONFIG_DONE:
1418 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001419 break;
zoey chene02881a2019-12-30 16:11:23 +08001420
1421 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1424 Pair<String, String> changed = (Pair<String, String>) request.argument;
1425 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1426 changed.first, changed.second, onCompleted);
1427 break;
1428 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 if (ar.exception == null) {
1432 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1433 } else {
1434 request.result = msg.arg1;
1435 }
1436 notifyRequester(request);
1437 break;
1438
1439 case CMD_SET_ICC_LOCK_ENABLED:
1440 request = (MainThreadRequest) msg.obj;
1441 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1442 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1443 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1444 enabled.first, enabled.second, onCompleted);
1445 break;
1446 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null) {
1450 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1451 } else {
1452 request.result = msg.arg1;
1453 }
1454 notifyRequester(request);
1455 break;
1456
Peter Wangdafb9ac2020-01-15 14:13:38 -08001457 case MSG_NOTIFY_USER_ACTIVITY:
1458 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
1459 Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION);
1460 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1461 getDefaultPhone().getContext().sendBroadcastAsUser(
1462 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1463 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 default:
1465 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1466 break;
1467 }
1468 }
Jake Hambye994d462014-02-03 13:10:13 -08001469
Pengquan Menga1bb6272018-09-06 09:59:22 -07001470 private void notifyRequester(MainThreadRequest request) {
1471 synchronized (request) {
1472 request.notifyAll();
1473 }
1474 }
1475
Jake Hambye994d462014-02-03 13:10:13 -08001476 private void handleNullReturnEvent(Message msg, String command) {
1477 AsyncResult ar = (AsyncResult) msg.obj;
1478 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1479 if (ar.exception == null) {
1480 request.result = true;
1481 } else {
1482 request.result = false;
1483 if (ar.exception instanceof CommandException) {
1484 loge(command + ": CommandException: " + ar.exception);
1485 } else {
1486 loge(command + ": Unknown exception");
1487 }
1488 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001489 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 }
1492
1493 /**
1494 * Posts the specified command to be executed on the main thread,
1495 * waits for the request to complete, and returns the result.
1496 * @see #sendRequestAsync
1497 */
1498 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001499 return sendRequest(
1500 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001501 }
1502
1503 /**
1504 * Posts the specified command to be executed on the main thread,
1505 * waits for the request to complete, and returns the result.
1506 * @see #sendRequestAsync
1507 */
1508 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1509 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001510 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001511 }
1512
1513 /**
1514 * Posts the specified command to be executed on the main thread,
1515 * waits for the request to complete, and returns the result.
1516 * @see #sendRequestAsync
1517 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001518 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001519 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001520 }
1521
1522 /**
1523 * Posts the specified command to be executed on the main thread,
1524 * waits for the request to complete, and returns the result.
1525 * @see #sendRequestAsync
1526 */
Nathan Harold92bed182018-10-12 18:16:49 -07001527 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1528 return sendRequest(command, argument, subId, null, workSource);
1529 }
1530
1531 /**
1532 * Posts the specified command to be executed on the main thread,
1533 * waits for the request to complete, and returns the result.
1534 * @see #sendRequestAsync
1535 */
1536 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1537 return sendRequest(
1538 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1539 }
1540
1541 /**
1542 * Posts the specified command to be executed on the main thread,
1543 * waits for the request to complete, and returns the result.
1544 * @see #sendRequestAsync
1545 */
1546 private Object sendRequest(
1547 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1549 throw new RuntimeException("This method will deadlock if called from the main thread.");
1550 }
1551
Nathan Harold92bed182018-10-12 18:16:49 -07001552 MainThreadRequest request = null;
1553 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1554 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1555 } else if (phone != null) {
1556 request = new MainThreadRequest(argument, phone, workSource);
1557 } else {
1558 request = new MainThreadRequest(argument, subId, workSource);
1559 }
1560
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 Message msg = mMainThreadHandler.obtainMessage(command, request);
1562 msg.sendToTarget();
1563
1564 // Wait for the request to complete
1565 synchronized (request) {
1566 while (request.result == null) {
1567 try {
1568 request.wait();
1569 } catch (InterruptedException e) {
1570 // Do nothing, go back and wait until the request is complete
1571 }
1572 }
1573 }
1574 return request.result;
1575 }
1576
1577 /**
1578 * Asynchronous ("fire and forget") version of sendRequest():
1579 * Posts the specified command to be executed on the main thread, and
1580 * returns immediately.
1581 * @see #sendRequest
1582 */
1583 private void sendRequestAsync(int command) {
1584 mMainThreadHandler.sendEmptyMessage(command);
1585 }
1586
1587 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001588 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001589 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001590 */
1591 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001592 sendRequestAsync(command, argument, null, null);
1593 }
1594
1595 /**
1596 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1597 * @see {@link #sendRequest(int,Object)}
1598 */
1599 private void sendRequestAsync(
1600 int command, Object argument, Phone phone, WorkSource workSource) {
1601 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001602 Message msg = mMainThreadHandler.obtainMessage(command, request);
1603 msg.sendToTarget();
1604 }
1605
1606 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 * Initialize the singleton PhoneInterfaceManager instance.
1608 * This is only done once, at startup, from PhoneApp.onCreate().
1609 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001610 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 synchronized (PhoneInterfaceManager.class) {
1612 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001613 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 } else {
1615 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1616 }
1617 return sInstance;
1618 }
1619 }
1620
1621 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001622 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001625 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001626 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1628 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001629 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001630 mTelephonySharedPreferences =
1631 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001632 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001633 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001634
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 publish();
1636 }
1637
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001638 private Phone getDefaultPhone() {
1639 Phone thePhone = getPhone(getDefaultSubscription());
1640 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1641 }
1642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 private void publish() {
1644 if (DBG) log("publish: " + this);
1645
Peter Wangc035ce42020-01-08 21:00:22 -08001646 TelephonyFrameworkInitializer
1647 .getTelephonyServiceManager()
1648 .getTelephonyServiceRegisterer()
1649 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
Stuart Scott584921c2015-01-15 17:10:34 -08001652 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001653 if (request.phone != null) {
1654 return request.phone;
1655 } else {
1656 return getPhoneFromSubId(request.subId);
1657 }
1658 }
1659
1660 private Phone getPhoneFromSubId(int subId) {
1661 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1662 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001663 }
1664
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001665 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1666 Phone phone = getPhoneFromRequest(request);
1667 return phone == null ? null :
1668 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1669 }
1670
Wink Saville36469e72014-06-11 15:17:00 -07001671 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001672 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001673 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675
Naina Nallurid63128d2019-09-17 14:10:30 -07001676 private void sendEraseModemConfig(Phone phone) {
1677 if (phone != null) {
1678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1679 mApp, phone.getSubId(), "eraseModemConfig");
1680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1683 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
1686 }
1687 }
1688 }
1689
Peter Wang44b186e2020-01-13 23:33:09 -08001690 private boolean isImsAvailableOnDevice() {
1691 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1692 if (pm == null) {
1693 // For some reason package manger is not available.. This will fail internally anyway,
1694 // so do not throw error and allow.
1695 return true;
1696 }
1697 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1698 }
1699
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001701 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001702 }
1703
Wink Savilleb564aae2014-10-23 10:18:09 -07001704 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 if (DBG) log("dial: " + number);
1706 // No permission check needed here: This is just a wrapper around the
1707 // ACTION_DIAL intent, which is available to any app since it puts up
1708 // the UI before it does anything.
1709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710 final long identity = Binder.clearCallingIdentity();
1711 try {
1712 String url = createTelUrl(number);
1713 if (url == null) {
1714 return;
1715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 // PENDING: should we just silently fail if phone is offhook or ringing?
1718 PhoneConstants.State state = mCM.getState(subId);
1719 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1720 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1721 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1722 mApp.startActivity(intent);
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727 }
1728
1729 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001730 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001731 }
1732
Wink Savilleb564aae2014-10-23 10:18:09 -07001733 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 if (DBG) log("call: " + number);
1735
1736 // This is just a wrapper around the ACTION_CALL intent, but we still
1737 // need to do a permission check since we're calling startActivity()
1738 // from the context of the phone app.
1739 enforceCallPermission();
1740
Jordan Liu1617b712019-07-10 15:06:26 -07001741 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 != AppOpsManager.MODE_ALLOWED) {
1743 return;
1744 }
1745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 String url = createTelUrl(number);
1749 if (url == null) {
1750 return;
1751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753 boolean isValid = false;
1754 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1755 if (slist != null) {
1756 for (SubscriptionInfo subInfoRecord : slist) {
1757 if (subInfoRecord.getSubscriptionId() == subId) {
1758 isValid = true;
1759 break;
1760 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001761 }
Wink Saville08874612014-08-31 19:19:58 -07001762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763 if (!isValid) {
1764 return;
1765 }
Wink Saville08874612014-08-31 19:19:58 -07001766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1768 intent.putExtra(SUBSCRIPTION_KEY, subId);
1769 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1770 mApp.startActivity(intent);
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
1773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
Wink Savilleb564aae2014-10-23 10:18:09 -07001776 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001777 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001778 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1779 }
1780
Wink Savilleb564aae2014-10-23 10:18:09 -07001781 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001782 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001783 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1784 }
1785
Wink Savilleb564aae2014-10-23 10:18:09 -07001786 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001788
1789 final long identity = Binder.clearCallingIdentity();
1790 try {
1791 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1792 checkSimPin.start();
1793 return checkSimPin.unlockSim(null, pin);
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
1796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Wink Savilleb564aae2014-10-23 10:18:09 -07001799 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801
1802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1805 checkSimPuk.start();
1806 return checkSimPuk.unlockSim(puk, pin);
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
1809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
1812 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001813 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 * a synchronous one.
1815 */
1816 private static class UnlockSim extends Thread {
1817
1818 private final IccCard mSimCard;
1819
1820 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001821 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1822 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823
1824 // For replies from SimCard interface
1825 private Handler mHandler;
1826
1827 // For async handler to identify request type
1828 private static final int SUPPLY_PIN_COMPLETE = 100;
1829
1830 public UnlockSim(IccCard simCard) {
1831 mSimCard = simCard;
1832 }
1833
1834 @Override
1835 public void run() {
1836 Looper.prepare();
1837 synchronized (UnlockSim.this) {
1838 mHandler = new Handler() {
1839 @Override
1840 public void handleMessage(Message msg) {
1841 AsyncResult ar = (AsyncResult) msg.obj;
1842 switch (msg.what) {
1843 case SUPPLY_PIN_COMPLETE:
1844 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1845 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001846 mRetryCount = msg.arg1;
1847 if (ar.exception != null) {
1848 if (ar.exception instanceof CommandException &&
1849 ((CommandException)(ar.exception)).getCommandError()
1850 == CommandException.Error.PASSWORD_INCORRECT) {
1851 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1852 } else {
1853 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1854 }
1855 } else {
1856 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 mDone = true;
1859 UnlockSim.this.notifyAll();
1860 }
1861 break;
1862 }
1863 }
1864 };
1865 UnlockSim.this.notifyAll();
1866 }
1867 Looper.loop();
1868 }
1869
1870 /*
1871 * Use PIN or PUK to unlock SIM card
1872 *
1873 * If PUK is null, unlock SIM card with PIN
1874 *
1875 * If PUK is not null, unlock SIM card with PUK and set PIN code
1876 */
Wink Saville9de0f752013-10-22 19:04:03 -07001877 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878
1879 while (mHandler == null) {
1880 try {
1881 wait();
1882 } catch (InterruptedException e) {
1883 Thread.currentThread().interrupt();
1884 }
1885 }
1886 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1887
1888 if (puk == null) {
1889 mSimCard.supplyPin(pin, callback);
1890 } else {
1891 mSimCard.supplyPuk(puk, pin, callback);
1892 }
1893
1894 while (!mDone) {
1895 try {
1896 Log.d(LOG_TAG, "wait for done");
1897 wait();
1898 } catch (InterruptedException e) {
1899 // Restore the interrupted status
1900 Thread.currentThread().interrupt();
1901 }
1902 }
1903 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001904 int[] resultArray = new int[2];
1905 resultArray[0] = mResult;
1906 resultArray[1] = mRetryCount;
1907 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909 }
1910
1911 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001913
1914 }
1915
Wink Savilleb564aae2014-10-23 10:18:09 -07001916 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 // No permission check needed here: this call is harmless, and it's
1918 // needed for the ServiceState.requestStateUpdate() call (which is
1919 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001920 final long identity = Binder.clearCallingIdentity();
1921 try {
1922 final Phone phone = getPhone(subId);
1923 if (phone != null) {
1924 phone.updateServiceLocation();
1925 }
1926 } finally {
1927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001931 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 @Override
1933 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001934 return isRadioOnWithFeature(callingPackage, null);
1935 }
1936
1937
1938 @Override
1939 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1940 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1941 callingFeatureId);
1942 }
1943
1944 @Deprecated
1945 @Override
1946 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1947 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001948 }
1949
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001951 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1952 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001954 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001955 return false;
1956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957
1958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 return isRadioOnForSubscriber(subId);
1961 } finally {
1962 Binder.restoreCallingIdentity(identity);
1963 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 }
1965
1966 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 final long identity = Binder.clearCallingIdentity();
1968 try {
1969 final Phone phone = getPhone(subId);
1970 if (phone != null) {
1971 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1972 } else {
1973 return false;
1974 }
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
1980 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001981 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
Wink Saville36469e72014-06-11 15:17:00 -07001983
Wink Savilleb564aae2014-10-23 10:18:09 -07001984 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986
1987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 final Phone phone = getPhone(subId);
1990 if (phone != null) {
1991 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 }
Wink Saville36469e72014-06-11 15:17:00 -07001996 }
1997
1998 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001999 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002000 }
2001
Wink Savilleb564aae2014-10-23 10:18:09 -07002002 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004
2005 final long identity = Binder.clearCallingIdentity();
2006 try {
2007 final Phone phone = getPhone(subId);
2008 if (phone == null) {
2009 return false;
2010 }
2011 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2012 toggleRadioOnOffForSubscriber(subId);
2013 }
2014 return true;
2015 } finally {
2016 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 }
Wink Saville36469e72014-06-11 15:17:00 -07002019
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002020 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002021 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002022 /*
2023 * If any of the Radios are available, it will need to be
2024 * shutdown. So return true if any Radio is available.
2025 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2029 Phone phone = PhoneFactory.getPhone(i);
2030 if (phone != null && phone.isRadioAvailable()) return true;
2031 }
2032 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2033 return false;
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002036 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002037 }
2038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002040 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 enforceModifyPermission();
2042
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
2045 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2046 logv("Shutting down Phone " + i);
2047 shutdownRadioUsingPhoneId(i);
2048 }
2049 } finally {
2050 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002051 }
2052 }
2053
2054 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002055 Phone phone = PhoneFactory.getPhone(phoneId);
2056 if (phone != null && phone.isRadioAvailable()) {
2057 phone.shutdownRadio();
2058 }
2059 }
2060
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002062 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063
2064 final long identity = Binder.clearCallingIdentity();
2065 try {
2066 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2067 if (defaultPhone != null) {
2068 defaultPhone.setRadioPower(turnOn);
2069 return true;
2070 } else {
2071 loge("There's no default phone.");
2072 return false;
2073 }
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002076 }
Wink Saville36469e72014-06-11 15:17:00 -07002077 }
2078
Wink Savilleb564aae2014-10-23 10:18:09 -07002079 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 final Phone phone = getPhone(subId);
2085 if (phone != null) {
2086 phone.setRadioPower(turnOn);
2087 return true;
2088 } else {
2089 return false;
2090 }
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
Wink Saville36469e72014-06-11 15:17:00 -07002096 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 public boolean enableDataConnectivity() {
2099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002100
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 int subId = mSubscriptionController.getDefaultDataSubId();
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002106 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002107 return true;
2108 } else {
2109 return false;
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
Wink Saville36469e72014-06-11 15:17:00 -07002116 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 public boolean disableDataConnectivity() {
2119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 int subId = mSubscriptionController.getDefaultDataSubId();
2124 final Phone phone = getPhone(subId);
2125 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002126 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002127 return true;
2128 } else {
2129 return false;
2130 }
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002137 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 final Phone phone = getPhone(subId);
2141 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002142 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002143 } else {
2144 return false;
2145 }
2146 } finally {
2147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 }
2150
2151 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002152 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002153 }
2154
pkanwarae03a6b2016-11-06 20:37:09 -08002155 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 enforceCallPermission();
2157
2158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2161 return;
2162 }
2163 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2164 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
pkanwar32d516d2016-10-14 19:37:38 -07002168 };
2169
Wink Savilleb564aae2014-10-23 10:18:09 -07002170 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2176 return false;
2177 }
2178 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002185 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002188 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 Phone phone = PhoneFactory.getPhone(slotIndex);
2192 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2193 PhoneConstantConversions.convertCallState(phone.getState());
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
2196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002200 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002201 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2202 }
2203
2204 @Override
2205 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206 final long identity = Binder.clearCallingIdentity();
2207 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002208 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 if (phone != null) {
2210 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2211 } else {
2212 return PhoneConstantConversions.convertDataState(
2213 PhoneConstants.DataState.DISCONNECTED);
2214 }
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219
Sanket Padawe356d7632015-06-22 14:03:32 -07002220 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002221 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002222 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2223 }
2224
2225 @Override
2226 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 final long identity = Binder.clearCallingIdentity();
2228 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002229 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 if (phone != null) {
2231 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2232 } else {
2233 return TelephonyManager.DATA_ACTIVITY_NONE;
2234 }
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
2240 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002241 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002242 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002243 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002244
2245 LocationAccessPolicy.LocationPermissionResult locationResult =
2246 LocationAccessPolicy.checkLocationPermission(mApp,
2247 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2248 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002249 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002250 .setCallingPid(Binder.getCallingPid())
2251 .setCallingUid(Binder.getCallingUid())
2252 .setMethod("getCellLocation")
2253 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2254 .build());
2255 switch (locationResult) {
2256 case DENIED_HARD:
2257 throw new SecurityException("Not allowed to access cell location");
2258 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002259 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2260 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002267 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002268 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Svetoslav64fad262015-04-14 14:35:21 -07002272 }
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002275 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2276 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002277 if (!TextUtils.isEmpty(callingPackage)) {
2278 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2280 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002281 return "";
2282 }
2283 }
2284
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002285 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2286 // registered cell info, so return a NULL country instead.
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002289 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2290 // Get default phone in this case.
2291 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2292 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002293 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002294 // Todo: fix this when we can get the actual cellular network info when the device
2295 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002296 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002297 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2298 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002299 return "";
2300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 Phone phone = PhoneFactory.getPhone(phoneId);
2302 if (phone != null) {
2303 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002304 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (sst != null) {
2306 LocaleTracker lt = sst.getLocaleTracker();
2307 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002308 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2309 return lt.getCurrentCountry();
2310 } else if (emergencyNumberTracker != null) {
2311 return emergencyNumberTracker.getEmergencyCountryIso();
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 }
2314 }
2315 }
2316 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002320 }
2321
2322 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mApp.enforceCallingOrSelfPermission(
2330 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 if (phone != null) {
2336 phone.enableLocationUpdates();
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 @Override
2344 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002345 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002349 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 mApp.enforceCallingOrSelfPermission(
2351 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 final Phone phone = getPhone(subId);
2356 if (phone != null) {
2357 phone.disableLocationUpdates();
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 }
2363
Nathan Harold31d7ff32018-10-15 20:20:30 -07002364 /**
2365 * Returns the target SDK version number for a given package name.
2366 *
Nathan Haroldec184742019-07-10 17:04:16 -07002367 * This call MUST be invoked before clearing the calling UID.
2368 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002369 * @return target SDK if the package is found or INT_MAX.
2370 */
2371 private int getTargetSdk(String packageName) {
2372 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002373 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002374 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002375 if (ai != null) return ai.targetSdkVersion;
2376 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002377 loge("Failed to get package info for pkg="
2378 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 }
2380 return Integer.MAX_VALUE;
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 @Override
2384 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002385 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2386 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002387 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002388 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2389 throw new SecurityException(
2390 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2391 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2395 return null;
2396 }
Svetoslav64fad262015-04-14 14:35:21 -07002397
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002398 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002400 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002401 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Nathan Haroldf180aac2018-06-01 18:43:55 -07002403 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2404 for (CellInfo ci : info) {
2405 if (ci instanceof CellInfoGsm) {
2406 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2407 } else if (ci instanceof CellInfoWcdma) {
2408 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002411 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 private List<CellInfo> getCachedCellInfo() {
2415 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2416 for (Phone phone : PhoneFactory.getPhones()) {
2417 List<CellInfo> info = phone.getAllCellInfo();
2418 if (info != null) cellInfos.addAll(info);
2419 }
2420 return cellInfos;
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
2423 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002424 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002425 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002426 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002427
2428 LocationAccessPolicy.LocationPermissionResult locationResult =
2429 LocationAccessPolicy.checkLocationPermission(mApp,
2430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2431 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002432 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002433 .setCallingPid(Binder.getCallingPid())
2434 .setCallingUid(Binder.getCallingUid())
2435 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002436 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002437 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2438 .build());
2439 switch (locationResult) {
2440 case DENIED_HARD:
2441 throw new SecurityException("Not allowed to access cell info");
2442 case DENIED_SOFT:
2443 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002446 final int targetSdk = getTargetSdk(callingPackage);
2447 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2448 return getCachedCellInfo();
2449 }
2450
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002451 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2456 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002457 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002458 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 if (info != null) cellInfos.addAll(info);
2460 }
2461 return cellInfos;
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002468 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2469 String callingFeatureId) {
2470 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2471 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002472 }
2473
2474 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002475 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2476 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002478 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 }
2480
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2482 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002484 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002485
2486 LocationAccessPolicy.LocationPermissionResult locationResult =
2487 LocationAccessPolicy.checkLocationPermission(mApp,
2488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2489 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002490 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002491 .setCallingPid(Binder.getCallingPid())
2492 .setCallingUid(Binder.getCallingUid())
2493 .setMethod("requestCellInfoUpdate")
2494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 switch (locationResult) {
2497 case DENIED_HARD:
2498 throw new SecurityException("Not allowed to access cell info");
2499 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002500 try {
2501 cb.onCellInfo(new ArrayList<CellInfo>());
2502 } catch (RemoteException re) {
2503 // Drop without consequences
2504 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002505 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002506 }
2507
Nathan Harolda939a962019-05-09 10:13:47 -07002508
2509 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2511
2512 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2513 }
2514
2515 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002517 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002522 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Shishir Agrawala9f32182016-04-12 12:00:16 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 Phone phone = PhoneFactory.getPhone(slotIndex);
2531 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 return null;
2533 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002534 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002535 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002536 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002537 return null;
2538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 return phone.getImei();
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002546 }
2547
2548 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002549 public String getTypeAllocationCodeForSlot(int slotIndex) {
2550 Phone phone = PhoneFactory.getPhone(slotIndex);
2551 String tac = null;
2552 if (phone != null) {
2553 String imei = phone.getImei();
2554 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2555 }
2556 return tac;
2557 }
2558
2559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002560 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 Phone phone = PhoneFactory.getPhone(slotIndex);
2562 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002563 return null;
2564 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002565
Jeff Davidson913390f2018-02-23 17:11:49 -08002566 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002567 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002568 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002569 return null;
2570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 return phone.getMeid();
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Jack Yu2af8d712017-03-15 17:14:14 -07002578 }
2579
2580 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002581 public String getManufacturerCodeForSlot(int slotIndex) {
2582 Phone phone = PhoneFactory.getPhone(slotIndex);
2583 String manufacturerCode = null;
2584 if (phone != null) {
2585 String meid = phone.getMeid();
2586 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2587 }
2588 return manufacturerCode;
2589 }
2590
2591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002592 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2593 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 return null;
2597 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002598 int subId = phone.getSubId();
2599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002600 mApp, subId, callingPackage, callingFeatureId,
2601 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002602 return null;
2603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 return phone.getDeviceSvn();
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
2610 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002611 }
2612
fionaxu43304da2017-11-27 22:51:16 -08002613 @Override
2614 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
2618 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
fionaxu43304da2017-11-27 22:51:16 -08002622 }
2623
2624 @Override
2625 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 final Phone phone = getPhone(subId);
2629 return phone == null ? null : phone.getCarrierName();
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
fionaxu43304da2017-11-27 22:51:16 -08002633 }
2634
calvinpanffe225e2018-11-01 19:43:06 +08002635 @Override
chen xu0026ca62019-03-06 15:28:50 -08002636 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002641 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
2645 }
2646
2647 @Override
chen xu0026ca62019-03-06 15:28:50 -08002648 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002652 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
2656 }
2657
chen xu651eec72018-11-11 19:03:44 -08002658 @Override
chen xu864e11c2018-12-06 22:10:03 -08002659 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2660 if (!isSubscriptionMccMnc) {
2661 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2662 }
chen xu651eec72018-11-11 19:03:44 -08002663 final Phone phone = PhoneFactory.getPhone(slotIndex);
2664 if (phone == null) {
2665 return TelephonyManager.UNKNOWN_CARRIER_ID;
2666 }
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
2673 }
2674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 //
2676 // Internal helper methods.
2677 //
2678
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002679 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2681 *
2682 * @throws SecurityException if the caller does not have the required permission
2683 */
2684 private void enforceModifyPermission() {
2685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2686 }
2687
Shuo Qiancd19c462020-01-16 20:51:11 -08002688 /**
2689 * Make sure the caller is system.
2690 *
2691 * @throws SecurityException if the caller is not system.
2692 */
2693 private void enforceSystemCaller() {
2694 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2695 throw new SecurityException("Caller must be system");
2696 }
2697 }
2698
Shuo Qian3b6ee772019-11-13 17:43:31 -08002699 private void enforceActiveEmergencySessionPermission() {
2700 mApp.enforceCallingOrSelfPermission(
2701 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2702 }
2703
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 /**
2705 * Make sure the caller has the CALL_PHONE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceCallPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2711 }
2712
paulhu5a773602019-08-23 19:17:33 +08002713 private void enforceSettingsPermission() {
2714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 private String createTelUrl(String number) {
2718 if (TextUtils.isEmpty(number)) {
2719 return null;
2720 }
2721
Jake Hambye994d462014-02-03 13:10:13 -08002722 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Ihab Awadf9e92732013-12-05 18:02:52 -08002725 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2727 }
2728
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002729 private static void logv(String msg) {
2730 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2731 }
2732
Ihab Awadf9e92732013-12-05 18:02:52 -08002733 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2735 }
2736
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002737 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002739 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002740 }
2741
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002743 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = PhoneFactory.getPhone(slotIndex);
2747 if (phone == null) {
2748 return PhoneConstants.PHONE_TYPE_NONE;
2749 } else {
2750 return phone.getPhoneType();
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 /**
2758 * Returns the CDMA ERI icon index to display
2759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002761 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2762 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002764 }
2765
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 mApp, subId, callingPackage, callingFeatureId,
2771 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 return -1;
2773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 final Phone phone = getPhone(subId);
2778 if (phone != null) {
2779 return phone.getCdmaEriIconIndex();
2780 } else {
2781 return -1;
2782 }
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 }
2787
2788 /**
2789 * Returns the CDMA ERI icon mode,
2790 * 0 - ON
2791 * 1 - FLASHING
2792 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002794 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2795 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2796 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002797 }
2798
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002800 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2801 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 mApp, subId, callingPackage, callingFeatureId,
2804 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 return -1;
2806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 final Phone phone = getPhone(subId);
2811 if (phone != null) {
2812 return phone.getCdmaEriIconMode();
2813 } else {
2814 return -1;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 /**
2822 * Returns the CDMA ERI text,
2823 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2826 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2827 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2832 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 mApp, subId, callingPackage, callingFeatureId,
2835 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 return null;
2837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
2843 return phone.getCdmaEriText();
2844 } else {
2845 return null;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002853 * Returns the CDMA MDN.
2854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002856 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2858 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 return phone.getLine1Number();
2865 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 return null;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002871 }
2872 }
2873
2874 /**
2875 * Returns the CDMA MIN.
2876 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002878 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2880 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
2885 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2886 return phone.getCdmaMin();
2887 } else {
2888 return null;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002892 }
2893 }
2894
Hall Liud892bec2018-11-30 14:51:45 -08002895 @Override
2896 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2897 INumberVerificationCallback callback, String callingPackage) {
2898 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2899 != PERMISSION_GRANTED) {
2900 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2901 }
2902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2903
2904 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2905 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2906 throw new SecurityException("Calling package must be configured in the device config");
2907 }
2908
2909 if (range == null) {
2910 throw new NullPointerException("Range must be non-null");
2911 }
2912
2913 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002914 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002915
2916 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2917 }
2918
Junda Liuca05d5d2014-08-14 22:36:34 -07002919 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 * Returns true if CDMA provisioning needs to run.
2921 */
2922 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
2931 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002932 * Sets the voice mail number of a given subId.
2933 */
2934 @Override
2935 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002936 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2937 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2942 new Pair<String, String>(alphaTag, number), new Integer(subId));
2943 return success;
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002947 }
2948
Ta-wei Yen87c49842016-05-13 21:19:52 -07002949 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002950 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002952 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2953 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002954 if (!TextUtils.equals(callingPackage, systemDialer)) {
2955 throw new SecurityException("caller must be system dialer");
2956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2961 if (phoneAccountHandle == null) {
2962 return null;
2963 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002967 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002968 }
2969
2970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002971 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2972 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002975 mApp, subId, callingPackage, callingFeatureId,
2976 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 return null;
2978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002986 }
2987
2988 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002989 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2990 VisualVoicemailSmsFilterSettings settings) {
2991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003000 }
3001
3002 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003003 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003013 }
3014
3015 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003016 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3017 String callingPackage, int subId) {
3018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003027 }
3028
3029 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003030 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003040 }
3041
3042 @Override
3043 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3044 String number, int port, String text, PendingIntent sentIntent) {
3045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003046 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003047 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003048 SmsController smsController = PhoneFactory.getSmsController();
3049 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3050 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003051 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003052
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003053 /**
fionaxu0152e512016-11-14 13:36:14 -08003054 * Sets the voice activation state of a given subId.
3055 */
3056 @Override
3057 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3059 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 final Phone phone = getPhone(subId);
3064 if (phone != null) {
3065 phone.setVoiceActivationState(activationState);
3066 } else {
3067 loge("setVoiceActivationState fails with invalid subId: " + subId);
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003071 }
3072 }
3073
3074 /**
3075 * Sets the data activation state of a given subId.
3076 */
3077 @Override
3078 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3080 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 if (phone != null) {
3086 phone.setDataActivationState(activationState);
3087 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003088 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 }
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003092 }
3093 }
3094
3095 /**
3096 * Returns the voice activation state of a given subId.
3097 */
3098 @Override
3099 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
fionaxu0152e512016-11-14 13:36:14 -08003102 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (phone != null) {
3106 return phone.getVoiceActivationState();
3107 } else {
3108 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003112 }
3113 }
3114
3115 /**
3116 * Returns the data activation state of a given subId.
3117 */
3118 @Override
3119 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
fionaxu0152e512016-11-14 13:36:14 -08003122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (phone != null) {
3126 return phone.getDataActivationState();
3127 } else {
3128 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3129 }
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003132 }
3133 }
3134
3135 /**
Wink Saville36469e72014-06-11 15:17:00 -07003136 * Returns the unread count of voicemails for a subId
3137 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3140 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 mApp, subId, callingPackage, callingFeatureId,
3143 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003144 return 0;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 final Phone phone = getPhone(subId);
3149 if (phone != null) {
3150 return phone.getVoiceMessageCount();
3151 } else {
3152 return 0;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
3159 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003160 * returns true, if the device is in a state where both voice and data
3161 * are supported simultaneously. This can change based on location or network condition.
3162 */
3163 @Override
3164 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003172 }
3173
3174 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003175 * Send the dialer code if called from the current default dialer or the caller has
3176 * carrier privilege.
3177 * @param inputCode The dialer code to send
3178 */
3179 @Override
3180 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003183 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3184 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003185 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003187 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
fionaxu235cc5e2017-03-06 22:25:57 -08003196 }
3197
Pengquan Menga1bb6272018-09-06 09:59:22 -07003198 @Override
3199 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003200 TelephonyPermissions
3201 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3202 mApp, subId, "getNetworkSelectionMode");
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 if (!isActiveSubscription(subId)) {
3206 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3207 }
3208 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003212 }
3213
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003215 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3216 String callingFeatureId) {
3217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3218 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3219 return null;
3220 }
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 return mPhoneConfigurationManager.getStaticPhoneCapability();
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 }
3228
3229 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003230 public boolean isInEmergencySmsMode() {
3231 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 for (Phone phone : PhoneFactory.getPhones()) {
3235 if (phone.isInEmergencySmsMode()) {
3236 return true;
3237 }
3238 }
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 return false;
3243 }
3244
shilu366312e2019-12-17 09:28:10 -08003245 /**
3246 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3247 * @param subId The subscription to use to check the configuration.
3248 * @param c The callback that will be used to send the result.
3249 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003250 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003251 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3252 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003253 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003254 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003255
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003256 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3257 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3258 "IMS not available on device.");
3259 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 final long token = Binder.clearCallingIdentity();
3261 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003265 } catch (ImsException e) {
3266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 } finally {
3268 Binder.restoreCallingIdentity(token);
3269 }
3270 }
3271
shilu366312e2019-12-17 09:28:10 -08003272 /**
3273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3274 * @param subId The subscription to use to check the configuration.
3275 * @param c The callback that will be used to send the result.
3276 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003278 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003279 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003280 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003281 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3282 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3283 }
Meng Wangafbc5852019-09-19 17:37:13 -07003284 final long token = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3287 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3288 .removeRegistrationCallbackForSubscription(c, subId);
3289 } catch (ImsException e) {
3290 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3291 + "is inactive, ignoring unregister.");
3292 // If the subscription is no longer active, just return, since the callback
3293 // will already have been removed internally.
3294 } finally {
3295 Binder.restoreCallingIdentity(token);
3296 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003297 }
3298
Brad Ebingera34a6c22019-10-22 17:36:18 -07003299 /**
3300 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3301 */
3302 @Override
3303 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3304 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3305 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3306 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3307 "IMS not available on device.");
3308 }
3309 final long token = Binder.clearCallingIdentity();
3310 try {
3311 Phone phone = getPhone(subId);
3312 if (phone == null) {
3313 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3314 + subId + "'");
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3316 }
3317 phone.getImsRegistrationState(regState -> {
3318 try {
3319 consumer.accept((regState == null)
3320 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3321 } catch (RemoteException e) {
3322 // Ignore if the remote process is no longer available to call back.
3323 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3324 }
3325 });
3326 } finally {
3327 Binder.restoreCallingIdentity(token);
3328 }
3329 }
3330
3331 /**
3332 * Get the transport type for the IMS service registration state.
3333 */
3334 @Override
3335 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003336 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003337 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3338 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3340 "IMS not available on device.");
3341 }
3342 final long token = Binder.clearCallingIdentity();
3343 try {
3344 Phone phone = getPhone(subId);
3345 if (phone == null) {
3346 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3347 + subId + "'");
3348 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3349 }
3350 phone.getImsRegistrationTech(regTech -> {
3351 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3352 int regTechConverted = (regTech == null)
3353 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3354 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3355 regTechConverted);
3356 try {
3357 consumer.accept(regTechConverted);
3358 } catch (RemoteException e) {
3359 // Ignore if the remote process is no longer available to call back.
3360 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3361 }
3362 });
3363 } finally {
3364 Binder.restoreCallingIdentity(token);
3365 }
3366 }
3367
shilu366312e2019-12-17 09:28:10 -08003368 /**
3369 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3370 * @param subId The subscription to use to check the configuration.
3371 * @param c The callback that will be used to send the result.
3372 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003374 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3375 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003376 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003377 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003378 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3379 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3380 "IMS not available on device.");
3381 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3383 final long token = Binder.clearCallingIdentity();
3384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003387 } catch (ImsException e) {
3388 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003389 } finally {
3390 Binder.restoreCallingIdentity(token);
3391 }
3392 }
3393
shilu366312e2019-12-17 09:28:10 -08003394 /**
3395 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3396 * @param subId The subscription to use to check the configuration.
3397 * @param c The callback that will be used to send the result.
3398 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003400 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003401 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003402 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003403 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3404 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3405 }
Meng Wangafbc5852019-09-19 17:37:13 -07003406
3407 final long token = Binder.clearCallingIdentity();
3408 try {
3409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3410 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003411 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003412 } catch (ImsException e) {
3413 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3414 + "is inactive, ignoring unregister.");
3415 // If the subscription is no longer active, just return, since the callback
3416 // will already have been removed internally.
3417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 }
3421
3422 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003423 public boolean isCapable(int subId, int capability, int regTech) {
3424 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3426 final long token = Binder.clearCallingIdentity();
3427 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003428 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003430 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3432 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003433 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003434 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3435 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 } finally {
3437 Binder.restoreCallingIdentity(token);
3438 }
3439 }
3440
3441 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003442 public boolean isAvailable(int subId, int capability, int regTech) {
3443 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 final long token = Binder.clearCallingIdentity();
3445 try {
3446 Phone phone = getPhone(subId);
3447 if (phone == null) return false;
3448 return phone.isImsCapabilityAvailable(capability, regTech);
3449 } finally {
3450 Binder.restoreCallingIdentity(token);
3451 }
3452 }
3453
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003454 /**
3455 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3456 * subscription.
3457 * @param subId The subscription to use to check the configuration.
3458 * @param callback The callback that will be used to send the result.
3459 * @param capability The MmTelFeature capability that will be used to send the result.
3460 * @param transportType The transport type of the MmTelFeature capability.
3461 */
3462 @Override
3463 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3464 int transportType) {
3465 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3466 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3467 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3468 "IMS not available on device.");
3469 }
3470 final long token = Binder.clearCallingIdentity();
3471 try {
3472 int slotId = getSlotIndex(subId);
3473 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3474 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3475 + subId + "'");
3476 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3477 }
3478 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3479 transportType, aBoolean -> {
3480 try {
3481 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3482 } catch (RemoteException e) {
3483 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3484 + "running. Ignore");
3485 }
3486 });
3487 } finally {
3488 Binder.restoreCallingIdentity(token);
3489 }
3490 }
3491
shilu366312e2019-12-17 09:28:10 -08003492 /**
3493 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3494 * @param subId The subscription to use to check the configuration.
3495 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 @Override
3497 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003498 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3499 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3500
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3502 final long token = Binder.clearCallingIdentity();
3503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (ImsException e) {
3507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 } finally {
3509 Binder.restoreCallingIdentity(token);
3510 }
3511 }
3512
3513 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003514 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003516 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (ImsException e) {
3523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
3527 }
3528
shilu366312e2019-12-17 09:28:10 -08003529 /**
3530 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3531 * @param subId The subscription to use to check the configuration.
3532 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003534 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003535 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003536 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3541 } catch (ImsException e) {
3542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
3546 }
3547
3548 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003549 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003551 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003556 } catch (ImsException e) {
3557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
shilu366312e2019-12-17 09:28:10 -08003563 /**
3564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3565 * @param subId The subscription to use to check the configuration.
3566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 @Override
3568 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003569 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
3581 }
3582
3583 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003584 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003586 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003591 } catch (ImsException e) {
3592 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
shilu366312e2019-12-17 09:28:10 -08003598 /**
3599 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3600 * @param subId The subscription to use to check the configuration.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
3603 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003604 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 } catch (ImsException e) {
3612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
3618 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003619 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003621 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (ImsException e) {
3628 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633
3634 @Override
3635 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3637 "setVoWiFiNonPersistent");
3638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003642 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003643 } catch (ImsException e) {
3644 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
3648 }
3649
shilu366312e2019-12-17 09:28:10 -08003650 /**
3651 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3652 * @param subId The subscription to use to check the configuration.
3653 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 @Override
3655 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003656 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003663 } catch (ImsException e) {
3664 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
3668 }
3669
3670 @Override
3671 public void setVoWiFiModeSetting(int subId, int mode) {
3672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3673 "setVoWiFiModeSetting");
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003679 } catch (ImsException e) {
3680 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
3684 }
3685
3686 @Override
3687 public int getVoWiFiRoamingModeSetting(int subId) {
3688 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setVoWiFiRoamingModeSetting");
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (ImsException e) {
3711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3720 "setRttCapabilityEnabled");
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
shilu366312e2019-12-17 09:28:10 -08003732 /**
3733 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3734 * @param subId The subscription to use to check the configuration.
3735 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 @Override
3737 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003738 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 } catch (ImsException e) {
3746 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003752 @Override
3753 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3754 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003757 if (!isImsAvailableOnDevice()) {
3758 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3759 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003760 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003761 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003763 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003764 } catch (ImsException e) {
3765 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
3769 }
3770
3771 @Override
3772 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3773 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3774 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 try {
3779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003781 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003782 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003783 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3784 + "is inactive, ignoring unregister.");
3785 // If the subscription is no longer active, just return, since the callback will already
3786 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
3790 }
3791
allenwtsu99c623b2020-01-03 18:24:23 +08003792
3793 private void checkModifyPhoneStatePermission(int subId, String message) {
3794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3795 message);
3796 }
3797
3798 private boolean isImsProvisioningRequired(int subId, int capability,
3799 boolean isMmtelCapability) {
3800 Phone phone = getPhone(subId);
3801 if (phone == null) {
3802 loge("phone instance null for subid " + subId);
3803 return false;
3804 }
3805 if (isMmtelCapability) {
3806 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3807 return false;
3808 }
3809 } else {
3810 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3811 return false;
3812 }
3813 }
3814 return true;
3815 }
3816
3817 @Override
3818 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3819 boolean isProvisioned) {
3820 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3825 if (!isImsProvisioningRequired(subId, capability, false)) {
3826 return;
3827 }
3828
3829 // this capability requires provisioning, route to the correct API.
3830 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3831 switch (capability) {
3832 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3833 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3834 ims.setEabProvisioned(isProvisioned);
3835 break;
3836 default: {
3837 throw new IllegalArgumentException("Tried to set provisioning for "
3838 + "rcs capability '" + capability + "', which does not require "
3839 + "provisioning.");
3840 }
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
3844 }
3845
3846 }
3847
3848
3849 @Override
3850 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3851 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3855 if (!isImsProvisioningRequired(subId, capability, false)) {
3856 return true;
3857 }
3858
3859 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3860 switch (capability) {
3861 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3863 return ims.isEabProvisionedOnDevice();
3864
3865 default: {
3866 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3867 + "capability '" + capability + "', which does not require "
3868 + "provisioning.");
3869 }
3870 }
3871
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
3875 }
3876
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003877 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003878 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3879 boolean isProvisioned) {
3880 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3881 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3882 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3883 }
allenwtsu99c623b2020-01-03 18:24:23 +08003884 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003888 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 return;
3890 }
3891
3892 // this capability requires provisioning, route to the correct API.
3893 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3894 switch (capability) {
3895 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3896 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3897 ims.setVolteProvisioned(isProvisioned);
3898 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3899 ims.setWfcProvisioned(isProvisioned);
3900 }
3901 break;
3902 }
3903 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3904 // There is currently no difference in VT provisioning type.
3905 ims.setVtProvisioned(isProvisioned);
3906 break;
3907 }
3908 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3909 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3910 // change the capability of the feature instead if needed.
3911 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3912 == isProvisioned) {
3913 // No change in provisioning.
3914 return;
3915 }
3916 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3917 try {
3918 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3921 + ", Exception" + e.getMessage());
3922 }
3923 break;
3924 }
3925 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003926 throw new IllegalArgumentException("Tried to set provisioning for "
3927 + "MmTel capability '" + capability + "', which does not require "
3928 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003929 }
3930 }
3931
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
3934 }
3935 }
3936
3937 @Override
3938 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3939 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3940 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3941 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3942 }
3943 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003947 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003948 return true;
3949 }
3950
3951 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3952 switch (capability) {
3953 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3954 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3955 return ims.isVolteProvisionedOnDevice();
3956 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3957 return ims.isWfcProvisionedOnDevice();
3958 }
3959 // This should never happen, since we are checking tech above to make sure it
3960 // is either LTE or IWLAN.
3961 throw new IllegalArgumentException("Invalid radio technology for voice "
3962 + "capability.");
3963 }
3964 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3965 // There is currently no difference in VT provisioning type.
3966 return ims.isVtProvisionedOnDevice();
3967 }
3968 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3969 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3970 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3971 }
3972 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003973 throw new IllegalArgumentException(
3974 "Tried to get provisioning for MmTel capability '" + capability
3975 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003976 }
3977 }
3978
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
3982 }
3983
3984 @Override
3985 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3986 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3987 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3988 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3989 }
3990 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3991 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3992 return (provisionedBits & capability) > 0;
3993 }
3994
3995 @Override
3996 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3997 boolean isProvisioned) {
3998 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3999 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4000 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4001 }
4002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4003 "setProvisioningStatusForCapability");
4004 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4005 // If the current provisioning status for capability already matches isProvisioned,
4006 // do nothing.
4007 if (((provisionedBits & capability) > 0) == isProvisioned) {
4008 return;
4009 }
4010 if (isProvisioned) {
4011 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4012 } else {
4013 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4014 }
4015 }
4016
4017 /**
4018 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4019 * technology. The bitfield should mirror the bitfield defined by
4020 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4021 */
4022 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4023 String key = getMmTelProvisioningKey(subId, tech);
4024 // Default is no capabilities are provisioned.
4025 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4026 }
4027
4028 /**
4029 * Sets the MmTel capability provisioning bitfield (defined by
4030 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4031 * technology specified.
4032 *
4033 * Note: This is a synchronous command and should not be called on UI thread.
4034 */
4035 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4036 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4037 String key = getMmTelProvisioningKey(subId, tech);
4038 editor.putInt(key, newField);
4039 editor.commit();
4040 }
4041
4042 private static String getMmTelProvisioningKey(int subId, int tech) {
4043 // resulting key is provision_ims_mmtel_{subId}_{tech}
4044 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4045 }
4046
4047 /**
4048 * Query CarrierConfig to see if the specified capability requires provisioning for the
4049 * carrier associated with the subscription id.
4050 */
4051 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4052 int capability) {
4053 CarrierConfigManager configManager = new CarrierConfigManager(context);
4054 PersistableBundle c = configManager.getConfigForSubId(subId);
4055 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004056 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004057 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4058 false);
4059 boolean requireVoiceVtProvisioning = c.getBoolean(
4060 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4061
4062 // First check to make sure that the capability requires provisioning.
4063 switch (capability) {
4064 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4065 // intentional fallthrough
4066 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4067 if (requireVoiceVtProvisioning) {
4068 // Voice and Video requires provisioning
4069 return true;
4070 }
4071 break;
4072 }
4073 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4074 if (requireUtProvisioning) {
4075 // UT requires provisioning
4076 return true;
4077 }
4078 break;
4079 }
4080 }
4081 return false;
4082 }
4083
allenwtsu99c623b2020-01-03 18:24:23 +08004084 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4085 int capability) {
4086 CarrierConfigManager configManager = new CarrierConfigManager(context);
4087 PersistableBundle c = configManager.getConfigForSubId(subId);
4088
4089 boolean requireRcsProvisioning = c.getBoolean(
4090 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4091
4092 // First check to make sure that the capability requires provisioning.
4093 switch (capability) {
4094 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4095 // intentional fallthrough
4096 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4097 if (requireRcsProvisioning) {
4098 // OPTION or PRESENCE requires provisioning
4099 return true;
4100 }
4101 break;
4102 }
4103 }
4104 return false;
4105 }
4106
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004107 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004108 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4110 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4111 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 enforceReadPrivilegedPermission("getImsProvisioningInt");
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004116 int slotId = getSlotIndex(subId);
4117 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4118 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4119 + subId + "' for key:" + key);
4120 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4121 }
4122 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4125 + subId + "' for key:" + key);
4126 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131
4132 @Override
4133 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4135 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4136 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 enforceReadPrivilegedPermission("getImsProvisioningString");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004141 int slotId = getSlotIndex(subId);
4142 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4143 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4144 + subId + "' for key:" + key);
4145 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4146 }
4147 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4150 + subId + "' for key:" + key);
4151 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4160 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4161 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4163 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004164 final long identity = Binder.clearCallingIdentity();
4165 try {
4166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004167 int slotId = getSlotIndex(subId);
4168 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4169 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4170 + subId + "' for key:" + key);
4171 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4172 }
4173 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004174 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004175 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4176 + "' for key:" + key);
4177 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004178 } finally {
4179 Binder.restoreCallingIdentity(identity);
4180 }
4181 }
4182
4183 @Override
4184 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4186 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4187 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4189 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004193 int slotId = getSlotIndex(subId);
4194 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4195 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4196 + subId + "' for key:" + key);
4197 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4198 }
4199 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4202 + "' for key:" + key);
4203 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 int slotId = SubscriptionManager.getSlotIndex(subId);
4211 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4213 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 }
4215 return slotId;
4216 }
4217
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004218 private int getSlotIndex(int subId) {
4219 int slotId = SubscriptionManager.getSlotIndex(subId);
4220 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4221 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4222 }
4223 return slotId;
4224 }
4225
Wink Saville36469e72014-06-11 15:17:00 -07004226 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004227 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004228 */
4229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4231 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004232 final int targetSdk = getTargetSdk(callingPackage);
4233 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004235 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004236 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004237 mApp, subId, callingPackage, callingFeatureId,
4238 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004239 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4240 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 final Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getServiceState().getDataNetworkType();
4247 } else {
4248 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004253 }
4254
4255 /**
4256 * Returns the data network type
4257 */
4258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004259 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4260 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4261 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004262 }
4263
4264 /**
4265 * Returns the data network type for a subId
4266 */
4267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004268 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4269 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 mApp, subId, callingPackage, callingFeatureId,
4272 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4274 }
4275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 final Phone phone = getPhone(subId);
4279 if (phone != null) {
4280 return phone.getServiceState().getDataNetworkType();
4281 } else {
4282 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4283 }
4284 } finally {
4285 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004287 }
4288
4289 /**
Wink Saville36469e72014-06-11 15:17:00 -07004290 * Returns the Voice network type for a subId
4291 */
4292 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004293 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4294 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004296 mApp, subId, callingPackage, callingFeatureId,
4297 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4299 }
4300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 final Phone phone = getPhone(subId);
4304 if (phone != null) {
4305 return phone.getServiceState().getVoiceNetworkType();
4306 } else {
4307 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4308 }
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004312 }
4313
4314 /**
4315 * @return true if a ICC card is present
4316 */
4317 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004318 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004319 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4320 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004321 }
4322
4323 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004324 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004325 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004326 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004327 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 final Phone phone = PhoneFactory.getPhone(slotIndex);
4331 if (phone != null) {
4332 return phone.getIccCard().hasIccCard();
4333 } else {
4334 return false;
4335 }
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004339 }
4340
4341 /**
4342 * Return if the current radio is LTE on CDMA. This
4343 * is a tri-state return value as for a period of time
4344 * the mode may be unknown.
4345 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004346 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004348 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004349 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004350 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004351 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4352 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4353 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004354 }
4355
Sanket Padawe356d7632015-06-22 14:03:32 -07004356 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004357 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4358 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004359 try {
4360 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4361 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004362 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4363 }
4364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 final long identity = Binder.clearCallingIdentity();
4366 try {
4367 final Phone phone = getPhone(subId);
4368 if (phone == null) {
4369 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4370 } else {
4371 return phone.getLteOnCdmaMode();
4372 }
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004375 }
Wink Saville36469e72014-06-11 15:17:00 -07004376 }
4377
Wink Saville36469e72014-06-11 15:17:00 -07004378 /**
4379 * {@hide}
4380 * Returns Default subId, 0 in the case of single standby.
4381 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004382 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004383 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004384 }
4385
Shishir Agrawala9f32182016-04-12 12:00:16 -07004386 private int getSlotForDefaultSubscription() {
4387 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4388 }
4389
Wink Savilleb564aae2014-10-23 10:18:09 -07004390 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004391 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004392 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004393
Pengquan Menge92a50d2018-09-21 15:54:48 -07004394 private boolean isActiveSubscription(int subId) {
4395 return mSubscriptionController.isActiveSubId(subId);
4396 }
4397
Ihab Awadf2177b72013-11-25 13:33:23 -08004398 /**
4399 * @see android.telephony.TelephonyManager.WifiCallingChoices
4400 */
4401 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004404 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4406 getWhenToMakeWifiCallsDefaultPreference());
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004410 }
4411
4412 /**
4413 * @see android.telephony.TelephonyManager.WifiCallingChoices
4414 */
4415 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004419 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004424 }
4425
Sailesh Nepald1e68152013-12-12 19:08:02 -08004426 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004427 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004428 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004429 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004430
Jordan Liu4c733742019-02-28 12:03:40 -08004431 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4432 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4433 if (phoneId == -1) {
4434 throw new IllegalArgumentException("Given slot index: " + slotIndex
4435 + " does not correspond to an active phone");
4436 }
4437 return PhoneFactory.getPhone(phoneId);
4438 }
4439
Shishir Agrawal566b7612013-10-28 14:41:00 -07004440 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004441 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4442 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4444 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004446 if (DBG) {
4447 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4448 }
4449 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4450 p2);
4451 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004452
Jordan Liu4c733742019-02-28 12:03:40 -08004453
4454 @Override
4455 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4456 int slotIndex, String callingPackage, String aid, int p2) {
4457 enforceModifyPermission();
4458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4459 if (DBG) {
4460 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4461 }
4462 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4463 callingPackage, aid, p2);
4464 }
4465
4466 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4467 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 if (TextUtils.equals(ISDR_AID, aid)) {
4471 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004472 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4473 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 if (bestComponent == null
4475 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4476 loge("The calling package is not allowed to access ISD-R.");
4477 throw new SecurityException(
4478 "The calling package is not allowed to access ISD-R.");
4479 }
Derek Tan740e1672017-06-27 14:56:27 -07004480 }
Derek Tan740e1672017-06-27 14:56:27 -07004481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004483 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4484 null /* workSource */);
4485 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 return response;
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004490 }
4491
4492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004493 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4495 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004496 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4497 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4498 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004499
Jordan Liu4c733742019-02-28 12:03:40 -08004500 @Override
4501 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4502 enforceModifyPermission();
4503 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4504 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4505 channel);
4506 }
4507
4508 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 final long identity = Binder.clearCallingIdentity();
4510 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 if (channel < 0) {
4512 return false;
4513 }
Jordan Liu4c733742019-02-28 12:03:40 -08004514 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4515 null /* workSource */);
4516 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 return success;
4518 } finally {
4519 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004521 }
4522
4523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004524 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004525 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004528 if (DBG) {
4529 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4530 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4531 + p3 + " data=" + data);
4532 }
4533 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4534 command, p1, p2, p3, data);
4535 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004536
Jordan Liu4c733742019-02-28 12:03:40 -08004537 @Override
4538 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4539 int command, int p1, int p2, int p3, String data) {
4540 enforceModifyPermission();
4541 if (DBG) {
4542 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4543 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4544 + p3 + " data=" + data);
4545 }
4546 return iccTransmitApduLogicalChannelWithPermission(
4547 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4548 data);
4549 }
4550
4551 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4552 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004555 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 return "";
4557 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004560 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4561 null /* workSource */);
4562 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 // Append the returned status code to the end of the response payload.
4565 String s = Integer.toHexString(
4566 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4567 if (response.payload != null) {
4568 s = IccUtils.bytesToHexString(response.payload) + s;
4569 }
4570 return s;
4571 } finally {
4572 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004573 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004574 }
Jake Hambye994d462014-02-03 13:10:13 -08004575
Evan Charltonc66da362014-05-16 14:06:40 -07004576 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004577 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4578 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4580 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004582 if (DBG) {
4583 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4584 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4585 }
4586 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4587 cla, command, p1, p2, p3, data);
4588 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004589
Jordan Liu4c733742019-02-28 12:03:40 -08004590 @Override
4591 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4592 int command, int p1, int p2, int p3, String data) {
4593 enforceModifyPermission();
4594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4595 if (DBG) {
4596 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4597 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4598 + " data=" + data);
4599 }
4600
4601 return iccTransmitApduBasicChannelWithPermission(
4602 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4603 p2, p3, data);
4604 }
4605
4606 // open APDU basic channel assuming the caller has sufficient permissions
4607 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4608 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4612 && TextUtils.equals(ISDR_AID, data)) {
4613 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004614 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4615 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 if (bestComponent == null
4617 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4618 loge("The calling package is not allowed to select ISD-R.");
4619 throw new SecurityException(
4620 "The calling package is not allowed to select ISD-R.");
4621 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004622 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004625 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4626 null /* workSource */);
4627 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 // Append the returned status code to the end of the response payload.
4630 String s = Integer.toHexString(
4631 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4632 if (response.payload != null) {
4633 s = IccUtils.bytesToHexString(response.payload) + s;
4634 }
4635 return s;
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004638 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004639 }
4640
4641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004642 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004643 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 if (DBG) {
4650 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4651 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4652 }
4653
4654 IccIoResult response =
4655 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4656 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4657 subId);
4658
4659 if (DBG) {
4660 log("Exchange SIM_IO [R]" + response);
4661 }
4662
4663 byte[] result = null;
4664 int length = 2;
4665 if (response.payload != null) {
4666 length = 2 + response.payload.length;
4667 result = new byte[length];
4668 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4669 } else {
4670 result = new byte[length];
4671 }
4672
4673 result[length - 1] = (byte) response.sw2;
4674 result[length - 2] = (byte) response.sw1;
4675 return result;
4676 } finally {
4677 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004678 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004679 }
4680
Nathan Haroldb3014052017-01-25 15:57:32 -08004681 /**
4682 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4683 * on a particular subscription
4684 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004685 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4686 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004688 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004689 return null;
4690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 if (appType != TelephonyManager.APPTYPE_USIM
4695 && appType != TelephonyManager.APPTYPE_SIM) {
4696 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4697 return null;
4698 }
4699 Object response = sendRequest(
4700 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4701 if (response instanceof String[]) {
4702 return (String[]) response;
4703 }
yincheng zhao2737e882019-09-06 17:06:54 -07004704 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004706 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004709 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004710 }
4711
yincheng zhao2737e882019-09-06 17:06:54 -07004712 /**
4713 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4714 * subscription.
4715 *
4716 * @param subId the id of the subscription.
4717 * @param appType the uicc app type, must be USIM or SIM.
4718 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4719 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004720 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004721 * @return number of fplmns that is successfully written to the SIM.
4722 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004723 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4724 String callingFeatureId) {
4725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4726 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004727 if (DBG) logv("no permissions for setForbiddenplmns");
4728 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4729 }
4730 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4731 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4732 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4733 }
4734 if (fplmns == null) {
4735 throw new IllegalArgumentException("Fplmn List provided is null");
4736 }
4737 for (String fplmn : fplmns) {
4738 if (!CellIdentity.isValidPlmn(fplmn)) {
4739 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4740 }
4741 }
4742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 Object response = sendRequest(
4745 CMD_SET_FORBIDDEN_PLMNS,
4746 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4747 subId);
4748 return (int) response;
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004754 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004755 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4757 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4762 if (response.payload == null) {
4763 return "";
4764 }
Evan Charltonc66da362014-05-16 14:06:40 -07004765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 // Append the returned status code to the end of the response payload.
4767 String s = Integer.toHexString(
4768 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4769 s = IccUtils.bytesToHexString(response.payload) + s;
4770 return s;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Evan Charltonc66da362014-05-16 14:06:40 -07004774 }
4775
Jake Hambye994d462014-02-03 13:10:13 -08004776 /**
4777 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4778 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4779 *
4780 * @param itemID the ID of the item to read
4781 * @return the NV item as a String, or null on error.
4782 */
4783 @Override
4784 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004792 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4794 return value;
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
4797 }
Jake Hambye994d462014-02-03 13:10:13 -08004798 }
4799
4800 /**
4801 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4802 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4803 *
4804 * @param itemID the ID of the item to read
4805 * @param itemValue the value to write, as a String
4806 * @return true on success; false on any failure
4807 */
4808 @Override
4809 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004810 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4817 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004818 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4820 return success;
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
Jake Hambye994d462014-02-03 13:10:13 -08004824 }
4825
4826 /**
4827 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4828 * Used for device configuration by some CDMA operators.
4829 *
4830 * @param preferredRoamingList byte array containing the new PRL
4831 * @return true on success; false on any failure
4832 */
4833 @Override
4834 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4836 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837
4838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4841 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4842 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4843 return success;
4844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
Jake Hambye994d462014-02-03 13:10:13 -08004847 }
4848
4849 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004850 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004851 * Used for device configuration by some CDMA operators.
4852 *
chen xu6dac5ab2018-10-26 17:39:23 -07004853 * @param slotIndex - device slot.
4854 *
Jake Hambye994d462014-02-03 13:10:13 -08004855 * @return true on success; false on any failure
4856 */
4857 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004858 public boolean resetModemConfig(int slotIndex) {
4859 Phone phone = PhoneFactory.getPhone(slotIndex);
4860 if (phone != null) {
4861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4862 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863
chen xu6dac5ab2018-10-26 17:39:23 -07004864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4867 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4868 return success;
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 }
chen xu6dac5ab2018-10-26 17:39:23 -07004873 return false;
4874 }
4875
4876 /**
4877 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4878 *
4879 * @param slotIndex - device slot.
4880 *
4881 * @return true on success; false on any failure
4882 */
4883 @Override
4884 public boolean rebootModem(int slotIndex) {
4885 Phone phone = PhoneFactory.getPhone(slotIndex);
4886 if (phone != null) {
4887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4888 mApp, phone.getSubId(), "rebootModem");
4889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4893 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4894 return success;
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
4898 }
4899 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004900 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004901
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004902 public String[] getPcscfAddress(String apnType, String callingPackage,
4903 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004904 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4906 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004907 return new String[0];
4908 }
4909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004912 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
Wink Saville36469e72014-06-11 15:17:00 -07004916 }
4917
Brad Ebinger51f743a2017-01-23 13:50:20 -08004918 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004919 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4920 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004921 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004922 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004923 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004927 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004928 // may happen if the device does not support IMS.
4929 return;
4930 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004931 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004935 }
4936
4937 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004938 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4939 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004940 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004941 public void disableIms(int slotId) {
4942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004946 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004947 // may happen if the device does not support IMS.
4948 return;
4949 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004950 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004954 }
4955
4956 /**
4957 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4958 * feature or {@link null} if the service is not available. If the feature is available, the
4959 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4960 */
4961 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004962 IImsServiceFeatureCallback callback) {
4963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964
4965 final long identity = Binder.clearCallingIdentity();
4966 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004967 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004968 // may happen if the device does not support IMS.
4969 return null;
4970 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004971 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004975 }
4976
4977 /**
4978 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4979 * feature during emergency calling or {@link null} if the service is not available. If the
4980 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4981 * listener for feature updates.
4982 */
4983 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985
4986 final long identity = Binder.clearCallingIdentity();
4987 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004988 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004989 // may happen if the device does not support IMS.
4990 return null;
4991 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004992 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004996 }
4997
Brad Ebinger5f64b052017-12-14 14:26:15 -08004998 /**
4999 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005000 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005001 */
5002 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005007 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005008 // may happen if the device does not support IMS.
5009 return null;
5010 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005011 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005015 }
5016
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005017 /**
5018 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005019 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005020 */
5021 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005026 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005027 // may happen if the device does not support IMS.
5028 return null;
5029 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005030 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005034 }
5035
Brad Ebinger884c07b2018-02-15 16:17:40 -08005036 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005037 * Sets the ImsService Package Name that Telephony will bind to.
5038 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005039 * @param slotIndex the slot ID that the ImsService should bind for.
5040 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005041 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005042 * @param featureTypes An integer array of feature types associated with a packageName.
5043 * @param packageName The name of the package that the current configuration will be replaced
5044 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005045 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005046 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005047 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5048 int[] featureTypes, String packageName) {
5049 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5052 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005053 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005057 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005058 // may happen if the device does not support IMS.
5059 return false;
5060 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 Map<Integer, String> featureConfig = new HashMap<>();
5062 for (int featureType : featureTypes) {
5063 featureConfig.put(featureType, packageName);
5064 }
5065 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5066 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005070 }
5071
5072 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005073 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005074 *
5075 * @param slotId The slot that the ImsService is associated with.
5076 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5077 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005079 * @return the package name of the ImsService configuration.
5080 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005081 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5082 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005083 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 TelephonyPermissions
5085 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5086 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5087 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005091 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005092 // may happen if the device does not support IMS.
5093 return "";
5094 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005095 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005096 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5097 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005101 }
5102
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005103 /**
5104 * Get the MmTelFeature state associated with the requested subscription id.
5105 * @param subId The subscription that the MmTelFeature is associated with.
5106 * @param callback A callback with an integer containing the
5107 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5108 */
5109 @Override
5110 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5111 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5112 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5113 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5114 "IMS not available on device.");
5115 }
5116 final long token = Binder.clearCallingIdentity();
5117 try {
5118 int slotId = getSlotIndex(subId);
5119 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5120 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5121 + subId + "'");
5122 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5123 }
5124 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5125 try {
5126 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5127 } catch (RemoteException e) {
5128 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5129 + "Ignore");
5130 }
5131 });
5132 } finally {
5133 Binder.restoreCallingIdentity(token);
5134 }
5135 }
5136
Wink Saville36469e72014-06-11 15:17:00 -07005137 public void setImsRegistrationState(boolean registered) {
5138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139
5140 final long identity = Binder.clearCallingIdentity();
5141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005142 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
Wink Saville36469e72014-06-11 15:17:00 -07005146 }
5147
5148 /**
Stuart Scott54788802015-03-30 13:18:01 -07005149 * Set the network selection mode to automatic.
5150 *
5151 */
5152 @Override
5153 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5155 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156
5157 final long identity = Binder.clearCallingIdentity();
5158 try {
shilufc958392020-01-20 11:36:01 -08005159 if (!isActiveSubscription(subId)) {
5160 return;
5161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5163 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
Stuart Scott54788802015-03-30 13:18:01 -07005167 }
5168
Pengquan Mengea84e042018-09-20 14:57:26 -07005169 /**
5170 * Ask the radio to connect to the input network and change selection mode to manual.
5171 *
5172 * @param subId the id of the subscription.
5173 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5174 * the operator to attach to.
5175 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5176 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5177 * normal network selection next time.
5178 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005179 */
5180 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005181 public boolean setNetworkSelectionModeManual(
5182 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5184 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005185
5186 if (!isActiveSubscription(subId)) {
5187 return false;
5188 }
5189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 final long identity = Binder.clearCallingIdentity();
5191 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005192 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005194 if (DBG) {
5195 log("setNetworkSelectionModeManual: subId: " + subId
5196 + " operator: " + operatorInfo);
5197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005202 }
shilu84f6e8b2019-12-19 13:58:01 -08005203 /**
5204 * Get the manual network selection
5205 *
5206 * @param subId the id of the subscription.
5207 *
5208 * @return the previously saved user selected PLMN
5209 */
5210 @Override
5211 public String getManualNetworkSelectionPlmn(int subId) {
5212 TelephonyPermissions
5213 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5214 mApp, subId, "getManualNetworkSelectionPlmn");
5215
5216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 if (!isActiveSubscription(subId)) {
5219 return "";
5220 }
5221
5222 final Phone phone = getPhone(subId);
5223 if (phone == null) {
5224 return "";
5225 }
5226 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5227 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5228 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
5232 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005233
5234 /**
5235 * Scans for available networks.
5236 */
5237 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005238 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5239 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5241 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005242 LocationAccessPolicy.LocationPermissionResult locationResult =
5243 LocationAccessPolicy.checkLocationPermission(mApp,
5244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5245 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005247 .setCallingPid(Binder.getCallingPid())
5248 .setCallingUid(Binder.getCallingUid())
5249 .setMethod("getCellNetworkScanResults")
5250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5251 .build());
5252 switch (locationResult) {
5253 case DENIED_HARD:
5254 throw new SecurityException("Not allowed to access scan results -- location");
5255 case DENIED_SOFT:
5256 return null;
5257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258
Pengquan Menga1bb6272018-09-06 09:59:22 -07005259 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 try {
5261 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005262 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005267 }
5268
5269 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005270 * Get the call forwarding info, given the call forwarding reason.
5271 */
5272 @Override
5273 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5274 enforceReadPrivilegedPermission("getCallForwarding");
5275 long identity = Binder.clearCallingIdentity();
5276 try {
5277 if (DBG) {
5278 log("getCallForwarding: subId " + subId
5279 + " callForwardingReason" + callForwardingReason);
5280 }
5281 return (CallForwardingInfo) sendRequest(
5282 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
5288 /**
5289 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5290 * reason, the number to forward, and the timeout before the forwarding is attempted.
5291 */
5292 @Override
5293 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5294 enforceModifyPermission();
5295 long identity = Binder.clearCallingIdentity();
5296 try {
5297 if (DBG) {
5298 log("setCallForwarding: subId " + subId
5299 + " callForwardingInfo" + callForwardingInfo);
5300 }
5301 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
5306
5307 /**
5308 * Get the call forwarding info, given the call forwarding reason.
5309 */
5310 @Override
5311 public int getCallWaitingStatus(int subId) {
5312 enforceReadPrivilegedPermission("getCallForwarding");
5313 long identity = Binder.clearCallingIdentity();
5314 try {
5315 if (DBG) log("getCallWaitingStatus: subId " + subId);
5316 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
5320 }
5321
5322 /**
5323 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5324 * reason, the number to forward, and the timeout before the forwarding is attempted.
5325 */
5326 @Override
5327 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5328 enforceModifyPermission();
5329 long identity = Binder.clearCallingIdentity();
5330 try {
5331 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5332 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
5336 }
5337
5338 /**
yinxub1bed742017-04-17 11:45:04 -07005339 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005340 *
yinxub1bed742017-04-17 11:45:04 -07005341 * @param subId id of the subscription
5342 * @param request contains the radio access networks with bands/channels to scan
5343 * @param messenger callback messenger for scan results or errors
5344 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005345 * @return the id of the requested scan which can be used to stop the scan.
5346 */
5347 @Override
5348 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005349 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5351 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005352 LocationAccessPolicy.LocationPermissionResult locationResult =
5353 LocationAccessPolicy.checkLocationPermission(mApp,
5354 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5355 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005356 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005357 .setCallingPid(Binder.getCallingPid())
5358 .setCallingUid(Binder.getCallingUid())
5359 .setMethod("requestNetworkScan")
5360 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5361 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005362 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005363 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005364 if (e != null) {
5365 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5366 throw e;
5367 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005368 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005369 return TelephonyScanManager.INVALID_SCAN_ID;
5370 }
5371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 }
Hall Liu912dfd32019-04-25 14:02:26 -07005373 int callingUid = Binder.getCallingUid();
5374 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 return mNetworkScanRequestTracker.startNetworkScan(
5378 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005379 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005380 } finally {
5381 Binder.restoreCallingIdentity(identity);
5382 }
yinxu504e1392017-04-12 16:03:22 -07005383 }
5384
Hall Liub2ac8ef2019-02-28 15:56:23 -08005385 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005386 NetworkScanRequest request, int subId) {
5387 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5388 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5389 boolean hasNetworkScanPermission =
5390 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5391 == PERMISSION_GRANTED;
5392
5393 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5394 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5395 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005396 }
5397
5398 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5399 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005400 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5401 return new SecurityException("Specific channels must not be"
5402 + " scanned without location access.");
5403 }
5404 }
5405 }
5406
Hall Liub2ac8ef2019-02-28 15:56:23 -08005407 return null;
5408 }
5409
yinxu504e1392017-04-12 16:03:22 -07005410 /**
5411 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005412 *
5413 * @param subId id of the subscription
5414 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005415 */
5416 @Override
5417 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5419 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420
Hall Liu912dfd32019-04-25 14:02:26 -07005421 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005424 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
yinxu504e1392017-04-12 16:03:22 -07005428 }
5429
5430 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005431 * Get the calculated preferred network type.
5432 * Used for debugging incorrect network type.
5433 *
5434 * @return the preferred network type, defined in RILConstants.java.
5435 */
5436 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005438 final Phone defaultPhone = getDefaultPhone();
5439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005440 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005441 return RILConstants.PREFERRED_NETWORK_MODE;
5442 }
5443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
5446 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005447 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
Junda Liu84d15a22014-07-02 11:21:04 -07005451 }
5452
5453 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005454 * Get the preferred network type.
5455 * Used for device configuration by some CDMA operators.
5456 *
5457 * @return the preferred network type, defined in RILConstants.java.
5458 */
5459 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005460 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005461 TelephonyPermissions
5462 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5463 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 if (DBG) log("getPreferredNetworkType");
5468 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5469 int networkType = (result != null ? result[0] : -1);
5470 if (DBG) log("getPreferredNetworkType: " + networkType);
5471 return networkType;
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005475 }
5476
5477 /**
5478 * Set the preferred network type.
5479 * Used for device configuration by some CDMA operators.
5480 *
5481 * @param networkType the preferred network type, defined in RILConstants.java.
5482 * @return true on success; false on any failure.
5483 */
5484 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005485 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5487 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005491 Settings.Global.putInt(mApp.getContentResolver(),
5492 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5493 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 } finally {
5495 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005496 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005497 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005498
5499 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005500 * Get the allowed network types that store in the telephony provider.
5501 *
5502 * @param subId the id of the subscription.
5503 * @return allowedNetworkTypes the allowed network types.
5504 */
5505 @Override
5506 public long getAllowedNetworkTypes(int subId) {
5507 TelephonyPermissions
5508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5509 mApp, subId, "getAllowedNetworkTypes");
5510
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 return SubscriptionManager.getLongSubscriptionProperty(
5514 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 }
5519
5520 /**
5521 * Set the allowed network types.
5522 *
5523 * @param subId the id of the subscription.
5524 * @param allowedNetworkTypes the allowed network types.
5525 * @return true on success; false on any failure.
5526 */
5527 @Override
5528 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5530 mApp, subId, "setAllowedNetworkTypes");
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 SubscriptionManager.setSubscriptionProperty(subId,
5534 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5535 String.valueOf(allowedNetworkTypes));
5536 return setPreferredNetworkTypesInternal(subId);
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
5540 }
5541
5542 private boolean setPreferredNetworkTypesInternal(int subId) {
5543 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5544 Settings.Global.getInt(mApp.getContentResolver(),
5545 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5546 RILConstants.PREFERRED_NETWORK_MODE));
5547 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5548 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5549 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5550 (int) (networkTypeBitMask & allowedNetworkTypes));
5551
5552 if (DBG) {
5553 log("setPreferredNetworkTypesInternal: subId " + subId
5554 + " networkTypes " + networkTypeBitMask
5555 + " allowedNetworkTypes " + allowedNetworkTypes
5556 + " networkMode " + networkMode);
5557 }
5558
5559 Boolean success = (Boolean) sendRequest(
5560 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5561 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5562 return success;
5563 }
5564
5565 /**
Miaoa84611c2019-03-15 09:21:10 +08005566 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005567 *
Miaoa84611c2019-03-15 09:21:10 +08005568 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005569 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005570 * @hide
5571 */
5572 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005573 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005576 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 try {
Miaoa84611c2019-03-15 09:21:10 +08005578 if (phone != null) {
5579 return phone.hasMatchedTetherApnSetting();
5580 } else {
5581 return false;
5582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005585 }
Junda Liu475951f2014-11-07 16:45:03 -08005586 }
5587
5588 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005589 * Set mobile data enabled
5590 * Used by the user through settings etc to turn on/off mobile data
5591 *
5592 * @param enable {@code true} turn turn data on, else {@code false}
5593 */
5594 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005595 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5597 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598
5599 final long identity = Binder.clearCallingIdentity();
5600 try {
5601 int phoneId = mSubscriptionController.getPhoneId(subId);
5602 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5603 Phone phone = PhoneFactory.getPhone(phoneId);
5604 if (phone != null) {
5605 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005606 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 }
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005612 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005613 }
5614
5615 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005616 * Enable or disable always reporting signal strength changes from radio.
5617 *
5618 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5619 */
5620 @Override
5621 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5622 enforceModifyPermission();
5623 enforceSystemCaller();
5624
5625 final long identity = Binder.clearCallingIdentity();
5626 final Phone phone = getPhone(subId);
5627 try {
5628 if (phone != null) {
5629 if (DBG) {
5630 log("setAlwaysReportSignalStrength: subId=" + subId
5631 + " isEnable=" + isEnable);
5632 }
5633 phone.setAlwaysReportSignalStrength(isEnable);
5634 } else {
5635 loge("setAlwaysReportSignalStrength: no phone found for subId="
5636 + subId);
5637 }
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
5641 }
5642
5643 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005644 * Get the user enabled state of Mobile Data.
5645 *
5646 * TODO: remove and use isUserDataEnabled.
5647 * This can't be removed now because some vendor codes
5648 * calls through ITelephony directly while they should
5649 * use TelephonyManager.
5650 *
5651 * @return true on enabled
5652 */
5653 @Override
5654 public boolean getDataEnabled(int subId) {
5655 return isUserDataEnabled(subId);
5656 }
5657
5658 /**
5659 * Get whether mobile data is enabled per user setting.
5660 *
5661 * There are other factors deciding whether mobile data is actually enabled, but they are
5662 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005663 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005664 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005665 *
5666 * @return {@code true} if data is enabled else {@code false}
5667 */
5668 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005669 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005670 try {
5671 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5672 null);
5673 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5675 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 int phoneId = mSubscriptionController.getPhoneId(subId);
5681 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5682 Phone phone = PhoneFactory.getPhone(phoneId);
5683 if (phone != null) {
5684 boolean retVal = phone.isUserDataEnabled();
5685 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5686 return retVal;
5687 } else {
5688 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5689 return false;
5690 }
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005693 }
5694 }
5695
5696 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005697 * Checks if the device is capable of mobile data by considering whether whether the
5698 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5699 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005700 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005701 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005702 */
5703 @Override
5704 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005705 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706
5707 final long identity = Binder.clearCallingIdentity();
5708 try {
5709 int phoneId = mSubscriptionController.getPhoneId(subId);
5710 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5711 Phone phone = PhoneFactory.getPhone(phoneId);
5712 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005713 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5715 return retVal;
5716 } else {
5717 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5718 return false;
5719 }
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005722 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005723 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005724
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005725 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5726 Phone phone) {
5727 //load access rules from carrier configs, and check those as well: b/139133814
5728 SubscriptionController subController = SubscriptionController.getInstance();
5729 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5730 || subController == null) return privilegeFromSim;
5731
5732 int uid = Binder.getCallingUid();
5733 PackageManager pkgMgr = phone.getContext().getPackageManager();
5734 String[] packages = pkgMgr.getPackagesForUid(uid);
5735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5739 SubscriptionManager subManager = (SubscriptionManager)
5740 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5741 for (String pkg : packages) {
5742 if (subManager.canManageSubscription(subInfo, pkg)) {
5743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5744 }
5745 }
5746 return privilegeFromSim;
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
5751
5752 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5753 String pkgName) {
5754 //load access rules from carrier configs, and check those as well: b/139133814
5755 SubscriptionController subController = SubscriptionController.getInstance();
5756 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5757 || subController == null) return privilegeFromSim;
5758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5762 SubscriptionManager subManager = (SubscriptionManager)
5763 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5764 return subManager.canManageSubscription(subInfo, pkgName)
5765 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 }
5770
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005771 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005772 public int getCarrierPrivilegeStatus(int subId) {
5773 final Phone phone = getPhone(subId);
5774 if (phone == null) {
5775 loge("getCarrierPrivilegeStatus: Invalid subId");
5776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5777 }
5778 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005779 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005780 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5782 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005783
5784 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5785 card.getCarrierPrivilegeStatusForCurrentTransaction(
5786 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005787 }
Junda Liu29340342014-07-10 15:23:27 -07005788
5789 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005790 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005791 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005792 final Phone phone = getPhone(subId);
5793 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005794 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5796 }
5797 UiccProfile profile =
5798 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5799 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005800 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5802 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005803 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005804 profile.getCarrierPrivilegeStatusForUid(
5805 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005806 }
5807
5808 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005809 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5810 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005812 }
5813
5814 int phoneId = SubscriptionManager.getPhoneId(subId);
5815 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005816 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005817 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005818 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5819 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005820 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5821 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5822 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005823 }
5824
5825 @Override
5826 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005827 if (TextUtils.isEmpty(pkgName))
5828 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005829 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5830 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5831 UiccCard card = UiccController.getInstance().getUiccCard(i);
5832 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005833 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005834 continue;
5835 }
5836
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005837 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5838 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5839 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005840 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5841 break;
5842 }
5843 }
5844
5845 return result;
Junda Liu29340342014-07-10 15:23:27 -07005846 }
Derek Tan89e89d42014-07-08 17:00:10 -07005847
5848 @Override
Junda Liue64de782015-04-16 17:19:16 -07005849 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5850 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5851 loge("phoneId " + phoneId + " is not valid.");
5852 return null;
5853 }
5854 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005855 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005856 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005857 return null ;
5858 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005859 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005860 }
5861
Amith Yamasani6e118872016-02-19 12:53:51 -08005862 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005863 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005864 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005865 List<String> privilegedPackages = new ArrayList<>();
5866 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005867 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5868 // has UICC in that slot.
5869 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005870 if (card.hasCarrierPrivilegeRules()) {
5871 if (packages == null) {
5872 // Only check packages in user 0 for now
5873 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005874 PackageManager.MATCH_DISABLED_COMPONENTS
5875 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005876 | PackageManager.GET_SIGNING_CERTIFICATES,
5877 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005878 }
5879 for (int p = packages.size() - 1; p >= 0; p--) {
5880 PackageInfo pkgInfo = packages.get(p);
5881 if (pkgInfo != null && pkgInfo.packageName != null
5882 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005883 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005884 privilegedPackages.add(pkgInfo.packageName);
5885 }
5886 }
5887 }
5888 }
5889 return privilegedPackages;
5890 }
5891
chen xuf7e9fe82019-05-09 19:31:02 -07005892 @Override
5893 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005894 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5895
5896 final long identity = Binder.clearCallingIdentity();
5897
chen xuf7e9fe82019-05-09 19:31:02 -07005898 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005899 try {
5900 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5901 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5902 }
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005905 }
5906 return privilegedPackages;
5907 }
5908
Wink Savilleb564aae2014-10-23 10:18:09 -07005909 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005910 final Phone phone = getPhone(subId);
5911 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005912 if (card == null) {
5913 loge("getIccId: No UICC");
5914 return null;
5915 }
5916 String iccId = card.getIccId();
5917 if (TextUtils.isEmpty(iccId)) {
5918 loge("getIccId: ICC ID is null or empty.");
5919 return null;
5920 }
5921 return iccId;
5922 }
5923
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005924 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005925 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5926 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005928 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 final String iccId = getIccId(subId);
5933 final Phone phone = getPhone(subId);
5934 if (phone == null) {
5935 return false;
5936 }
5937 final String subscriberId = phone.getSubscriberId();
5938
5939 if (DBG_MERGE) {
5940 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5941 + subscriberId + " to " + number);
5942 }
5943
5944 if (TextUtils.isEmpty(iccId)) {
5945 return false;
5946 }
5947
5948 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5949
5950 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5951 if (alphaTag == null) {
5952 editor.remove(alphaTagPrefKey);
5953 } else {
5954 editor.putString(alphaTagPrefKey, alphaTag);
5955 }
5956
5957 // Record both the line number and IMSI for this ICCID, since we need to
5958 // track all merged IMSIs based on line number
5959 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5960 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5961 if (number == null) {
5962 editor.remove(numberPrefKey);
5963 editor.remove(subscriberPrefKey);
5964 } else {
5965 editor.putString(numberPrefKey, number);
5966 editor.putString(subscriberPrefKey, subscriberId);
5967 }
5968
5969 editor.commit();
5970 return true;
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005973 }
Derek Tan7226c842014-07-02 17:42:23 -07005974 }
5975
5976 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005977 public String getLine1NumberForDisplay(int subId, String callingPackage,
5978 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005979 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005981 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005982 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005983 return null;
5984 }
Derek Tan97ebb422014-09-05 16:55:38 -07005985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 String iccId = getIccId(subId);
5989 if (iccId != null) {
5990 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5991 if (DBG_MERGE) {
5992 log("getLine1NumberForDisplay returning "
5993 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5994 }
5995 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5998 return null;
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006001 }
Derek Tan7226c842014-07-02 17:42:23 -07006002 }
6003
6004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006005 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6006 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006008 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006009 return null;
6010 }
Derek Tan97ebb422014-09-05 16:55:38 -07006011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 final long identity = Binder.clearCallingIdentity();
6013 try {
6014 String iccId = getIccId(subId);
6015 if (iccId != null) {
6016 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6017 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6018 }
6019 return null;
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006022 }
Derek Tan7226c842014-07-02 17:42:23 -07006023 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006024
6025 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006026 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6027 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006028 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6029 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006031 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006032 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006033 return null;
6034 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006035
Jordan Liub49b04b2019-05-06 14:45:15 -07006036 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6037 // the process, where TelephonyManager was instantiated.
6038 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006039 final long identity = Binder.clearCallingIdentity();
6040 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006041 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final TelephonyManager tele = TelephonyManager.from(context);
6043 final SubscriptionManager sub = SubscriptionManager.from(context);
6044
6045 // Figure out what subscribers are currently active
6046 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047
Jordan Liub49b04b2019-05-06 14:45:15 -07006048 // Only consider subs which match the current subId
6049 // This logic can be simplified. See b/131189269 for progress.
6050 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006051 activeSubscriberIds.add(tele.getSubscriberId(subId));
6052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 // First pass, find a number override for an active subscriber
6055 String mergeNumber = null;
6056 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6057 for (String key : prefs.keySet()) {
6058 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6059 final String subscriberId = (String) prefs.get(key);
6060 if (activeSubscriberIds.contains(subscriberId)) {
6061 final String iccId = key.substring(
6062 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6063 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6064 mergeNumber = (String) prefs.get(numberKey);
6065 if (DBG_MERGE) {
6066 Slog.d(LOG_TAG, "Found line number " + mergeNumber
6067 + " for active subscriber " + subscriberId);
6068 }
6069 if (!TextUtils.isEmpty(mergeNumber)) {
6070 break;
6071 }
6072 }
6073 }
6074 }
6075
6076 // Shortcut when no active merged subscribers
6077 if (TextUtils.isEmpty(mergeNumber)) {
6078 return null;
6079 }
6080
6081 // Second pass, find all subscribers under that line override
6082 final ArraySet<String> result = new ArraySet<>();
6083 for (String key : prefs.keySet()) {
6084 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6085 final String number = (String) prefs.get(key);
6086 if (mergeNumber.equals(number)) {
6087 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6088 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6089 final String subscriberId = (String) prefs.get(subscriberKey);
6090 if (!TextUtils.isEmpty(subscriberId)) {
6091 result.add(subscriberId);
6092 }
6093 }
6094 }
6095 }
6096
6097 final String[] resultArray = result.toArray(new String[result.size()]);
6098 Arrays.sort(resultArray);
6099 if (DBG_MERGE) {
6100 Slog.d(LOG_TAG,
6101 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6102 }
6103 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006104 } finally {
6105 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006106 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006107 }
6108
6109 @Override
zoey chen38003472019-12-13 17:16:31 +08006110 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6111 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006112
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 final TelephonyManager telephonyManager = mApp.getSystemService(
6116 TelephonyManager.class);
6117 String subscriberId = telephonyManager.getSubscriberId(subId);
6118 if (subscriberId == null) {
6119 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006120 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006121 + subId);
6122 }
6123 return null;
6124 }
6125
6126 final SubscriptionInfo info = SubscriptionController.getInstance()
6127 .getSubscriptionInfo(subId);
6128 final ParcelUuid groupUuid = info.getGroupUuid();
6129 // If it doesn't belong to any group, return just subscriberId of itself.
6130 if (groupUuid == null) {
6131 return new String[]{subscriberId};
6132 }
6133
6134 // Get all subscriberIds from the group.
6135 final List<String> mergedSubscriberIds = new ArrayList<>();
6136 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006137 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6138 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006139 for (SubscriptionInfo subInfo : groupInfos) {
6140 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6141 if (subscriberId != null) {
6142 mergedSubscriberIds.add(subscriberId);
6143 }
6144 }
6145
6146 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6147 } finally {
6148 Binder.restoreCallingIdentity(identity);
6149
6150 }
6151 }
6152
6153 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006154 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006155 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006156 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157
6158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 final Phone phone = getPhone(subId);
6161 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006165 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006166
6167 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006168 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006169 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6170 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006171 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6172 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 final Phone phone = getPhone(subId);
6177 if (phone == null) {
6178 return false;
6179 }
6180 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6181 cdmaNonRoamingList);
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006184 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006185 }
6186
6187 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006188 @Deprecated
6189 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6190 enforceModifyPermission();
6191
6192 int returnValue = 0;
6193 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006194 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006195 if(result.exception == null) {
6196 if (result.result != null) {
6197 byte[] responseData = (byte[])(result.result);
6198 if(responseData.length > oemResp.length) {
6199 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6200 responseData.length + "bytes. Buffer Size is " +
6201 oemResp.length + "bytes.");
6202 }
6203 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6204 returnValue = responseData.length;
6205 }
6206 } else {
6207 CommandException ex = (CommandException) result.exception;
6208 returnValue = ex.getCommandError().ordinal();
6209 if(returnValue > 0) returnValue *= -1;
6210 }
6211 } catch (RuntimeException e) {
6212 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6213 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6214 if(returnValue > 0) returnValue *= -1;
6215 }
6216
6217 return returnValue;
6218 }
6219
6220 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006221 public void setRadioCapability(RadioAccessFamily[] rafs) {
6222 try {
6223 ProxyController.getInstance().setRadioCapability(rafs);
6224 } catch (RuntimeException e) {
6225 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6226 }
6227 }
6228
6229 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006230 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006231 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006232 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006233 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006234 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 final long identity = Binder.clearCallingIdentity();
6237 try {
chen xub97461a2018-10-26 14:17:57 -07006238 TelephonyPermissions
6239 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6240 mApp, phone.getSubId(), "getRadioAccessFamily");
6241 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 } finally {
6243 Binder.restoreCallingIdentity(identity);
6244 }
chen xub97461a2018-10-26 14:17:57 -07006245 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006246 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006247
6248 @Override
6249 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006250 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252
6253 final long identity = Binder.clearCallingIdentity();
6254 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006255 ImsManager.getInstance(defaultPhone.getContext(),
6256 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006260 }
6261
6262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006263 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006264 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6266 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006267 return false;
6268 }
Svet Ganovb320e182015-04-16 12:30:10 -07006269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 // Check the user preference and the system-level IMS setting. Even if the user has
6273 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6274 // In the long run, we may instead need to check if there exists a connection service
6275 // which can support video calling.
6276 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006277 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 return imsManager.isVtEnabledByPlatform()
6279 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6280 && imsManager.isVtEnabledByUser();
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006284 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006285
Andrew Leea1239f22015-03-02 17:44:07 -08006286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006287 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6288 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006290 mApp, subId, callingPackage, callingFeatureId,
6291 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 return false;
6293 }
6294
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 CarrierConfigManager configManager =
6298 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006299 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
Andrew Leea1239f22015-03-02 17:44:07 -08006304 }
6305
6306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006307 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006309 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 return false;
6311 }
6312
6313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 CarrierConfigManager configManager =
6316 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006317 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
Andrew Leea1239f22015-03-02 17:44:07 -08006322 }
6323
Andrew Lee9431b832015-03-09 18:46:45 -07006324 @Override
6325 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006326 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006327 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006328 }
6329
6330 @Override
6331 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 final long identity = Binder.clearCallingIdentity();
6333 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006334 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Andrew Lee9431b832015-03-09 18:46:45 -07006338 }
6339
Hall Liuf6668912018-10-31 17:05:23 -07006340 /**
6341 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6342 * support for the feature and device firmware support.
6343 *
6344 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6345 */
6346 @Override
6347 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006349 final Phone phone = getPhone(subscriptionId);
6350 if (phone == null) {
6351 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6352 return false;
6353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006355 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6357 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006358 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 return isCarrierSupported && isDeviceSupported;
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
6362 }
Hall Liu98187582018-01-22 19:15:32 -08006363 }
6364
Hall Liuf6668912018-10-31 17:05:23 -07006365 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006366 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6367 * RTT setting, will return true if the device and carrier both support RTT.
6368 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006369 */
6370 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 final long identity = Binder.clearCallingIdentity();
6372 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006373 boolean isRttSupported = isRttSupported(subscriptionId);
6374 boolean isUserRttSettingOn = Settings.Secure.getInt(
6375 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6376 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6377 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6378 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006382 }
6383
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006384 @Deprecated
6385 @Override
6386 public String getDeviceId(String callingPackage) {
6387 return getDeviceIdWithFeature(callingPackage, null);
6388 }
6389
Sanket Padawe7310cc72015-01-14 09:53:20 -08006390 /**
6391 * Returns the unique device ID of phone, for example, the IMEI for
6392 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6393 *
6394 * <p>Requires Permission:
6395 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6396 */
6397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006398 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006399 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006400 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006401 return null;
6402 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006403 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006404 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006405 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006406 return null;
6407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 return phone.getDeviceId();
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006415 }
6416
Ping Sunc67b7c22016-03-02 19:16:45 +08006417 /**
6418 * {@hide}
6419 * Returns the IMS Registration Status on a particular subid
6420 *
6421 * @param subId
6422 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006423 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006424 Phone phone = getPhone(subId);
6425 if (phone != null) {
6426 return phone.isImsRegistered();
6427 } else {
6428 return false;
6429 }
6430 }
6431
Santos Cordon7a1885b2015-02-03 11:15:19 -08006432 @Override
6433 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 final long identity = Binder.clearCallingIdentity();
6435 try {
6436 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006440 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006441
Tyler Gunnf70ed162019-04-03 15:28:53 -07006442 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006443 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006444 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006446 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006447 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6448 }
6449 final long identity = Binder.clearCallingIdentity();
6450 try {
6451 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
6456
6457 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006458 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6459 final long identity = Binder.clearCallingIdentity();
6460 try {
6461 Phone phone = getPhone(subscriptionId);
6462 if (phone == null) {
6463 return null;
6464 }
6465 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006471 /**
6472 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006473 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006474 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 final long identity = Binder.clearCallingIdentity();
6476 try {
6477 Phone phone = getPhone(subId);
6478 if (phone != null) {
6479 return phone.isWifiCallingEnabled();
6480 } else {
6481 return false;
6482 }
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006485 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006486 }
6487
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006488 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006489 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006490 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006491 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 Phone phone = getPhone(subId);
6495 if (phone != null) {
6496 return phone.isVideoEnabled();
6497 } else {
6498 return false;
6499 }
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006502 }
6503 }
6504
6505 /**
6506 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6507 * defined in {@link ImsRegistrationImplBase}.
6508 */
6509 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 final long identity = Binder.clearCallingIdentity();
6511 try {
6512 Phone phone = getPhone(subId);
6513 if (phone != null) {
6514 return phone.getImsRegistrationTech();
6515 } else {
6516 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6517 }
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006520 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006521 }
6522
Stuart Scott8eef64f2015-04-08 15:13:54 -07006523 @Override
6524 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006525 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006526 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6527 return;
6528 }
6529
Svet Ganovcc087f82015-05-12 20:35:54 -07006530 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006531
Svet Ganovcc087f82015-05-12 20:35:54 -07006532 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006533 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6534 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006535 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006536 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006537 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006538 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6539 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006540 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006541 // There has been issues when Sms raw table somehow stores orphan
6542 // fragments. They lead to garbled message when new fragments come
6543 // in and combined with those stale ones. In case this happens again,
6544 // user can reset all network settings which will clean up this table.
6545 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006546 // Clean up IMS settings as well here.
6547 int slotId = getSlotIndex(subId);
6548 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6549 ImsManager.getInstance(mApp, slotId).factoryReset();
6550 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006551
6552 // Erase modem config if erase modem on network setting is enabled.
6553 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6554 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6555 if (configValue != null && Boolean.parseBoolean(configValue)) {
6556 sendEraseModemConfig(getDefaultPhone());
6557 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006560 }
6561 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006562
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006563 private void cleanUpSmsRawTable(Context context) {
6564 ContentResolver resolver = context.getContentResolver();
6565 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6566 resolver.delete(uri, null, null);
6567 }
6568
Narayan Kamath1c496c22015-04-16 14:40:19 +01006569 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006570 public String getSimLocaleForSubscriber(int subId) {
6571 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6572 final Phone phone = getPhone(subId);
6573 if (phone == null) {
6574 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006575 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 final long identity = Binder.clearCallingIdentity();
6578 try {
chen xu5d3637b2019-01-21 23:31:38 -08006579 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006580 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006581 if (info == null) {
6582 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6583 return null;
6584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 // Try and fetch the locale from the carrier properties or from the SIM language
6586 // preferences (EF-PL and EF-LI)...
6587 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006589 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6590 if (localeFromDefaultSim != null) {
6591 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6592 if (DBG) log("Using locale from subId: " + subId + " locale: "
6593 + localeFromDefaultSim);
6594 return localeFromDefaultSim.toLanguageTag();
6595 } else {
6596 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 }
6598 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 // The SIM language preferences only store a language (e.g. fr = French), not an
6601 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6602 // the SIM and carrier preferences does not include a country we add the country
6603 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006604 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006606 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 return mccLocale.toLanguageTag();
6608 }
6609
6610 if (DBG) log("No locale found - returning null");
6611 return null;
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006615 }
6616
6617 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006618 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6619 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006620 }
6621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 /**
6623 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6624 */
6625 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006626 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6627 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006628 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006629
Chenjie Yu1ba97252018-01-11 18:16:20 -08006630 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006631 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006632
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006633 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006634 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6635 * representing the state of the modem.
6636 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006637 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6638 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006639 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006640 */
6641 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006642 public void requestModemActivityInfo(ResultReceiver result) {
6643 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006644 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 ModemActivityInfo ret = null;
6649 synchronized (mLastModemActivityInfo) {
6650 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6651 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006652 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006653 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006655 int[] txTimeMs = info.getTransmitTimeMillis();
6656 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006658 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 }
6660 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006661 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6662 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 mLastModemActivityInfo.setIdleTimeMillis(
6664 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006665 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6666 mLastModemActivityInfo.setReceiveTimeMillis(
6667 info.getReceiveTimeMillis() + mLastModemActivityInfo
6668 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006669 }
Chen Xud78231e2019-09-10 18:49:52 -07006670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6672 mLastModemActivityInfo.getSleepTimeMillis(),
6673 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006674 mLastModemActivityInfo.getTransmitTimeMillis(),
6675 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 Bundle bundle = new Bundle();
6678 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6679 result.send(0, bundle);
6680 } finally {
6681 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006682 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006683 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006684
Siddharth Rayb8114062018-06-17 15:02:38 -07006685 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6686 // less than total activity duration.
6687 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6688 if (info == null) {
6689 return false;
6690 }
6691 int activityDurationMs =
6692 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6693 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006694 int[] txTimeMs = info.getTransmitTimeMillis();
6695 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6696 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006697 }
6698 return (info.isValid()
6699 && (info.getSleepTimeMillis() <= activityDurationMs)
6700 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006701 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006702 && (totalTxTimeMs <= activityDurationMs));
6703 }
6704
Jack Yu85bd38a2015-11-09 11:34:32 -08006705 /**
6706 * {@hide}
6707 * Returns the service state information on specified subscription.
6708 */
6709 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006710 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6711 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006713 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006714 return null;
6715 }
6716
Hall Liuf19c44f2018-11-27 14:38:17 -08006717 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6718 LocationAccessPolicy.checkLocationPermission(mApp,
6719 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6720 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006721 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006722 .setCallingPid(Binder.getCallingPid())
6723 .setCallingUid(Binder.getCallingUid())
6724 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006725 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006726 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6727 .build());
6728
6729 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6730 LocationAccessPolicy.checkLocationPermission(mApp,
6731 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6732 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006733 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006734 .setCallingPid(Binder.getCallingPid())
6735 .setCallingUid(Binder.getCallingUid())
6736 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006737 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006738 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6739 .build());
6740 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6741 boolean hasFinePermission =
6742 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6743 boolean hasCoarsePermission =
6744 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 final Phone phone = getPhone(subId);
6749 if (phone == null) {
6750 return null;
6751 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006752
Hall Liuf19c44f2018-11-27 14:38:17 -08006753 ServiceState ss = phone.getServiceState();
6754
6755 // Scrub out the location info in ServiceState depending on what level of access
6756 // the caller has.
6757 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006758 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6759 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006763 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006764
6765 /**
6766 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6767 *
6768 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6769 * voicemail ringtone.
6770 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6771 * PhoneAccount.
6772 */
6773 @Override
6774 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6778 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006779 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006786 }
6787
6788 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006789 * Sets the per-account voicemail ringtone.
6790 *
6791 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6792 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6793 *
6794 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6795 * voicemail ringtone.
6796 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6797 * PhoneAccount.
6798 */
6799 @Override
6800 public void setVoicemailRingtoneUri(String callingPackage,
6801 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006802 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006803 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006804 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6805 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6807 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6808 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810
6811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6814 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006815 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 }
6817 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006820 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006821 }
6822
6823 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006824 * Returns whether vibration is set for voicemail notification in Phone settings.
6825 *
6826 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6827 * voicemail vibration setting.
6828 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6829 */
6830 @Override
6831 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6835 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006836 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006843 }
6844
Youhan Wange64578a2016-05-02 15:32:42 -07006845 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006846 * Sets the per-account voicemail vibration.
6847 *
6848 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6849 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6850 *
6851 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6852 * voicemail vibration setting.
6853 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6854 * specific PhoneAccount.
6855 */
6856 @Override
6857 public void setVoicemailVibrationEnabled(String callingPackage,
6858 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006859 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006861 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6862 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6864 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6865 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006866 }
6867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6871 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006872 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 }
6874 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006877 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006878 }
6879
6880 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006881 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6882 *
6883 * @throws SecurityException if the caller does not have the required permission
6884 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006885 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006886 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006887 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006888 }
6889
6890 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006891 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6892 * permission.
6893 *
6894 * @throws SecurityException if the caller does not have the required permission
6895 */
6896 private void enforceSendSmsPermission() {
6897 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6898 }
6899
6900 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006901 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006902 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006903 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006904 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006905 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006909 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 if (componentName == null) {
6911 throw new SecurityException(
6912 "Caller not current active visual voicemail package[null]");
6913 }
6914 String vvmPackage = componentName.getPackageName();
6915 if (!callingPackage.equals(vvmPackage)) {
6916 throw new SecurityException("Caller not current active visual voicemail package["
6917 + vvmPackage + "]");
6918 }
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006921 }
6922 }
6923
6924 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006925 * Return the application ID for the app type.
6926 *
6927 * @param subId the subscription ID that this request applies to.
6928 * @param appType the uicc app type.
6929 * @return Application ID for specificied app type, or null if no uicc.
6930 */
6931 @Override
6932 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006933 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006934 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935
6936 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006937 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 if (phone == null) {
6939 return null;
6940 }
6941 String aid = null;
6942 try {
6943 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6944 .getApplicationByType(appType).getAid();
6945 } catch (Exception e) {
6946 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6947 }
6948 return aid;
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006951 }
Youhan Wange64578a2016-05-02 15:32:42 -07006952 }
6953
Youhan Wang4001d252016-05-11 10:29:41 -07006954 /**
6955 * Return the Electronic Serial Number.
6956 *
6957 * @param subId the subscription ID that this request applies to.
6958 * @return ESN or null if error.
6959 */
6960 @Override
6961 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006962 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006963 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964
6965 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006966 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 if (phone == null) {
6968 return null;
6969 }
6970 String esn = null;
6971 try {
6972 esn = phone.getEsn();
6973 } catch (Exception e) {
6974 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6975 }
6976 return esn;
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006979 }
Youhan Wang4001d252016-05-11 10:29:41 -07006980 }
6981
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006982 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006983 * Return the Preferred Roaming List Version.
6984 *
6985 * @param subId the subscription ID that this request applies to.
6986 * @return PRLVersion or null if error.
6987 */
6988 @Override
6989 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006990 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006991 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992
6993 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006994 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 if (phone == null) {
6996 return null;
6997 }
6998 String cdmaPrlVersion = null;
6999 try {
7000 cdmaPrlVersion = phone.getCdmaPrlVersion();
7001 } catch (Exception e) {
7002 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7003 }
7004 return cdmaPrlVersion;
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007007 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007008 }
7009
7010 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007011 * Get snapshot of Telephony histograms
7012 * @return List of Telephony histograms
7013 * @hide
7014 */
7015 @Override
7016 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7018 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 return RIL.getTelephonyRILTimingHistograms();
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007026 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007027
7028 /**
7029 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007030 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7031 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007032 * Require system privileges. In the future we may add this to carrier APIs.
7033 *
Michele Berionne482f8202018-11-27 18:57:59 -08007034 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007035 */
7036 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007037 @TelephonyManager.SetCarrierRestrictionResult
7038 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007039 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007040 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007041
Michele Berionne482f8202018-11-27 18:57:59 -08007042 if (carrierRestrictionRules == null) {
7043 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007044 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 final long identity = Binder.clearCallingIdentity();
7047 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007048 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007049 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007053 }
7054
7055 /**
7056 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007057 * Get the allowed carrier list and the excluded carrier list, including the priority between
7058 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007059 * Require system privileges. In the future we may add this to carrier APIs.
7060 *
Michele Berionne482f8202018-11-27 18:57:59 -08007061 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007062 */
7063 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007064 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007065 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007070 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7071 if (response instanceof CarrierRestrictionRules) {
7072 return (CarrierRestrictionRules) response;
7073 }
7074 // Response is an Exception of some kind,
7075 // which is signalled to the user as a NULL retval
7076 return null;
7077 } catch (Exception e) {
7078 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7079 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007083 }
7084
fionaxu59545b42016-05-25 15:53:37 -07007085 /**
7086 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7087 * @param subId the subscription ID that this action applies to.
7088 * @param enabled control enable or disable metered apns.
7089 * {@hide}
7090 */
7091 @Override
7092 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7093 enforceModifyPermission();
7094 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095
7096 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007097 if (phone == null) {
7098 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7099 return;
7100 }
7101 try {
7102 phone.carrierActionSetMeteredApnsEnabled(enabled);
7103 } catch (Exception e) {
7104 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 } finally {
7106 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007107 }
7108 }
7109
7110 /**
7111 * Action set from carrier signalling broadcast receivers to enable/disable radio
7112 * @param subId the subscription ID that this action applies to.
7113 * @param enabled control enable or disable radio.
7114 * {@hide}
7115 */
7116 @Override
7117 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7118 enforceModifyPermission();
7119 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120
7121 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007122 if (phone == null) {
7123 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7124 return;
7125 }
7126 try {
7127 phone.carrierActionSetRadioEnabled(enabled);
7128 } catch (Exception e) {
7129 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 } finally {
7131 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007132 }
7133 }
7134
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007135 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007136 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7137 * network status based on which carrier apps could apply actions accordingly,
7138 * enable/disable default url handler for example.
7139 *
7140 * @param subId the subscription ID that this action applies to.
7141 * @param report control start/stop reporting the default network status.
7142 * {@hide}
7143 */
7144 @Override
7145 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7146 enforceModifyPermission();
7147 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007150 if (phone == null) {
7151 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7152 return;
7153 }
7154 try {
7155 phone.carrierActionReportDefaultNetworkStatus(report);
7156 } catch (Exception e) {
7157 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 } finally {
7159 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007160 }
7161 }
7162
7163 /**
fionaxud9622282017-07-17 17:51:30 -07007164 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7165 * @param subId the subscription ID that this action applies to.
7166 * {@hide}
7167 */
7168 @Override
7169 public void carrierActionResetAll(int subId) {
7170 enforceModifyPermission();
7171 final Phone phone = getPhone(subId);
7172 if (phone == null) {
7173 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7174 return;
7175 }
7176 try {
7177 phone.carrierActionResetAll();
7178 } catch (Exception e) {
7179 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7180 }
7181 }
7182
7183 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007184 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7185 * bug report is being generated.
7186 */
7187 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007188 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007189 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7190 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007191 writer.println("Permission Denial: can't dump Phone from pid="
7192 + Binder.getCallingPid()
7193 + ", uid=" + Binder.getCallingUid()
7194 + "without permission "
7195 + android.Manifest.permission.DUMP);
7196 return;
7197 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007198 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007199 }
Jack Yueb89b242016-06-22 13:27:47 -07007200
Brad Ebingerdac2f002018-04-03 15:17:52 -07007201 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007202 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7203 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7204 @NonNull String[] args) {
7205 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7206 this, in.getFileDescriptor(), out.getFileDescriptor(),
7207 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007208 }
7209
Jack Yueb89b242016-06-22 13:27:47 -07007210 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007211 * Get aggregated video call data usage since boot.
7212 *
7213 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7214 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007215 * {@hide}
7216 */
7217 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007218 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007219 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7220 null);
7221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 final long identity = Binder.clearCallingIdentity();
7223 try {
7224 // NetworkStatsService keeps tracking the active network interface and identity. It
7225 // records the delta with the corresponding network identity.
7226 // We just return the total video call data usage snapshot since boot.
7227 Phone phone = getPhone(subId);
7228 if (phone != null) {
7229 return phone.getVtDataUsage(perUidStats);
7230 }
7231 return null;
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007234 }
Jack Yueb89b242016-06-22 13:27:47 -07007235 }
Jack Yu75ab2952016-07-08 14:29:33 -07007236
7237 /**
7238 * Policy control of data connection. Usually used when data limit is passed.
7239 * @param enabled True if enabling the data, otherwise disabling.
7240 * @param subId Subscription index
7241 * {@hide}
7242 */
7243 @Override
7244 public void setPolicyDataEnabled(boolean enabled, int subId) {
7245 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 Phone phone = getPhone(subId);
7250 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007251 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 }
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007255 }
7256 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007257
7258 /**
7259 * Get Client request stats
7260 * @return List of Client Request Stats
7261 * @hide
7262 */
7263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007264 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7265 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007267 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007268 return null;
7269 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007270 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
7274 if (phone != null) {
7275 return phone.getClientRequestStats();
7276 }
7277
7278 return null;
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007282 }
7283
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007284 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007285 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007286 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007287 }
Jack Yueb4124c2017-02-16 15:32:43 -08007288
7289 /**
Grace Chen70990072017-03-24 17:21:30 -07007290 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007291 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007292 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007293 * @param state State of SIM (power down, power up, pass through)
7294 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7295 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7296 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007297 *
7298 **/
7299 @Override
Grace Chen70990072017-03-24 17:21:30 -07007300 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007301 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007302 Phone phone = PhoneFactory.getPhone(slotIndex);
7303
vagdeviaf9a5b92018-08-15 16:01:53 -07007304 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 final long identity = Binder.clearCallingIdentity();
7307 try {
7308 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007309 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 }
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007313 }
7314 }
Shuo Qiandd210312017-04-12 22:11:33 +00007315
Tyler Gunn65d45c22017-06-05 11:22:26 -07007316 private boolean isUssdApiAllowed(int subId) {
7317 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007318 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007319 if (configManager == null) {
7320 return false;
7321 }
7322 PersistableBundle pb = configManager.getConfigForSubId(subId);
7323 if (pb == null) {
7324 return false;
7325 }
7326 return pb.getBoolean(
7327 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7328 }
7329
Shuo Qiandd210312017-04-12 22:11:33 +00007330 /**
7331 * Check if phone is in emergency callback mode
7332 * @return true if phone is in emergency callback mode
7333 * @param subId sub id
7334 */
goneil9c5f4872017-12-05 14:07:56 -08007335 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007336 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007337 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007338 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339
7340 final long identity = Binder.clearCallingIdentity();
7341 try {
7342 if (phone != null) {
7343 return phone.isInEcm();
7344 } else {
7345 return false;
7346 }
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007349 }
7350 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007351
7352 /**
7353 * Get the current signal strength information for the given subscription.
7354 * Because this information is not updated when the device is in a low power state
7355 * it should not be relied-upon to be current.
7356 * @param subId Subscription index
7357 * @return the most recent cached signal strength info from the modem
7358 */
7359 @Override
7360 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 Phone p = getPhone(subId);
7364 if (p == null) {
7365 return null;
7366 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 return p.getSignalStrength();
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
7371 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007373
Pengquan Meng77b7f132018-08-22 14:49:57 -07007374 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007375 * Get the current modem radio state for the given slot.
7376 * @param slotIndex slot index.
7377 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007378 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007379 * @return the current radio power state from the modem
7380 */
7381 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007382 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007383 Phone phone = PhoneFactory.getPhone(slotIndex);
7384 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7386 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007387 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7388 }
7389
7390 final long identity = Binder.clearCallingIdentity();
7391 try {
7392 return phone.getRadioPowerState();
7393 } finally {
7394 Binder.restoreCallingIdentity(identity);
7395 }
7396 }
7397 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7398 }
7399
7400 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007401 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7402 *
7403 * <p>Requires one of the following permissions:
7404 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7405 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7406 * privileges.
7407 *
7408 * @param subId subscription id
7409 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7410 * {@code false}.
7411 */
7412 @Override
7413 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7415 null /* message */);
7416
Pengquan Menga1bb6272018-09-06 09:59:22 -07007417 boolean isEnabled = false;
7418 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007419 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007420 Phone phone = getPhone(subId);
7421 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007422 } catch (Exception e) {
7423 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7424 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007425 } finally {
7426 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007427 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007428 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007429 }
7430
7431
7432 /**
7433 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7434 *
7435 * <p> Requires permission:
7436 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7437 * privileges.
7438 *
7439 * @param subId subscription id
7440 * @param isEnabled {@code true} means enable, {@code false} means disable.
7441 */
7442 @Override
7443 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7445 mApp, subId, "setDataRoamingEnabled");
7446
Pengquan Menga1bb6272018-09-06 09:59:22 -07007447 final long identity = Binder.clearCallingIdentity();
7448 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007449 Phone phone = getPhone(subId);
7450 if (phone != null) {
7451 phone.setDataRoamingEnabled(isEnabled);
7452 }
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007455 }
7456 }
7457
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007458 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007459 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007460 TelephonyPermissions
7461 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007462 mApp, subId, "isManualNetworkSelectionAllowed");
7463
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007464 boolean isAllowed = true;
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007467 Phone phone = getPhone(subId);
7468 if (phone != null) {
7469 isAllowed = phone.isCspPlmnEnabled();
7470 }
7471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
7474 return isAllowed;
7475 }
7476
7477 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007478 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007479 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007480 try {
7481 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007482 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007483 } catch (SecurityException e) {
7484 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7485 // has carrier privileges on an active UICC
7486 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7487 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007488 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007489 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007490 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007494 UiccController uiccController = UiccController.getInstance();
7495 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007496 if (hasReadPermission) {
7497 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007498 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007499
7500 // Remove private info if the caller doesn't have access
7501 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7502 for (UiccCardInfo cardInfo : cardInfos) {
7503 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7504 // is available
7505 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7506 if (card == null || card.getUiccProfile() == null) {
7507 // assume no access if the card or profile is unavailable
7508 filteredInfos.add(cardInfo.getUnprivileged());
7509 continue;
7510 }
7511 UiccProfile profile = card.getUiccProfile();
7512 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7513 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7514 filteredInfos.add(cardInfo);
7515 } else {
7516 filteredInfos.add(cardInfo.getUnprivileged());
7517 }
7518 }
7519 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
7523 }
7524
7525 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007526 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007527 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7532 if (slots == null) {
7533 Rlog.i(LOG_TAG, "slots is null.");
7534 return null;
7535 }
7536
7537 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7538 for (int i = 0; i < slots.length; i++) {
7539 UiccSlot slot = slots[i];
7540 if (slot == null) {
7541 continue;
7542 }
7543
Jordan Liu7be7e652019-05-06 18:55:02 +00007544 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 UiccCard card = slot.getUiccCard();
7546 if (card != null) {
7547 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007548 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007549 cardId = slot.getEid();
7550 if (TextUtils.isEmpty(cardId)) {
7551 cardId = slot.getIccId();
7552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 }
7554
Jordan Liu857451f2019-05-09 16:35:35 -07007555 if (cardId != null) {
7556 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7557 // if cardId is an EID, it's all digits so this is fine
7558 cardId = IccUtils.stripTrailingFs(cardId);
7559 }
7560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 int cardState = 0;
7562 switch (slot.getCardState()) {
7563 case CARDSTATE_ABSENT:
7564 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7565 break;
7566 case CARDSTATE_PRESENT:
7567 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7568 break;
7569 case CARDSTATE_ERROR:
7570 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7571 break;
7572 case CARDSTATE_RESTRICTED:
7573 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7574 break;
7575 default:
7576 break;
7577
7578 }
7579
7580 infos[i] = new UiccSlotInfo(
7581 slot.isActive(),
7582 slot.isEuicc(),
7583 cardId,
7584 cardState,
7585 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007586 slot.isExtendedApduSupported(),
7587 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 }
7589 return infos;
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007592 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007593 }
7594
7595 @Override
7596 public boolean switchSlots(int[] physicalSlots) {
7597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
7604 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007605 }
Jack Yu4c988042018-02-27 15:30:01 -08007606
7607 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007608 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 return UiccController.getInstance().getCardIdForDefaultEuicc();
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
7615 }
7616
7617 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007618 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7619 enforceModifyPermission();
7620 final Phone phone = getPhone(subId);
7621 if (phone == null) {
7622 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7623 return;
7624 }
7625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 phone.setRadioIndicationUpdateMode(filters, mode);
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
Jack Yu4c988042018-02-27 15:30:01 -08007632 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007633
7634 /**
goneil47ffb6e2018-04-06 15:40:58 -07007635 * A test API to reload the UICC profile.
7636 *
7637 * <p>Requires that the calling app has permission
7638 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7639 * @hide
7640 */
7641 @Override
7642 public void refreshUiccProfile(int subId) {
7643 enforceModifyPermission();
7644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 Phone phone = getPhone(subId);
7648 if (phone == null) {
7649 return;
7650 }
7651 UiccCard uiccCard = phone.getUiccCard();
7652 if (uiccCard == null) {
7653 return;
7654 }
7655 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7656 if (uiccProfile == null) {
7657 return;
7658 }
7659 uiccProfile.refresh();
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
7662 }
7663 }
7664
7665 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007666 * Returns false if the mobile data is disabled by default, otherwise return true.
7667 */
7668 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007669 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007670 }
7671
7672 /**
7673 * Returns true if the data roaming is enabled by default, i.e the system property
7674 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7675 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7676 */
7677 private boolean getDefaultDataRoamingEnabled(int subId) {
7678 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007680 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007681 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7682 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7683 return isDataRoamingEnabled;
7684 }
7685
7686 /**
7687 * Returns the default network type for the given {@code subId}, if the default network type is
7688 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7689 */
7690 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007691 List<Integer> list = TelephonyProperties.default_network();
7692 int phoneId = mSubscriptionController.getPhoneId(subId);
7693 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7694 return list.get(phoneId);
7695 }
7696 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007697 }
fionaxua13278b2018-03-21 00:08:13 -07007698
7699 @Override
7700 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007701 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703
7704 final long identity = Binder.clearCallingIdentity();
7705 try {
7706 final Phone phone = getPhone(subId);
7707 if (phone == null) {
7708 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7709 return;
7710 }
chen xueaba88a2019-03-15 13:15:10 -07007711 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7712 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 } finally {
7714 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007715 }
fionaxua13278b2018-03-21 00:08:13 -07007716 }
7717
7718 @Override
7719 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007720 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721
7722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 final Phone phone = getPhone(subId);
7725 if (phone == null) {
7726 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7727 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7728 }
7729 return phone.getCarrierIdListVersion();
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007732 }
fionaxua13278b2018-03-21 00:08:13 -07007733 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007734
7735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007736 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7737 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007739 mApp, subId, callingPackage, callingFeatureId,
7740 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007741 return -1;
7742 }
7743
7744 final long identity = Binder.clearCallingIdentity();
7745 try {
7746 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
7750 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007751
7752 @Override
7753 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007754 TelephonyPermissions
7755 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007756 mApp, subId, "getCdmaRoamingMode");
7757
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
7764 }
7765
7766 @Override
7767 public boolean setCdmaRoamingMode(int subId, int mode) {
7768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7769 mApp, subId, "setCdmaRoamingMode");
7770
7771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
7777 }
7778
7779 @Override
7780 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7782 mApp, subId, "setCdmaSubscriptionMode");
7783
7784 final long identity = Binder.clearCallingIdentity();
7785 try {
7786 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
7789 }
7790 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007791
sqianc5eccab2018-10-19 18:46:41 -07007792 @Override
sqian8c685422019-02-22 15:55:18 -08007793 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007794 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007796 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7797 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007798 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7799 }
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
sqian854d44b2018-12-12 16:48:18 -08007802 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7803 for (Phone phone: PhoneFactory.getPhones()) {
7804 if (phone.getEmergencyNumberTracker() != null
7805 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7806 emergencyNumberListInternal.put(
7807 phone.getSubId(),
7808 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7809 }
sqian11b7a0e2018-12-05 18:48:28 -08007810 }
sqian854d44b2018-12-12 16:48:18 -08007811 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
sqianc5eccab2018-10-19 18:46:41 -07007815 }
7816
7817 @Override
sqian8c685422019-02-22 15:55:18 -08007818 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007819 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007820 if (!exactMatch) {
7821 TelephonyPermissions
7822 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007823 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007824 }
7825 final long identity = Binder.clearCallingIdentity();
7826 try {
sqian854d44b2018-12-12 16:48:18 -08007827 for (Phone phone: PhoneFactory.getPhones()) {
7828 if (phone.getEmergencyNumberTracker() != null
7829 && phone.getEmergencyNumberTracker() != null) {
7830 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7831 number, exactMatch)) {
7832 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007833 }
7834 }
sqian11b7a0e2018-12-05 18:48:28 -08007835 }
7836 return false;
7837 } finally {
7838 Binder.restoreCallingIdentity(identity);
7839 }
7840 }
7841
sqianf4ca7ed2019-01-15 18:32:07 -08007842 /**
7843 * Update emergency number list for test mode.
7844 */
7845 @Override
7846 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7848 "updateEmergencyNumberListTestMode");
7849
7850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 for (Phone phone: PhoneFactory.getPhones()) {
7853 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7854 if (tracker != null) {
7855 tracker.executeEmergencyNumberTestModeCommand(action, num);
7856 }
7857 }
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
7861 }
7862
7863 /**
7864 * Get the full emergency number list for test mode.
7865 */
7866 @Override
7867 public List<String> getEmergencyNumberListTestMode() {
7868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7869 "getEmergencyNumberListTestMode");
7870
7871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 Set<String> emergencyNumbers = new HashSet<>();
7874 for (Phone phone: PhoneFactory.getPhones()) {
7875 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7876 if (tracker != null) {
7877 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7878 emergencyNumbers.add(num.getNumber());
7879 }
7880 }
7881 }
7882 return new ArrayList<>(emergencyNumbers);
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
7886 }
7887
chen xud6b45bd2018-10-30 22:27:10 -07007888 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007889 public int getEmergencyNumberDbVersion(int subId) {
7890 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7891
7892 final long identity = Binder.clearCallingIdentity();
7893 try {
7894 final Phone phone = getPhone(subId);
7895 if (phone == null) {
7896 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7897 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7898 }
7899 return phone.getEmergencyNumberDbVersion();
7900 } finally {
7901 Binder.restoreCallingIdentity(identity);
7902 }
7903 }
7904
7905 @Override
7906 public void notifyOtaEmergencyNumberDbInstalled() {
7907 enforceModifyPermission();
7908
7909 final long identity = Binder.clearCallingIdentity();
7910 try {
7911 for (Phone phone: PhoneFactory.getPhones()) {
7912 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7913 if (tracker != null) {
7914 tracker.updateOtaEmergencyNumberDatabase();
7915 }
7916 }
7917 } finally {
7918 Binder.restoreCallingIdentity(identity);
7919 }
7920 }
7921
7922 @Override
7923 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7924 enforceActiveEmergencySessionPermission();
7925
7926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 for (Phone phone: PhoneFactory.getPhones()) {
7929 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7930 if (tracker != null) {
7931 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7932 }
7933 }
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
7937 }
7938
7939 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007940 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7941 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7942 Phone phone = getPhone(subId);
7943 if (phone == null) {
7944 return null;
7945 }
7946 final long identity = Binder.clearCallingIdentity();
7947 try {
7948 UiccProfile profile = UiccController.getInstance()
7949 .getUiccProfileForPhone(phone.getPhoneId());
7950 if (profile != null) {
7951 return profile.getCertsFromCarrierPrivilegeAccessRules();
7952 }
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
7955 }
7956 return null;
7957 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007958
7959 /**
7960 * Enable or disable a modem stack.
7961 */
7962 @Override
7963 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7964 enforceModifyPermission();
7965
7966 final long identity = Binder.clearCallingIdentity();
7967 try {
7968 Phone phone = PhoneFactory.getPhone(slotIndex);
7969 if (phone == null) {
7970 return false;
7971 } else {
7972 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7973 }
7974 } finally {
7975 Binder.restoreCallingIdentity(identity);
7976 }
7977 }
Michelecea4cf22018-12-21 15:00:11 -08007978
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007979 /**
7980 * Whether a modem stack is enabled or not.
7981 */
7982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007983 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7984 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007985 Phone phone = PhoneFactory.getPhone(slotIndex);
7986 if (phone == null) return false;
7987
7988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007989 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7990 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007991 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7992 }
7993
7994 final long identity = Binder.clearCallingIdentity();
7995 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007996 try {
7997 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7998 } catch (NoSuchElementException ex) {
7999 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8000 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008001 } finally {
8002 Binder.restoreCallingIdentity(identity);
8003 }
8004 }
8005
Michelecea4cf22018-12-21 15:00:11 -08008006 @Override
Michele0ea7d782019-03-19 14:58:42 -07008007 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008008 enforceModifyPermission();
8009
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008013 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008014 .commit();
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
8018 }
8019
8020 @Override
Michele0ea7d782019-03-19 14:58:42 -07008021 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008022 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008024 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8025 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008026 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008027 }
Michelecea4cf22018-12-21 15:00:11 -08008028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
Michele0ea7d782019-03-19 14:58:42 -07008031 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008032 } finally {
8033 Binder.restoreCallingIdentity(identity);
8034 }
8035 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008036
Michele0ea7d782019-03-19 14:58:42 -07008037 @TelephonyManager.IsMultiSimSupportedResult
8038 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008039 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8040 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8041 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008042 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8043 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008044 }
8045 // Check if the hardware supports multisim functionality. If usage of multisim is not
8046 // supported by the modem, indicate that it is restricted.
8047 PhoneCapability staticCapability =
8048 mPhoneConfigurationManager.getStaticPhoneCapability();
8049 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008050 loge("isMultiSimSupportedInternal: no static configuration available");
8051 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008052 }
Sarah Chin0605abf2019-12-06 10:24:18 -08008053 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008054 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8055 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008056 }
8057 // Check if support of multiple SIMs is restricted by carrier
8058 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008059 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008060 }
8061
Michele0ea7d782019-03-19 14:58:42 -07008062 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008063 }
8064
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008065 /**
8066 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008067 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8068 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8069 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008070 * @param numOfSims number of active sims we want to switch to
8071 */
8072 @Override
8073 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008074 if (numOfSims == 1) {
8075 enforceModifyPermission();
8076 } else {
8077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8078 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8079 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008080 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008081
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008082 try {
Michele30b57b22019-03-01 12:01:14 -08008083 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008084 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008085 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8086 return;
8087 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008088 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
8091 }
8092 }
8093
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008094 @Override
8095 public boolean isApplicationOnUicc(int subId, int appType) {
8096 enforceReadPrivilegedPermission("isApplicationOnUicc");
8097 Phone phone = getPhone(subId);
8098 if (phone == null) {
8099 return false;
8100 }
8101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 UiccCard uiccCard = phone.getUiccCard();
8104 if (uiccCard == null) {
8105 return false;
8106 }
8107 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8108 if (uiccProfile == null) {
8109 return false;
8110 }
8111 if (TelephonyManager.APPTYPE_SIM <= appType
8112 && appType <= TelephonyManager.APPTYPE_ISIM) {
8113 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8114 }
8115 return false;
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
8118 }
8119 }
8120
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008121 /**
chen xub4baa772019-04-03 10:23:41 -07008122 * Get whether making changes to modem configurations will trigger reboot.
8123 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008124 */
8125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008126 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8127 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008129 mApp, subId, callingPackage, callingFeatureId,
8130 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008131 return false;
8132 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
8138 }
8139 }
8140
Nathan Harold29f5f052019-02-15 13:41:57 -08008141 private void updateModemStateMetrics() {
8142 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8143 // TODO: check the state for each modem if the api is ready.
8144 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8145 }
8146
Pengquan Meng3889a572019-01-23 11:16:29 -08008147 @Override
8148 public int[] getSlotsMapping() {
8149 enforceReadPrivilegedPermission("getSlotsMapping");
8150
8151 final long identity = Binder.clearCallingIdentity();
8152 try {
8153 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8154 // All logical slots should have a mapping to a physical slot.
8155 int[] logicalSlotsMapping = new int[phoneCount];
8156 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8157 for (int i = 0; i < slotInfos.length; i++) {
8158 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8159 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8160 }
8161 }
8162 return logicalSlotsMapping;
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
8165 }
8166 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008167
8168 /**
8169 * Get the IRadio HAL Version
8170 */
8171 @Override
8172 public int getRadioHalVersion() {
8173 Phone phone = getDefaultPhone();
8174 if (phone == null) return -1;
8175 HalVersion hv = phone.getHalVersion();
8176 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8177 return hv.major * 100 + hv.minor;
8178 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008179
8180 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008181 * Get the current calling package name.
8182 * @return the current calling package name
8183 */
8184 @Override
8185 public String getCurrentPackageName() {
8186 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8187 }
8188
8189 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008190 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8191 * corresponding network requests on a subId.
8192 *
8193 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008194 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008195 * 2) APN is un-metered for this subscription, or
8196 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008197 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008198 *
8199 * @return whether data is allowed for a apn type.
8200 *
8201 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008202 */
8203 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008204 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008205 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8206 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008207
8208 // Now that all security checks passes, perform the operation as ourselves.
8209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 Phone phone = getPhone(subId);
8212 if (phone == null) return false;
8213
Jack Yu41407ee2019-05-13 16:54:09 -07008214 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008215 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8216 } finally {
8217 Binder.restoreCallingIdentity(identity);
8218 }
8219 }
8220
8221 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008222 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008223 enforceReadPrivilegedPermission("isApnMetered");
8224
8225 // Now that all security checks passes, perform the operation as ourselves.
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
8228 Phone phone = getPhone(subId);
8229 if (phone == null) return true; // By default return true.
8230
Jack Yu41407ee2019-05-13 16:54:09 -07008231 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
8235 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008236
8237 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008238 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8239 int subscriptionId, IBooleanConsumer resultCallback) {
8240 enforceModifyPermission();
8241 long token = Binder.clearCallingIdentity();
8242 try {
8243 Phone phone = getPhone(subscriptionId);
8244 if (phone == null) {
8245 try {
8246 if (resultCallback != null) {
8247 resultCallback.accept(false);
8248 }
8249 } catch (RemoteException e) {
8250 // ignore
8251 }
8252 return;
8253 }
8254 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8255 Pair.create(specifiers, (x) -> {
8256 try {
8257 if (resultCallback != null) {
8258 resultCallback.accept(x);
8259 }
8260 } catch (RemoteException e) {
8261 // ignore
8262 }
8263 });
8264 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8265 } finally {
8266 Binder.restoreCallingIdentity(token);
8267 }
8268 }
8269
8270 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008271 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8272 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8273 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8274 if (iccRecords == null) {
8275 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8276 return false;
8277 }
8278 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8279 }
8280
8281 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008282 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008283 if (callingPackage == null) {
8284 callingPackage = getCurrentPackageName();
8285 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008286 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8287 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8288 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8289 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8290 }
8291 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8292 Intent intent = new Intent();
8293 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8294 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8295 // Bring up choose default SMS subscription dialog right now
8296 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8297 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8298 mApp.startActivity(intent);
8299 }
chen xud5ca2d52019-05-28 15:20:57 -07008300
8301 @Override
8302 public String getMmsUAProfUrl(int subId) {
8303 //TODO investigate if this API should require proper permission check in R b/133791609
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8307 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
8312
8313 @Override
8314 public String getMmsUserAgent(int subId) {
8315 //TODO investigate if this API should require proper permission check in R b/133791609
8316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8319 .getString(com.android.internal.R.string.config_mms_user_agent);
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
Jack Yub07d4972019-05-28 16:12:25 -07008324
8325 @Override
8326 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8327 enforceModifyPermission();
8328
8329 // Now that all security checks passes, perform the operation as ourselves.
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
8332 Phone phone = getPhone(subId);
8333 if (phone == null) return false;
8334
8335 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 }
8340
8341 @Override
8342 public boolean isDataAllowedInVoiceCall(int subId) {
8343 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8344
8345 // Now that all security checks passes, perform the operation as ourselves.
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
8348 Phone phone = getPhone(subId);
8349 if (phone == null) return false;
8350
8351 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008356
changbettyd5c246e2019-12-24 15:40:37 +08008357 @Override
8358 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8359 enforceModifyPermission();
8360
8361 // Now that all security checks passes, perform the operation as ourselves.
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
8364 Phone phone = getPhone(subId);
8365 if (phone == null) return false;
8366
8367 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
8372
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008373 /**
8374 * Updates whether conference event pacakge handling is enabled.
8375 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8376 * otherwise.
8377 */
8378 @Override
8379 public void setCepEnabled(boolean isCepEnabled) {
8380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8381
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8385 for (Phone phone : PhoneFactory.getPhones()) {
8386 Phone defaultPhone = phone.getImsPhone();
8387 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8388 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8389 ImsPhoneCallTracker imsPhoneCallTracker =
8390 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8391 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8392 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8393 + imsPhone.getMsisdn());
8394 }
8395 }
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 }
allenwtsu46dcc572020-01-08 18:24:03 +08008400
8401 /**
8402 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8403 *
8404 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8405 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8406 * before being read.
8407 */
8408 @Override
8409 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8410 isCompressed) {
8411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8412 mApp, subId, "notifyRcsAutoConfigurationReceived");
8413 try {
8414 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8415 if (configBinder == null) {
8416 Rlog.e(LOG_TAG, "null result for getImsConfig");
8417 } else {
8418 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8419 }
8420 } catch (RemoteException e) {
8421 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8422 }
8423 }
zoey chene02881a2019-12-30 16:11:23 +08008424
8425 @Override
8426 public boolean isIccLockEnabled(int subId) {
8427 enforceReadPrivilegedPermission("isIccLockEnabled");
8428
8429 // Now that all security checks passes, perform the operation as ourselves.
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 Phone phone = getPhone(subId);
8433 if (phone != null && phone.getIccCard() != null) {
8434 return phone.getIccCard().getIccLockEnabled();
8435 } else {
8436 return false;
8437 }
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
8443 /**
8444 * Set the ICC pin lock enabled or disabled.
8445 *
8446 * @return an integer representing the status of IccLock enabled or disabled in the following
8447 * three cases:
8448 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8449 * successfully.
8450 * - Positive number and zero for remaining password attempts.
8451 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8452 *
8453 */
8454 @Override
8455 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8456 enforceModifyPermission();
8457
8458 Phone phone = getPhone(subId);
8459 if (phone == null) {
8460 return 0;
8461 }
8462 // Now that all security checks passes, perform the operation as ourselves.
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8466 new Pair<Boolean, String>(enabled, password), phone, null);
8467 return attemptsRemaining;
8468
8469 } catch (Exception e) {
8470 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 return 0;
8475 }
8476
8477 /**
8478 * Change the ICC password used in ICC pin lock.
8479 *
8480 * @return an integer representing the status of IccLock changed in the following three cases:
8481 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8482 * - Positive number and zero for remaining password attempts.
8483 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8484 *
8485 */
8486 @Override
8487 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8488 enforceModifyPermission();
8489
8490 Phone phone = getPhone(subId);
8491 if (phone == null) {
8492 return 0;
8493 }
8494 // Now that all security checks passes, perform the operation as ourselves.
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8498 new Pair<String, String>(oldPassword, newPassword), phone, null);
8499 return attemptsRemaining;
8500
8501 } catch (Exception e) {
8502 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 return 0;
8507 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008508
8509 /**
8510 * Request for receiving user activity notification
8511 */
8512 @Override
8513 public void requestUserActivityNotification() {
8514 if (!mNotifyUserActivity.get()
8515 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8516 mNotifyUserActivity.set(true);
8517 }
8518 }
8519
8520 /**
8521 * Called when userActivity is signalled in the power manager.
8522 * This is safe to call from any thread, with any window manager locks held or not.
8523 */
8524 @Override
8525 public void userActivity() {
8526 // ***************************************
8527 // * Inherited from PhoneWindowManager *
8528 // ***************************************
8529 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8530 // WITH ITS LOCKS HELD.
8531 //
8532 // This code must be VERY careful about the locks
8533 // it acquires.
8534 // In fact, the current code acquires way too many,
8535 // and probably has lurking deadlocks.
8536
8537 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8538 throw new SecurityException("Only the OS may call notifyUserActivity()");
8539 }
8540
8541 if (mNotifyUserActivity.getAndSet(false)) {
8542 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8543 USER_ACTIVITY_NOTIFICATION_DELAY);
8544 }
8545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008546}