blob: 43613d0a49931f08c3d65b169f189b3690ebf9c5 [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;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
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;
Daniel Bright9a8791d2020-02-11 18:19:36 -0800174import com.android.internal.telephony.util.TelephonyResourceUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700175import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800176import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700177import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800179import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700180import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700181import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800182import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800183
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700184import java.io.FileDescriptor;
185import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800188import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800190import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100191import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700193import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800195import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800196import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198/**
199 * Implementation of the ITelephony interface.
200 */
Santos Cordon117fee72014-05-16 17:56:12 -0700201public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202 private static final String LOG_TAG = "PhoneInterfaceManager";
203 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
204 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800205 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
207 // Message codes used with mMainThreadHandler
208 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700209 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
210 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700211 private static final int CMD_OPEN_CHANNEL = 9;
212 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
213 private static final int CMD_CLOSE_CHANNEL = 11;
214 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800215 private static final int CMD_NV_READ_ITEM = 13;
216 private static final int EVENT_NV_READ_ITEM_DONE = 14;
217 private static final int CMD_NV_WRITE_ITEM = 15;
218 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
219 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
220 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700221 private static final int CMD_RESET_MODEM_CONFIG = 19;
222 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800223 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
224 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
225 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
226 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800227 private static final int CMD_SEND_ENVELOPE = 25;
228 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000229 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
230 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700231 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
232 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
233 private static final int CMD_EXCHANGE_SIM_IO = 31;
234 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800235 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
236 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700237 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
238 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700239 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
240 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700241 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
242 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
243 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
244 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700245 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
246 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
247 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
248 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700249 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800250 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
251 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000252 private static final int CMD_SWITCH_SLOTS = 50;
253 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700254 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
255 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
256 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
257 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
258 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
259 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
260 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
261 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700262 private static final int CMD_GET_ALL_CELL_INFO = 60;
263 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
264 private static final int CMD_GET_CELL_LOCATION = 62;
265 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_MODEM_REBOOT = 64;
267 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700268 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
269 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800270 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
271 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700272 private static final int CMD_GET_MODEM_STATUS = 70;
273 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700274 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
275 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700276 private static final int CMD_ERASE_MODEM_CONFIG = 74;
277 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800278 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
279 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
280 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
281 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800282 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
283 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800284 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800285 private static final int CMD_GET_CALL_FORWARDING = 83;
286 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
287 private static final int CMD_SET_CALL_FORWARDING = 85;
288 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
289 private static final int CMD_GET_CALL_WAITING = 87;
290 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
291 private static final int CMD_SET_CALL_WAITING = 89;
292 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800294 // Parameters of select command.
295 private static final int SELECT_COMMAND = 0xA4;
296 private static final int SELECT_P1 = 0x04;
297 private static final int SELECT_P2 = 0;
298 private static final int SELECT_P3 = 0x10;
299
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 /** The singleton instance. */
301 private static PhoneInterfaceManager sInstance;
302
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800304 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800305 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700306 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private AppOpsManager mAppOps;
308 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800309 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800310 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700311 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 /** User Activity */
314 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800315 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
316
Derek Tan97ebb422014-09-05 16:55:38 -0700317 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
318 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800319 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800320 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700321
Michelecea4cf22018-12-21 15:00:11 -0800322 // String to store multi SIM allowed
323 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
324
Derek Tan740e1672017-06-27 14:56:27 -0700325 // The AID of ISD-R.
326 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
327
yinxub1bed742017-04-17 11:45:04 -0700328 private NetworkScanRequestTracker mNetworkScanRequestTracker;
329
David Kelly5e06a7f2018-03-12 14:10:59 +0000330 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
331 private static final int MANUFACTURER_CODE_LENGTH = 8;
332
Derek Tan89e89d42014-07-08 17:00:10 -0700333 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700334 * Experiment flag to enable erase modem config on reset network, default value is false
335 */
336 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
337 "reset_network_erase_modem_config_enabled";
338
339 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700340 * A request object to use for transmitting data to an ICC.
341 */
342 private static final class IccAPDUArgument {
343 public int channel, cla, command, p1, p2, p3;
344 public String data;
345
346 public IccAPDUArgument(int channel, int cla, int command,
347 int p1, int p2, int p3, String data) {
348 this.channel = channel;
349 this.cla = cla;
350 this.command = command;
351 this.p1 = p1;
352 this.p2 = p2;
353 this.p3 = p3;
354 this.data = data;
355 }
356 }
357
358 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700359 * A request object to use for transmitting data to an ICC.
360 */
361 private static final class ManualNetworkSelectionArgument {
362 public OperatorInfo operatorInfo;
363 public boolean persistSelection;
364
365 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
366 this.operatorInfo = operatorInfo;
367 this.persistSelection = persistSelection;
368 }
369 }
370
371 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
373 * request after sending. The main thread will notify the request when it is complete.
374 */
375 private static final class MainThreadRequest {
376 /** The argument to use for the request */
377 public Object argument;
378 /** The result of the request that is run on the main thread */
379 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800380 // The subscriber id that this request applies to. Defaults to
381 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
382 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Nathan Harold92bed182018-10-12 18:16:49 -0700384 // In cases where subId is unavailable, the caller needs to specify the phone.
385 public Phone phone;
386
vagdeviaf9a5b92018-08-15 16:01:53 -0700387 public WorkSource workSource;
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 public MainThreadRequest(Object argument) {
390 this.argument = argument;
391 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392
Nathan Harold92bed182018-10-12 18:16:49 -0700393 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
394 this.argument = argument;
395 if (phone != null) {
396 this.phone = phone;
397 }
398 this.workSource = workSource;
399 }
400
vagdeviaf9a5b92018-08-15 16:01:53 -0700401 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800402 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800403 if (subId != null) {
404 this.subId = subId;
405 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700406 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 }
409
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800410 private static final class IncomingThirdPartyCallArgs {
411 public final ComponentName component;
412 public final String callId;
413 public final String callerDisplayName;
414
415 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
416 String callerDisplayName) {
417 this.component = component;
418 this.callId = callId;
419 this.callerDisplayName = callerDisplayName;
420 }
421 }
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 /**
424 * A handler that processes messages on the main thread in the phone process. Since many
425 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
426 * inbound binder threads to the main thread in the phone process. The Binder thread
427 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
428 * on, which will be notified when the operation completes and will contain the result of the
429 * request.
430 *
431 * <p>If a MainThreadRequest object is provided in the msg.obj field,
432 * note that request.result must be set to something non-null for the calling thread to
433 * unblock.
434 */
435 private final class MainThreadHandler extends Handler {
436 @Override
437 public void handleMessage(Message msg) {
438 MainThreadRequest request;
439 Message onCompleted;
440 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800443 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
445 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 case CMD_HANDLE_USSD_REQUEST: {
447 request = (MainThreadRequest) msg.obj;
448 final Phone phone = getPhoneFromRequest(request);
449 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
450 String ussdRequest = ussdObject.first;
451 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 if (!isUssdApiAllowed(request.subId)) {
454 // Carrier does not support use of this API, return failure.
455 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
456 UssdResponse response = new UssdResponse(ussdRequest, null);
457 Bundle returnData = new Bundle();
458 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
459 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700460
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 request.result = true;
462 notifyRequester(request);
463 return;
464 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700465
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 try {
467 request.result = phone != null
468 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
469 } catch (CallStateException cse) {
470 request.result = false;
471 }
472 // Wake up the requesting thread
473 notifyRequester(request);
474 break;
pkanwar32d516d2016-10-14 19:37:38 -0700475 }
476
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700479 final Phone phone = getPhoneFromRequest(request);
480 request.result = phone != null ?
481 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
482 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800491 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 if (uiccCard == null) {
493 loge("iccTransmitApduLogicalChannel: No UICC");
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700496 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
498 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700499 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 iccArgument.channel, iccArgument.cla, iccArgument.command,
501 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 break;
505
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6F, 0, (byte[])null);
513 if (ar.result == null) {
514 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800515 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800517 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700518 } else {
519 loge("iccTransmitApduLogicalChannel: Unknown exception");
520 }
521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 break;
524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
526 request = (MainThreadRequest) msg.obj;
527 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 if (uiccCard == null) {
530 loge("iccTransmitApduBasicChannel: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 } else {
534 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
535 request);
536 uiccCard.iccTransmitApduBasicChannel(
537 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
538 iccArgument.p3, iccArgument.data, onCompleted);
539 }
540 break;
541
542 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
547 } else {
548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("iccTransmitApduBasicChannel: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("iccTransmitApduBasicChannel: CommandException: " +
553 ar.exception);
554 } else {
555 loge("iccTransmitApduBasicChannel: Unknown exception");
556 }
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 break;
560
561 case CMD_EXCHANGE_SIM_IO:
562 request = (MainThreadRequest) msg.obj;
563 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 if (uiccCard == null) {
566 loge("iccExchangeSimIO: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
571 request);
572 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
573 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
574 iccArgument.data, onCompleted);
575 }
576 break;
577
578 case EVENT_EXCHANGE_SIM_IO_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
581 if (ar.exception == null && ar.result != null) {
582 request.result = ar.result;
583 } else {
584 request.result = new IccIoResult(0x6f, 0, (byte[])null);
585 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 break;
588
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 case CMD_SEND_ENVELOPE:
590 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800591 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 if (uiccCard == null) {
593 loge("sendEnvelopeWithStatus: No UICC");
594 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 } else {
597 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
598 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
599 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800600 break;
601
602 case EVENT_SEND_ENVELOPE_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("sendEnvelopeWithStatus: Empty response");
611 } else if (ar.exception instanceof CommandException) {
612 loge("sendEnvelopeWithStatus: CommandException: " +
613 ar.exception);
614 } else {
615 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
616 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800619 break;
620
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 case CMD_OPEN_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800624 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800627 request.result = new IccOpenLogicalChannelResponse(-1,
628 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800632 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
633 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case EVENT_OPEN_CHANNEL_DONE:
638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 int[] result = (int[]) ar.result;
643 int channelId = result[0];
644 byte[] selectResponse = null;
645 if (result.length > 1) {
646 selectResponse = new byte[result.length - 1];
647 for (int i = 1; i < result.length; ++i) {
648 selectResponse[i - 1] = (byte) result[i];
649 }
650 }
651 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700652 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 if (ar.result == null) {
655 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 if (ar.exception != null) {
658 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
659 }
660
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700661 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700662 if (ar.exception instanceof CommandException) {
663 CommandException.Error error =
664 ((CommandException) (ar.exception)).getCommandError();
665 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700667 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700668 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 }
670 }
671 openChannelResp = new IccOpenLogicalChannelResponse(
672 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700674 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case CMD_CLOSE_CHANNEL:
679 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800680 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 if (uiccCard == null) {
682 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900683 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 } else {
686 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
687 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
688 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
691 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800692 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
693 break;
694
695 case CMD_NV_READ_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800705 if (ar.exception == null && ar.result != null) {
706 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800708 request.result = "";
709 if (ar.result == null) {
710 loge("nvReadItem: Empty response");
711 } else if (ar.exception instanceof CommandException) {
712 loge("nvReadItem: CommandException: " +
713 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800715 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 }
717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
Jake Hambye994d462014-02-03 13:10:13 -0800721 case CMD_NV_WRITE_ITEM:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
724 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800725 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700726 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_WRITE_ITEM_DONE:
730 handleNullReturnEvent(msg, "nvWriteItem");
731 break;
732
733 case CMD_NV_WRITE_CDMA_PRL:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
739 case EVENT_NV_WRITE_CDMA_PRL_DONE:
740 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
741 break;
742
chen xu6dac5ab2018-10-26 17:39:23 -0700743 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800744 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700745 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800747 break;
748
chen xu6dac5ab2018-10-26 17:39:23 -0700749 case EVENT_RESET_MODEM_CONFIG_DONE:
750 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800751 break;
752
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 case CMD_GET_PREFERRED_NETWORK_TYPE:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 if (ar.exception == null && ar.result != null) {
763 request.result = ar.result; // Integer
764 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800765 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800766 if (ar.result == null) {
767 loge("getPreferredNetworkType: Empty response");
768 } else if (ar.exception instanceof CommandException) {
769 loge("getPreferredNetworkType: CommandException: " +
770 ar.exception);
771 } else {
772 loge("getPreferredNetworkType: Unknown exception");
773 }
774 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800776 break;
777
778 case CMD_SET_PREFERRED_NETWORK_TYPE:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
781 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700782 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800783 break;
784
785 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
786 handleNullReturnEvent(msg, "setPreferredNetworkType");
787 break;
788
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000789 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
790 request = (MainThreadRequest)msg.obj;
791 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000793 break;
794
795 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
796 ar = (AsyncResult)msg.obj;
797 request = (MainThreadRequest)ar.userObj;
798 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000800 break;
801
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800802 case CMD_SET_VOICEMAIL_NUMBER:
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
805 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800806 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
807 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800808 break;
809
810 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
811 handleNullReturnEvent(msg, "setVoicemailNumber");
812 break;
813
Stuart Scott54788802015-03-30 13:18:01 -0700814 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
817 request);
818 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
819 break;
820
821 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
822 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
823 break;
824
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 case CMD_PERFORM_NETWORK_SCAN:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
828 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
829 break;
830
Shuo Qian4a594052020-01-23 11:59:30 -0800831 case CMD_GET_CALL_FORWARDING:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
834 int callForwardingReason = (Integer) request.argument;
835 getPhoneFromRequest(request).getCallForwardingOption(
836 callForwardingReason, onCompleted);
837 break;
838
839 case EVENT_GET_CALL_FORWARDING_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 CallForwardingInfo callForwardingInfo = null;
843 if (ar.exception == null && ar.result != null) {
844 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
845 for (CallForwardInfo callForwardInfo : callForwardInfos) {
846 // Service Class is a bit mask per 3gpp 27.007. Search for
847 // any service for voice call.
848 if ((callForwardInfo.serviceClass
849 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
850 callForwardingInfo = new CallForwardingInfo(
851 callForwardInfo.serviceClass, callForwardInfo.reason,
852 callForwardInfo.number,
853 callForwardInfo.timeSeconds);
854 break;
855 }
856 }
857 // Didn't find a call forward info for voice call.
858 if (callForwardingInfo == null) {
859 callForwardingInfo = new CallForwardingInfo(
860 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
861 0 /* reason */, null /* number */, 0 /* timeout */);
862 }
863 } else {
864 if (ar.result == null) {
865 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
866 }
867 if (ar.exception != null) {
868 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
869 }
870 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
871 if (ar.exception instanceof CommandException) {
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
874 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
875 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
876 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
877 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
878 }
879 }
880 callForwardingInfo = new CallForwardingInfo(
881 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
882 }
883 request.result = callForwardingInfo;
884 notifyRequester(request);
885 break;
886
887 case CMD_SET_CALL_FORWARDING:
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
890 CallForwardingInfo callForwardingInfoToSet =
891 (CallForwardingInfo) request.argument;
892 getPhoneFromRequest(request).setCallForwardingOption(
893 callForwardingInfoToSet.getStatus(),
894 callForwardingInfoToSet.getReason(),
895 callForwardingInfoToSet.getNumber(),
896 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
897 break;
898
899 case EVENT_SET_CALL_FORWARDING_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null) {
903 request.result = true;
904 } else {
905 request.result = false;
906 loge("setCallForwarding exception: " + ar.exception);
907 }
908 notifyRequester(request);
909 break;
910
911 case CMD_GET_CALL_WAITING:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
914 getPhoneFromRequest(request).getCallWaiting(onCompleted);
915 break;
916
917 case EVENT_GET_CALL_WAITING_DONE:
918 ar = (AsyncResult) msg.obj;
919 request = (MainThreadRequest) ar.userObj;
920 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
921 if (ar.exception == null && ar.result != null) {
922 ArrayList<Integer> callForwardResults = (ArrayList<Integer>) ar.result;
923 // Service Class is a bit mask per 3gpp 27.007.
924 // Search for any service for voice call.
925 if ((callForwardResults.get(1)
926 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
927 callForwardingStatus = callForwardResults.get(0) == 0
928 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
929 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
930 } else {
931 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
932 }
933 } else {
934 if (ar.result == null) {
935 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
936 }
937 if (ar.exception != null) {
938 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
939 }
940 if (ar.exception instanceof CommandException) {
941 CommandException.Error error =
942 ((CommandException) (ar.exception)).getCommandError();
943 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
944 callForwardingStatus =
945 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
946 }
947 }
948 }
949 request.result = callForwardingStatus;
950 notifyRequester(request);
951 break;
952
953 case CMD_SET_CALL_WAITING:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
956 boolean isEnable = (Boolean) request.argument;
957 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
958 break;
959
960 case EVENT_SET_CALL_WAITING_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception == null) {
964 request.result = true;
965 } else {
966 request.result = false;
967 loge("setCallWaiting exception: " + ar.exception);
968 }
969 notifyRequester(request);
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case EVENT_PERFORM_NETWORK_SCAN_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 CellNetworkScanResult cellScanResult;
976 if (ar.exception == null && ar.result != null) {
977 cellScanResult = new CellNetworkScanResult(
978 CellNetworkScanResult.STATUS_SUCCESS,
979 (List<OperatorInfo>) ar.result);
980 } else {
981 if (ar.result == null) {
982 loge("getCellNetworkScanResults: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("getCellNetworkScanResults: Exception: " + ar.exception);
986 }
987 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.GENERIC_FAILURE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
995 }
996 }
997 cellScanResult = new CellNetworkScanResult(errorCode, null);
998 }
999 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 break;
1002
1003 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1004 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001005 ManualNetworkSelectionArgument selArg =
1006 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001007 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1008 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001009 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1010 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001011 break;
1012
1013 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 loge("setNetworkSelectionModeManual " + ar.exception);
1021 }
1022 notifyRequester(request);
1023 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001024 break;
1025
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001026 case CMD_GET_MODEM_ACTIVITY_INFO:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001029 if (defaultPhone != null) {
1030 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1031 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001032 break;
1033
1034 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 if (ar.exception == null && ar.result != null) {
1038 request.result = ar.result;
1039 } else {
1040 if (ar.result == null) {
1041 loge("queryModemActivityInfo: Empty response");
1042 } else if (ar.exception instanceof CommandException) {
1043 loge("queryModemActivityInfo: CommandException: " +
1044 ar.exception);
1045 } else {
1046 loge("queryModemActivityInfo: Unknown exception");
1047 }
1048 }
Amit Mahajand4766222016-01-28 15:28:28 -08001049 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1050 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -08001051 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001052 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001053 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001054 break;
1055
Meng Wang1a7c35a2016-05-05 20:56:15 -07001056 case CMD_SET_ALLOWED_CARRIERS:
1057 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001058 CarrierRestrictionRules argument =
1059 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001060 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001061 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001062 break;
1063
1064 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
1067 if (ar.exception == null && ar.result != null) {
1068 request.result = ar.result;
1069 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001070 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1071 if (ar.exception instanceof CommandException) {
1072 loge("setAllowedCarriers: CommandException: " + ar.exception);
1073 CommandException.Error error =
1074 ((CommandException) (ar.exception)).getCommandError();
1075 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1076 request.result =
1077 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1078 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001079 } else {
1080 loge("setAllowedCarriers: Unknown exception");
1081 }
1082 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001083 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001084 break;
1085
1086 case CMD_GET_ALLOWED_CARRIERS:
1087 request = (MainThreadRequest) msg.obj;
1088 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001089 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001090 break;
1091
1092 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null && ar.result != null) {
1096 request.result = ar.result;
1097 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001098 request.result = new IllegalStateException(
1099 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001100 if (ar.result == null) {
1101 loge("getAllowedCarriers: Empty response");
1102 } else if (ar.exception instanceof CommandException) {
1103 loge("getAllowedCarriers: CommandException: " +
1104 ar.exception);
1105 } else {
1106 loge("getAllowedCarriers: Unknown exception");
1107 }
1108 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001109 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001110 break;
1111
Nathan Haroldb3014052017-01-25 15:57:32 -08001112 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 if (ar.exception == null && ar.result != null) {
1116 request.result = ar.result;
1117 } else {
1118 request.result = new IllegalArgumentException(
1119 "Failed to retrieve Forbidden Plmns");
1120 if (ar.result == null) {
1121 loge("getForbiddenPlmns: Empty response");
1122 } else {
1123 loge("getForbiddenPlmns: Unknown exception");
1124 }
1125 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001127 break;
1128
1129 case CMD_GET_FORBIDDEN_PLMNS:
1130 request = (MainThreadRequest) msg.obj;
1131 uiccCard = getUiccCardFromRequest(request);
1132 if (uiccCard == null) {
1133 loge("getForbiddenPlmns() UiccCard is null");
1134 request.result = new IllegalArgumentException(
1135 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001136 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001137 break;
1138 }
1139 Integer appType = (Integer) request.argument;
1140 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1141 if (uiccApp == null) {
1142 loge("getForbiddenPlmns() no app with specified type -- "
1143 + appType);
1144 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001145 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001146 break;
1147 } else {
1148 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1149 + " specified type -- " + appType);
1150 }
1151 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1152 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1153 onCompleted);
1154 break;
1155
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001156 case CMD_SWITCH_SLOTS:
1157 request = (MainThreadRequest) msg.obj;
1158 int[] physicalSlots = (int[]) request.argument;
1159 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1160 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1161 break;
1162
1163 case EVENT_SWITCH_SLOTS_DONE:
1164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
1166 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
1168 break;
1169 case CMD_GET_NETWORK_SELECTION_MODE:
1170 request = (MainThreadRequest) msg.obj;
1171 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1172 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1173 break;
1174
1175 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
1178 if (ar.exception != null) {
1179 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1180 } else {
1181 int mode = ((int[]) ar.result)[0];
1182 if (mode == 0) {
1183 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1184 } else {
1185 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1186 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001187 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001188 notifyRequester(request);
1189 break;
1190 case CMD_GET_CDMA_ROAMING_MODE:
1191 request = (MainThreadRequest) msg.obj;
1192 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1193 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1194 break;
1195 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 if (ar.exception != null) {
1199 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1200 } else {
1201 request.result = ((int[]) ar.result)[0];
1202 }
1203 notifyRequester(request);
1204 break;
1205 case CMD_SET_CDMA_ROAMING_MODE:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1208 int mode = (int) request.argument;
1209 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1210 break;
1211 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 request.result = ar.exception == null;
1215 notifyRequester(request);
1216 break;
1217 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1218 request = (MainThreadRequest) msg.obj;
1219 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1220 int subscriptionMode = (int) request.argument;
1221 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1222 break;
1223 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
1226 request.result = ar.exception == null;
1227 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001228 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001229 case CMD_GET_ALL_CELL_INFO:
1230 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001231 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001232 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001233 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001234 case EVENT_GET_ALL_CELL_INFO_DONE:
1235 ar = (AsyncResult) msg.obj;
1236 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001237 // If a timeout occurs, the response will be null
1238 request.result = (ar.exception == null && ar.result != null)
1239 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001240 synchronized (request) {
1241 request.notifyAll();
1242 }
1243 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001244 case CMD_REQUEST_CELL_INFO_UPDATE:
1245 request = (MainThreadRequest) msg.obj;
1246 request.phone.requestCellInfoUpdate(request.workSource,
1247 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1248 break;
1249 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
1252 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1253 try {
1254 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001255 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001256 cb.onError(
1257 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1258 ar.exception.getClass().getName(),
1259 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001260 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001261 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001262 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001263 } else {
1264 // use the result as returned
1265 cb.onCellInfo((List<CellInfo>) ar.result);
1266 }
1267 } catch (RemoteException re) {
1268 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1269 }
1270 break;
1271 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 request = (MainThreadRequest) msg.obj;
1273 WorkSource ws = (WorkSource) request.argument;
1274 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001275 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001276 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001277 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
1280 if (ar.exception == null) {
1281 request.result = ar.result;
1282 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001283 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001284 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001285 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001286 }
1287
1288 synchronized (request) {
1289 request.notifyAll();
1290 }
1291 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001292 case CMD_MODEM_REBOOT:
1293 request = (MainThreadRequest) msg.obj;
1294 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001295 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001296 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001297 case EVENT_CMD_MODEM_REBOOT_DONE:
1298 handleNullReturnEvent(msg, "rebootModem");
1299 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001300 case CMD_REQUEST_ENABLE_MODEM:
1301 request = (MainThreadRequest) msg.obj;
1302 boolean enable = (boolean) request.argument;
1303 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001304 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001305 PhoneConfigurationManager.getInstance()
1306 .enablePhone(request.phone, enable, onCompleted);
1307 break;
1308 case EVENT_ENABLE_MODEM_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001312 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001313 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001314 if ((boolean) request.result) {
1315 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1316 updateModemStateMetrics();
1317 } else {
1318 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1319 + ar.exception);
1320 }
1321 notifyRequester(request);
1322 break;
1323 case CMD_GET_MODEM_STATUS:
1324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1326 PhoneConfigurationManager.getInstance()
1327 .getPhoneStatusFromModem(request.phone, onCompleted);
1328 break;
1329 case EVENT_GET_MODEM_STATUS_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 int id = request.phone.getPhoneId();
1333 if (ar.exception == null && ar.result != null) {
1334 request.result = ar.result;
1335 //update the cache as modem status has changed
1336 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1337 (boolean) request.result);
1338 } else {
1339 // Return true if modem status cannot be retrieved. For most cases,
1340 // modem status is on. And for older version modems, GET_MODEM_STATUS
1341 // and disable modem are not supported. Modem is always on.
1342 // TODO: this should be fixed in R to support a third
1343 // status UNKNOWN b/131631629
1344 request.result = true;
1345 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1346 + ar.exception);
1347 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001348 notifyRequester(request);
1349 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001350 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1351 request = (MainThreadRequest) msg.obj;
1352 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1353 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1354 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1355 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1356 break;
1357 }
1358 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
1361 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1362 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1363 args.second.accept(ar.exception == null);
1364 notifyRequester(request);
1365 break;
1366 }
yincheng zhao2737e882019-09-06 17:06:54 -07001367 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1368 ar = (AsyncResult) msg.obj;
1369 request = (MainThreadRequest) ar.userObj;
1370 if (ar.exception == null && ar.result != null) {
1371 request.result = ar.result;
1372 } else {
1373 request.result = -1;
1374 loge("Failed to set Forbidden Plmns");
1375 if (ar.result == null) {
1376 loge("setForbidenPlmns: Empty response");
1377 } else if (ar.exception != null) {
1378 loge("setForbiddenPlmns: Exception: " + ar.exception);
1379 request.result = -1;
1380 } else {
1381 loge("setForbiddenPlmns: Unknown exception");
1382 }
1383 }
1384 notifyRequester(request);
1385 break;
1386 case CMD_SET_FORBIDDEN_PLMNS:
1387 request = (MainThreadRequest) msg.obj;
1388 uiccCard = getUiccCardFromRequest(request);
1389 if (uiccCard == null) {
1390 loge("setForbiddenPlmns: UiccCard is null");
1391 request.result = -1;
1392 notifyRequester(request);
1393 break;
1394 }
1395 Pair<Integer, List<String>> setFplmnsArgs =
1396 (Pair<Integer, List<String>>) request.argument;
1397 appType = setFplmnsArgs.first;
1398 List<String> fplmns = setFplmnsArgs.second;
1399 uiccApp = uiccCard.getApplicationByType(appType);
1400 if (uiccApp == null) {
1401 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1402 request.result = -1;
1403 loge("Failed to get UICC App");
1404 notifyRequester(request);
1405 } else {
1406 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1407 ((SIMRecords) uiccApp.getIccRecords())
1408 .setForbiddenPlmns(onCompleted, fplmns);
1409 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001410 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001411 case CMD_ERASE_MODEM_CONFIG:
1412 request = (MainThreadRequest) msg.obj;
1413 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1414 defaultPhone.eraseModemConfig(onCompleted);
1415 break;
1416 case EVENT_ERASE_MODEM_CONFIG_DONE:
1417 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001418 break;
zoey chene02881a2019-12-30 16:11:23 +08001419
1420 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1423 Pair<String, String> changed = (Pair<String, String>) request.argument;
1424 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1425 changed.first, changed.second, onCompleted);
1426 break;
1427 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception == null) {
1431 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1432 } else {
1433 request.result = msg.arg1;
1434 }
1435 notifyRequester(request);
1436 break;
1437
1438 case CMD_SET_ICC_LOCK_ENABLED:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1441 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1442 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1443 enabled.first, enabled.second, onCompleted);
1444 break;
1445 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null) {
1449 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1450 } else {
1451 request.result = msg.arg1;
1452 }
1453 notifyRequester(request);
1454 break;
1455
Peter Wangdafb9ac2020-01-15 14:13:38 -08001456 case MSG_NOTIFY_USER_ACTIVITY:
1457 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001458 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001459 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1460 getDefaultPhone().getContext().sendBroadcastAsUser(
1461 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1462 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 default:
1464 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1465 break;
1466 }
1467 }
Jake Hambye994d462014-02-03 13:10:13 -08001468
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 private void notifyRequester(MainThreadRequest request) {
1470 synchronized (request) {
1471 request.notifyAll();
1472 }
1473 }
1474
Jake Hambye994d462014-02-03 13:10:13 -08001475 private void handleNullReturnEvent(Message msg, String command) {
1476 AsyncResult ar = (AsyncResult) msg.obj;
1477 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1478 if (ar.exception == null) {
1479 request.result = true;
1480 } else {
1481 request.result = false;
1482 if (ar.exception instanceof CommandException) {
1483 loge(command + ": CommandException: " + ar.exception);
1484 } else {
1485 loge(command + ": Unknown exception");
1486 }
1487 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001488 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 }
1491
1492 /**
1493 * Posts the specified command to be executed on the main thread,
1494 * waits for the request to complete, and returns the result.
1495 * @see #sendRequestAsync
1496 */
1497 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001498 return sendRequest(
1499 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001500 }
1501
1502 /**
1503 * Posts the specified command to be executed on the main thread,
1504 * waits for the request to complete, and returns the result.
1505 * @see #sendRequestAsync
1506 */
1507 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1508 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001509 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001510 }
1511
1512 /**
1513 * Posts the specified command to be executed on the main thread,
1514 * waits for the request to complete, and returns the result.
1515 * @see #sendRequestAsync
1516 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001517 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001518 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001519 }
1520
1521 /**
1522 * Posts the specified command to be executed on the main thread,
1523 * waits for the request to complete, and returns the result.
1524 * @see #sendRequestAsync
1525 */
Nathan Harold92bed182018-10-12 18:16:49 -07001526 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1527 return sendRequest(command, argument, subId, null, workSource);
1528 }
1529
1530 /**
1531 * Posts the specified command to be executed on the main thread,
1532 * waits for the request to complete, and returns the result.
1533 * @see #sendRequestAsync
1534 */
1535 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1536 return sendRequest(
1537 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1538 }
1539
1540 /**
1541 * Posts the specified command to be executed on the main thread,
1542 * waits for the request to complete, and returns the result.
1543 * @see #sendRequestAsync
1544 */
1545 private Object sendRequest(
1546 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1548 throw new RuntimeException("This method will deadlock if called from the main thread.");
1549 }
1550
Nathan Harold92bed182018-10-12 18:16:49 -07001551 MainThreadRequest request = null;
1552 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1553 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1554 } else if (phone != null) {
1555 request = new MainThreadRequest(argument, phone, workSource);
1556 } else {
1557 request = new MainThreadRequest(argument, subId, workSource);
1558 }
1559
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 Message msg = mMainThreadHandler.obtainMessage(command, request);
1561 msg.sendToTarget();
1562
1563 // Wait for the request to complete
1564 synchronized (request) {
1565 while (request.result == null) {
1566 try {
1567 request.wait();
1568 } catch (InterruptedException e) {
1569 // Do nothing, go back and wait until the request is complete
1570 }
1571 }
1572 }
1573 return request.result;
1574 }
1575
1576 /**
1577 * Asynchronous ("fire and forget") version of sendRequest():
1578 * Posts the specified command to be executed on the main thread, and
1579 * returns immediately.
1580 * @see #sendRequest
1581 */
1582 private void sendRequestAsync(int command) {
1583 mMainThreadHandler.sendEmptyMessage(command);
1584 }
1585
1586 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001587 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001588 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001589 */
1590 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001591 sendRequestAsync(command, argument, null, null);
1592 }
1593
1594 /**
1595 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1596 * @see {@link #sendRequest(int,Object)}
1597 */
1598 private void sendRequestAsync(
1599 int command, Object argument, Phone phone, WorkSource workSource) {
1600 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001601 Message msg = mMainThreadHandler.obtainMessage(command, request);
1602 msg.sendToTarget();
1603 }
1604
1605 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 * Initialize the singleton PhoneInterfaceManager instance.
1607 * This is only done once, at startup, from PhoneApp.onCreate().
1608 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001609 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 synchronized (PhoneInterfaceManager.class) {
1611 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001612 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 } else {
1614 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1615 }
1616 return sInstance;
1617 }
1618 }
1619
1620 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001621 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001624 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001625 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001626 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1627 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001628 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001629 mTelephonySharedPreferences =
1630 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001631 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001632 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001633 mNotifyUserActivity = new AtomicBoolean(false);
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")
Hall Liu773ba022020-01-24 18:07:12 -08002253 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002254 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2255 .build());
2256 switch (locationResult) {
2257 case DENIED_HARD:
2258 throw new SecurityException("Not allowed to access cell location");
2259 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002260 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2261 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002268 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002269 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
Svetoslav64fad262015-04-14 14:35:21 -07002273 }
2274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002276 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2277 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002278 if (!TextUtils.isEmpty(callingPackage)) {
2279 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2281 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002282 return "";
2283 }
2284 }
2285
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002286 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2287 // registered cell info, so return a NULL country instead.
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002290 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2291 // Get default phone in this case.
2292 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2293 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002294 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002295 // Todo: fix this when we can get the actual cellular network info when the device
2296 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002297 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002298 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2299 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002300 return "";
2301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 Phone phone = PhoneFactory.getPhone(phoneId);
2303 if (phone != null) {
2304 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002305 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 if (sst != null) {
2307 LocaleTracker lt = sst.getLocaleTracker();
2308 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002309 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2310 return lt.getCurrentCountry();
2311 } else if (emergencyNumberTracker != null) {
2312 return emergencyNumberTracker.getEmergencyCountryIso();
2313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314 }
2315 }
2316 }
2317 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002321 }
2322
2323 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002325 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002326 }
2327
Sanket Padawe356d7632015-06-22 14:03:32 -07002328 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002329 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 mApp.enforceCallingOrSelfPermission(
2331 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332
2333 final long identity = Binder.clearCallingIdentity();
2334 try {
2335 final Phone phone = getPhone(subId);
2336 if (phone != null) {
2337 phone.enableLocationUpdates();
2338 }
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
2344 @Override
2345 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002346 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002347 }
2348
Sanket Padawe356d7632015-06-22 14:03:32 -07002349 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002350 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 mApp.enforceCallingOrSelfPermission(
2352 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353
2354 final long identity = Binder.clearCallingIdentity();
2355 try {
2356 final Phone phone = getPhone(subId);
2357 if (phone != null) {
2358 phone.disableLocationUpdates();
2359 }
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 }
2364
Nathan Harold31d7ff32018-10-15 20:20:30 -07002365 /**
2366 * Returns the target SDK version number for a given package name.
2367 *
Nathan Haroldec184742019-07-10 17:04:16 -07002368 * This call MUST be invoked before clearing the calling UID.
2369 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002370 * @return target SDK if the package is found or INT_MAX.
2371 */
2372 private int getTargetSdk(String packageName) {
2373 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002374 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002375 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002376 if (ai != null) return ai.targetSdkVersion;
2377 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002378 loge("Failed to get package info for pkg="
2379 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002380 }
2381 return Integer.MAX_VALUE;
2382 }
2383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 @Override
2385 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002386 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2387 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002388 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002389 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2390 throw new SecurityException(
2391 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2392 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002393
Jordan Liu1617b712019-07-10 15:06:26 -07002394 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2396 return null;
2397 }
Svetoslav64fad262015-04-14 14:35:21 -07002398
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002399 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002401 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002402 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403
Nathan Haroldf180aac2018-06-01 18:43:55 -07002404 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2405 for (CellInfo ci : info) {
2406 if (ci instanceof CellInfoGsm) {
2407 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2408 } else if (ci instanceof CellInfoWcdma) {
2409 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002412 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 }
2414
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002415 private List<CellInfo> getCachedCellInfo() {
2416 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2417 for (Phone phone : PhoneFactory.getPhones()) {
2418 List<CellInfo> info = phone.getAllCellInfo();
2419 if (info != null) cellInfos.addAll(info);
2420 }
2421 return cellInfos;
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423
2424 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002425 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002426 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002427 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002428
2429 LocationAccessPolicy.LocationPermissionResult locationResult =
2430 LocationAccessPolicy.checkLocationPermission(mApp,
2431 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2432 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002433 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002434 .setCallingPid(Binder.getCallingPid())
2435 .setCallingUid(Binder.getCallingUid())
2436 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002437 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002438 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2439 .build());
2440 switch (locationResult) {
2441 case DENIED_HARD:
2442 throw new SecurityException("Not allowed to access cell info");
2443 case DENIED_SOFT:
2444 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002447 final int targetSdk = getTargetSdk(callingPackage);
2448 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2449 return getCachedCellInfo();
2450 }
2451
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002452 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2457 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002458 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002459 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 if (info != null) cellInfos.addAll(info);
2461 }
2462 return cellInfos;
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466 }
2467
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002468 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002469 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2470 String callingFeatureId) {
2471 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2472 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002473 }
2474
2475 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002476 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2477 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002478 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002479 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002480 }
2481
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002482 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2483 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002484 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002485 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002486
2487 LocationAccessPolicy.LocationPermissionResult locationResult =
2488 LocationAccessPolicy.checkLocationPermission(mApp,
2489 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2490 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002491 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002492 .setCallingPid(Binder.getCallingPid())
2493 .setCallingUid(Binder.getCallingUid())
2494 .setMethod("requestCellInfoUpdate")
2495 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2496 .build());
2497 switch (locationResult) {
2498 case DENIED_HARD:
2499 throw new SecurityException("Not allowed to access cell info");
2500 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002501 try {
2502 cb.onCellInfo(new ArrayList<CellInfo>());
2503 } catch (RemoteException re) {
2504 // Drop without consequences
2505 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002506 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002507 }
2508
Nathan Harolda939a962019-05-09 10:13:47 -07002509
2510 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002511 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2512
2513 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2514 }
2515
2516 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002518 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520
2521 final long identity = Binder.clearCallingIdentity();
2522 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002523 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 } finally {
2525 Binder.restoreCallingIdentity(identity);
2526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
Shishir Agrawala9f32182016-04-12 12:00:16 -07002529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002530 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002531 Phone phone = PhoneFactory.getPhone(slotIndex);
2532 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002533 return null;
2534 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002535 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002536 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002537 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 return null;
2539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540
2541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 return phone.getImei();
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002547 }
2548
2549 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002550 public String getTypeAllocationCodeForSlot(int slotIndex) {
2551 Phone phone = PhoneFactory.getPhone(slotIndex);
2552 String tac = null;
2553 if (phone != null) {
2554 String imei = phone.getImei();
2555 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2556 }
2557 return tac;
2558 }
2559
2560 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 Phone phone = PhoneFactory.getPhone(slotIndex);
2563 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002564 return null;
2565 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002566
Jeff Davidson913390f2018-02-23 17:11:49 -08002567 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002568 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002569 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002570 return null;
2571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 return phone.getMeid();
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
2578 }
Jack Yu2af8d712017-03-15 17:14:14 -07002579 }
2580
2581 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002582 public String getManufacturerCodeForSlot(int slotIndex) {
2583 Phone phone = PhoneFactory.getPhone(slotIndex);
2584 String manufacturerCode = null;
2585 if (phone != null) {
2586 String meid = phone.getMeid();
2587 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2588 }
2589 return manufacturerCode;
2590 }
2591
2592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2594 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002595 Phone phone = PhoneFactory.getPhone(slotIndex);
2596 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002597 return null;
2598 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002599 int subId = phone.getSubId();
2600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002601 mApp, subId, callingPackage, callingFeatureId,
2602 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 return null;
2604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 return phone.getDeviceSvn();
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
2611 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002612 }
2613
fionaxu43304da2017-11-27 22:51:16 -08002614 @Override
2615 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 final Phone phone = getPhone(subId);
2619 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
fionaxu43304da2017-11-27 22:51:16 -08002623 }
2624
2625 @Override
2626 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 return phone == null ? null : phone.getCarrierName();
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
fionaxu43304da2017-11-27 22:51:16 -08002634 }
2635
calvinpanffe225e2018-11-01 19:43:06 +08002636 @Override
chen xu0026ca62019-03-06 15:28:50 -08002637 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002642 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002643 } finally {
2644 Binder.restoreCallingIdentity(identity);
2645 }
2646 }
2647
2648 @Override
chen xu0026ca62019-03-06 15:28:50 -08002649 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002653 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002654 } finally {
2655 Binder.restoreCallingIdentity(identity);
2656 }
2657 }
2658
chen xu651eec72018-11-11 19:03:44 -08002659 @Override
chen xu864e11c2018-12-06 22:10:03 -08002660 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2661 if (!isSubscriptionMccMnc) {
2662 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2663 }
chen xu651eec72018-11-11 19:03:44 -08002664 final Phone phone = PhoneFactory.getPhone(slotIndex);
2665 if (phone == null) {
2666 return TelephonyManager.UNKNOWN_CARRIER_ID;
2667 }
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
2674 }
2675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 //
2677 // Internal helper methods.
2678 //
2679
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002680 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2682 *
2683 * @throws SecurityException if the caller does not have the required permission
2684 */
2685 private void enforceModifyPermission() {
2686 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2687 }
2688
Shuo Qiancd19c462020-01-16 20:51:11 -08002689 /**
2690 * Make sure the caller is system.
2691 *
2692 * @throws SecurityException if the caller is not system.
2693 */
2694 private void enforceSystemCaller() {
2695 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2696 throw new SecurityException("Caller must be system");
2697 }
2698 }
2699
Shuo Qian3b6ee772019-11-13 17:43:31 -08002700 private void enforceActiveEmergencySessionPermission() {
2701 mApp.enforceCallingOrSelfPermission(
2702 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2703 }
2704
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 /**
2706 * Make sure the caller has the CALL_PHONE permission.
2707 *
2708 * @throws SecurityException if the caller does not have the required permission
2709 */
2710 private void enforceCallPermission() {
2711 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2712 }
2713
paulhu5a773602019-08-23 19:17:33 +08002714 private void enforceSettingsPermission() {
2715 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002716 }
2717
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 private String createTelUrl(String number) {
2719 if (TextUtils.isEmpty(number)) {
2720 return null;
2721 }
2722
Jake Hambye994d462014-02-03 13:10:13 -08002723 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Ihab Awadf9e92732013-12-05 18:02:52 -08002726 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2728 }
2729
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002730 private static void logv(String msg) {
2731 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2732 }
2733
Ihab Awadf9e92732013-12-05 18:02:52 -08002734 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2736 }
2737
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002738 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002740 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
Sanket Padawe356d7632015-06-22 14:03:32 -07002743 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002744 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 final Phone phone = PhoneFactory.getPhone(slotIndex);
2748 if (phone == null) {
2749 return PhoneConstants.PHONE_TYPE_NONE;
2750 } else {
2751 return phone.getPhoneType();
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
2757
2758 /**
2759 * Returns the CDMA ERI icon index to display
2760 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002762 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2763 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2764 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002768 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2769 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002771 mApp, subId, callingPackage, callingFeatureId,
2772 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002773 return -1;
2774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 final Phone phone = getPhone(subId);
2779 if (phone != null) {
2780 return phone.getCdmaEriIconIndex();
2781 } else {
2782 return -1;
2783 }
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788
2789 /**
2790 * Returns the CDMA ERI icon mode,
2791 * 0 - ON
2792 * 1 - FLASHING
2793 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002794 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2796 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2797 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002798 }
2799
Sanket Padawe356d7632015-06-22 14:03:32 -07002800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002801 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2802 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002804 mApp, subId, callingPackage, callingFeatureId,
2805 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002806 return -1;
2807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone phone = getPhone(subId);
2812 if (phone != null) {
2813 return phone.getCdmaEriIconMode();
2814 } else {
2815 return -1;
2816 }
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821
2822 /**
2823 * Returns the CDMA ERI text,
2824 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002825 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002826 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2827 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2828 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002832 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2833 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002835 mApp, subId, callingPackage, callingFeatureId,
2836 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002837 return null;
2838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 final Phone phone = getPhone(subId);
2843 if (phone != null) {
2844 return phone.getCdmaEriText();
2845 } else {
2846 return null;
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
2853 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002854 * Returns the CDMA MDN.
2855 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002857 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2859 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 return phone.getLine1Number();
2866 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002867 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 return null;
2869 }
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002872 }
2873 }
2874
2875 /**
2876 * Returns the CDMA MIN.
2877 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002879 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2881 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 final Phone phone = getPhone(subId);
2886 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2887 return phone.getCdmaMin();
2888 } else {
2889 return null;
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002893 }
2894 }
2895
Hall Liud892bec2018-11-30 14:51:45 -08002896 @Override
2897 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2898 INumberVerificationCallback callback, String callingPackage) {
2899 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2900 != PERMISSION_GRANTED) {
2901 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2902 }
2903 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2904
2905 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2906 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2907 throw new SecurityException("Calling package must be configured in the device config");
2908 }
2909
2910 if (range == null) {
2911 throw new NullPointerException("Range must be non-null");
2912 }
2913
2914 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002915 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002916
2917 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2918 }
2919
Junda Liuca05d5d2014-08-14 22:36:34 -07002920 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 * Returns true if CDMA provisioning needs to run.
2922 */
2923 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 final long identity = Binder.clearCallingIdentity();
2925 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002926 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
2932 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002933 * Sets the voice mail number of a given subId.
2934 */
2935 @Override
2936 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002937 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2938 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2943 new Pair<String, String>(alphaTag, number), new Integer(subId));
2944 return success;
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002948 }
2949
Ta-wei Yen87c49842016-05-13 21:19:52 -07002950 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002951 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002953 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2954 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002955 if (!TextUtils.equals(callingPackage, systemDialer)) {
2956 throw new SecurityException("caller must be system dialer");
2957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2962 if (phoneAccountHandle == null) {
2963 return null;
2964 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002968 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002969 }
2970
2971 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002972 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2973 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002976 mApp, subId, callingPackage, callingFeatureId,
2977 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002978 return null;
2979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002981 final long identity = Binder.clearCallingIdentity();
2982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002987 }
2988
2989 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002990 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2991 VisualVoicemailSmsFilterSettings settings) {
2992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002997 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003001 }
3002
3003 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003004 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006
3007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003014 }
3015
3016 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003017 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3018 String callingPackage, int subId) {
3019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003028 }
3029
3030 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003031 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003041 }
3042
3043 @Override
3044 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3045 String number, int port, String text, PendingIntent sentIntent) {
3046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003047 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003048 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003049 SmsController smsController = PhoneFactory.getSmsController();
3050 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3051 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003052 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003053
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003054 /**
fionaxu0152e512016-11-14 13:36:14 -08003055 * Sets the voice activation state of a given subId.
3056 */
3057 @Override
3058 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3060 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 final Phone phone = getPhone(subId);
3065 if (phone != null) {
3066 phone.setVoiceActivationState(activationState);
3067 } else {
3068 loge("setVoiceActivationState fails with invalid subId: " + subId);
3069 }
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003072 }
3073 }
3074
3075 /**
3076 * Sets the data activation state of a given subId.
3077 */
3078 @Override
3079 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3081 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 final Phone phone = getPhone(subId);
3086 if (phone != null) {
3087 phone.setDataActivationState(activationState);
3088 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003089 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003093 }
3094 }
3095
3096 /**
3097 * Returns the voice activation state of a given subId.
3098 */
3099 @Override
3100 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
fionaxu0152e512016-11-14 13:36:14 -08003103 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 if (phone != null) {
3107 return phone.getVoiceActivationState();
3108 } else {
3109 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3110 }
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003113 }
3114 }
3115
3116 /**
3117 * Returns the data activation state of a given subId.
3118 */
3119 @Override
3120 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
fionaxu0152e512016-11-14 13:36:14 -08003123 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 if (phone != null) {
3127 return phone.getDataActivationState();
3128 } else {
3129 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3130 }
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003133 }
3134 }
3135
3136 /**
Wink Saville36469e72014-06-11 15:17:00 -07003137 * Returns the unread count of voicemails for a subId
3138 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003140 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3141 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003143 mApp, subId, callingPackage, callingFeatureId,
3144 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003145 return 0;
3146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 final Phone phone = getPhone(subId);
3150 if (phone != null) {
3151 return phone.getVoiceMessageCount();
3152 } else {
3153 return 0;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
3160 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003161 * returns true, if the device is in a state where both voice and data
3162 * are supported simultaneously. This can change based on location or network condition.
3163 */
3164 @Override
3165 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 final Phone phone = getPhone(subId);
3169 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
3172 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003173 }
3174
3175 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003176 * Send the dialer code if called from the current default dialer or the caller has
3177 * carrier privilege.
3178 * @param inputCode The dialer code to send
3179 */
3180 @Override
3181 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003184 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3185 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003186 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003187 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003188 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003193 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
fionaxu235cc5e2017-03-06 22:25:57 -08003197 }
3198
Pengquan Menga1bb6272018-09-06 09:59:22 -07003199 @Override
3200 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003201 TelephonyPermissions
3202 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3203 mApp, subId, "getNetworkSelectionMode");
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 if (!isActiveSubscription(subId)) {
3207 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3208 }
3209 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003212 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003213 }
3214
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003216 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3217 String callingFeatureId) {
3218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3219 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3220 return null;
3221 }
3222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 return mPhoneConfigurationManager.getStaticPhoneCapability();
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003231 public boolean isInEmergencySmsMode() {
3232 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 for (Phone phone : PhoneFactory.getPhones()) {
3236 if (phone.isInEmergencySmsMode()) {
3237 return true;
3238 }
3239 }
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 return false;
3244 }
3245
shilu366312e2019-12-17 09:28:10 -08003246 /**
3247 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3248 * @param subId The subscription to use to check the configuration.
3249 * @param c The callback that will be used to send the result.
3250 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003251 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003252 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3253 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003254 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3255 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003256
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003257 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3258 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3259 "IMS not available on device.");
3260 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 final long token = Binder.clearCallingIdentity();
3262 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003263 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003265 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003266 } catch (ImsException e) {
3267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 } finally {
3269 Binder.restoreCallingIdentity(token);
3270 }
3271 }
3272
shilu366312e2019-12-17 09:28:10 -08003273 /**
3274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3275 * @param subId The subscription to use to check the configuration.
3276 * @param c The callback that will be used to send the result.
3277 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003279 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003280 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3281 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003282 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3283 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3284 }
Meng Wangafbc5852019-09-19 17:37:13 -07003285 final long token = Binder.clearCallingIdentity();
3286 try {
3287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3288 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3289 .removeRegistrationCallbackForSubscription(c, subId);
3290 } catch (ImsException e) {
3291 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3292 + "is inactive, ignoring unregister.");
3293 // If the subscription is no longer active, just return, since the callback
3294 // will already have been removed internally.
3295 } finally {
3296 Binder.restoreCallingIdentity(token);
3297 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 }
3299
Brad Ebingera34a6c22019-10-22 17:36:18 -07003300 /**
3301 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3302 */
3303 @Override
3304 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3305 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3306 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3307 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3308 "IMS not available on device.");
3309 }
3310 final long token = Binder.clearCallingIdentity();
3311 try {
3312 Phone phone = getPhone(subId);
3313 if (phone == null) {
3314 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3315 + subId + "'");
3316 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3317 }
3318 phone.getImsRegistrationState(regState -> {
3319 try {
3320 consumer.accept((regState == null)
3321 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3322 } catch (RemoteException e) {
3323 // Ignore if the remote process is no longer available to call back.
3324 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3325 }
3326 });
3327 } finally {
3328 Binder.restoreCallingIdentity(token);
3329 }
3330 }
3331
3332 /**
3333 * Get the transport type for the IMS service registration state.
3334 */
3335 @Override
3336 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003337 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3338 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003339 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3340 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3341 "IMS not available on device.");
3342 }
3343 final long token = Binder.clearCallingIdentity();
3344 try {
3345 Phone phone = getPhone(subId);
3346 if (phone == null) {
3347 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3348 + subId + "'");
3349 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3350 }
3351 phone.getImsRegistrationTech(regTech -> {
3352 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3353 int regTechConverted = (regTech == null)
3354 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3355 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3356 regTechConverted);
3357 try {
3358 consumer.accept(regTechConverted);
3359 } catch (RemoteException e) {
3360 // Ignore if the remote process is no longer available to call back.
3361 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3362 }
3363 });
3364 } finally {
3365 Binder.restoreCallingIdentity(token);
3366 }
3367 }
3368
shilu366312e2019-12-17 09:28:10 -08003369 /**
3370 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3371 * @param subId The subscription to use to check the configuration.
3372 * @param c The callback that will be used to send the result.
3373 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003375 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3376 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003377 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3378 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003379 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3380 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3381 "IMS not available on device.");
3382 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3384 final long token = Binder.clearCallingIdentity();
3385 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003386 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003388 } catch (ImsException e) {
3389 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 } finally {
3391 Binder.restoreCallingIdentity(token);
3392 }
3393 }
3394
shilu366312e2019-12-17 09:28:10 -08003395 /**
3396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3397 * @param subId The subscription to use to check the configuration.
3398 * @param c The callback that will be used to send the result.
3399 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003401 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003402 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3403 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003404 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3405 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3406 }
Meng Wangafbc5852019-09-19 17:37:13 -07003407
3408 final long token = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3411 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003412 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003413 } catch (ImsException e) {
3414 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3415 + "is inactive, ignoring unregister.");
3416 // If the subscription is no longer active, just return, since the callback
3417 // will already have been removed internally.
3418 } finally {
3419 Binder.restoreCallingIdentity(token);
3420 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 }
3422
3423 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003424 public boolean isCapable(int subId, int capability, int regTech) {
3425 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3427 final long token = Binder.clearCallingIdentity();
3428 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003429 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003431 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3433 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003434 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003435 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3436 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003437 } finally {
3438 Binder.restoreCallingIdentity(token);
3439 }
3440 }
3441
3442 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003443 public boolean isAvailable(int subId, int capability, int regTech) {
3444 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 final long token = Binder.clearCallingIdentity();
3446 try {
3447 Phone phone = getPhone(subId);
3448 if (phone == null) return false;
3449 return phone.isImsCapabilityAvailable(capability, regTech);
3450 } finally {
3451 Binder.restoreCallingIdentity(token);
3452 }
3453 }
3454
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003455 /**
3456 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3457 * subscription.
3458 * @param subId The subscription to use to check the configuration.
3459 * @param callback The callback that will be used to send the result.
3460 * @param capability The MmTelFeature capability that will be used to send the result.
3461 * @param transportType The transport type of the MmTelFeature capability.
3462 */
3463 @Override
3464 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3465 int transportType) {
3466 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3467 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3468 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3469 "IMS not available on device.");
3470 }
3471 final long token = Binder.clearCallingIdentity();
3472 try {
3473 int slotId = getSlotIndex(subId);
3474 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3475 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3476 + subId + "'");
3477 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3478 }
3479 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3480 transportType, aBoolean -> {
3481 try {
3482 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3483 } catch (RemoteException e) {
3484 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3485 + "running. Ignore");
3486 }
3487 });
3488 } finally {
3489 Binder.restoreCallingIdentity(token);
3490 }
3491 }
3492
shilu366312e2019-12-17 09:28:10 -08003493 /**
3494 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3495 * @param subId The subscription to use to check the configuration.
3496 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 @Override
3498 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003499 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3500 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003501
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3503 final long token = Binder.clearCallingIdentity();
3504 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003507 } catch (ImsException e) {
3508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 } finally {
3510 Binder.restoreCallingIdentity(token);
3511 }
3512 }
3513
3514 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003515 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003517 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003523 } catch (ImsException e) {
3524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
3528 }
3529
shilu366312e2019-12-17 09:28:10 -08003530 /**
3531 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3532 * @param subId The subscription to use to check the configuration.
3533 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003535 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003536 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3537 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3542 } catch (ImsException e) {
3543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003550 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003552 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003556 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003557 } catch (ImsException e) {
3558 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
3562 }
3563
shilu366312e2019-12-17 09:28:10 -08003564 /**
3565 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3566 * @param subId The subscription to use to check the configuration.
3567 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 @Override
3569 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003570 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3571 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003577 } catch (ImsException e) {
3578 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
3582 }
3583
3584 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003585 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003587 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003592 } catch (ImsException e) {
3593 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597 }
3598
shilu366312e2019-12-17 09:28:10 -08003599 /**
3600 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3601 * @param subId The subscription to use to check the configuration.
3602 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 @Override
3604 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003605 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3606 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003620 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003622 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003628 } catch (ImsException e) {
3629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
3633 }
3634
3635 @Override
3636 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3638 "setVoWiFiNonPersistent");
3639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003642 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003643 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003644 } catch (ImsException e) {
3645 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
3649 }
3650
shilu366312e2019-12-17 09:28:10 -08003651 /**
3652 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3653 * @param subId The subscription to use to check the configuration.
3654 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 @Override
3656 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003657 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3658 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (ImsException e) {
3665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670
3671 @Override
3672 public void setVoWiFiModeSetting(int subId, int mode) {
3673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3674 "setVoWiFiModeSetting");
3675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003680 } catch (ImsException e) {
3681 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
3685 }
3686
3687 @Override
3688 public int getVoWiFiRoamingModeSetting(int subId) {
3689 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003695 } catch (ImsException e) {
3696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
3700 }
3701
3702 @Override
3703 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3705 "setVoWiFiRoamingModeSetting");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003709 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003711 } catch (ImsException e) {
3712 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
3716 }
3717
3718 @Override
3719 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3721 "setRttCapabilityEnabled");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3726 } catch (ImsException e) {
3727 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
3731 }
3732
shilu366312e2019-12-17 09:28:10 -08003733 /**
3734 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3735 * @param subId The subscription to use to check the configuration.
3736 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 @Override
3738 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003739 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3740 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003744 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003746 } catch (ImsException e) {
3747 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
3751 }
3752
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003753 @Override
3754 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3755 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3756 final long identity = Binder.clearCallingIdentity();
3757 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003758 if (!isImsAvailableOnDevice()) {
3759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3760 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003761 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003762 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003764 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003765 } catch (ImsException e) {
3766 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
3770 }
3771
3772 @Override
3773 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3774 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3775 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3778 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003779 try {
3780 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003781 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003782 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003783 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003784 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3785 + "is inactive, ignoring unregister.");
3786 // If the subscription is no longer active, just return, since the callback will already
3787 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
allenwtsu99c623b2020-01-03 18:24:23 +08003793
3794 private void checkModifyPhoneStatePermission(int subId, String message) {
3795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3796 message);
3797 }
3798
3799 private boolean isImsProvisioningRequired(int subId, int capability,
3800 boolean isMmtelCapability) {
3801 Phone phone = getPhone(subId);
3802 if (phone == null) {
3803 loge("phone instance null for subid " + subId);
3804 return false;
3805 }
3806 if (isMmtelCapability) {
3807 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3808 return false;
3809 }
3810 } else {
3811 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3812 return false;
3813 }
3814 }
3815 return true;
3816 }
3817
3818 @Override
3819 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3820 boolean isProvisioned) {
3821 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3822
3823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3826 if (!isImsProvisioningRequired(subId, capability, false)) {
3827 return;
3828 }
3829
3830 // this capability requires provisioning, route to the correct API.
3831 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3832 switch (capability) {
3833 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3834 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3835 ims.setEabProvisioned(isProvisioned);
3836 break;
3837 default: {
3838 throw new IllegalArgumentException("Tried to set provisioning for "
3839 + "rcs capability '" + capability + "', which does not require "
3840 + "provisioning.");
3841 }
3842 }
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
3845 }
3846
3847 }
3848
3849
3850 @Override
3851 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3852 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3856 if (!isImsProvisioningRequired(subId, capability, false)) {
3857 return true;
3858 }
3859
3860 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3861 switch (capability) {
3862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3863 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3864 return ims.isEabProvisionedOnDevice();
3865
3866 default: {
3867 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3868 + "capability '" + capability + "', which does not require "
3869 + "provisioning.");
3870 }
3871 }
3872
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
3876 }
3877
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003878 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003879 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3880 boolean isProvisioned) {
3881 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3882 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3883 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3884 }
allenwtsu99c623b2020-01-03 18:24:23 +08003885 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003889 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003890 return;
3891 }
3892
3893 // this capability requires provisioning, route to the correct API.
3894 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3895 switch (capability) {
3896 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3897 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3898 ims.setVolteProvisioned(isProvisioned);
3899 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3900 ims.setWfcProvisioned(isProvisioned);
3901 }
3902 break;
3903 }
3904 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3905 // There is currently no difference in VT provisioning type.
3906 ims.setVtProvisioned(isProvisioned);
3907 break;
3908 }
3909 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3910 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3911 // change the capability of the feature instead if needed.
3912 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3913 == isProvisioned) {
3914 // No change in provisioning.
3915 return;
3916 }
3917 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3918 try {
3919 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003920 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003921 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3922 + ", Exception" + e.getMessage());
3923 }
3924 break;
3925 }
3926 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003927 throw new IllegalArgumentException("Tried to set provisioning for "
3928 + "MmTel capability '" + capability + "', which does not require "
3929 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003930 }
3931 }
3932
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
3936 }
3937
3938 @Override
3939 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3940 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3941 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3942 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3943 }
3944 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003948 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003949 return true;
3950 }
3951
3952 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3953 switch (capability) {
3954 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3955 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3956 return ims.isVolteProvisionedOnDevice();
3957 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3958 return ims.isWfcProvisionedOnDevice();
3959 }
3960 // This should never happen, since we are checking tech above to make sure it
3961 // is either LTE or IWLAN.
3962 throw new IllegalArgumentException("Invalid radio technology for voice "
3963 + "capability.");
3964 }
3965 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3966 // There is currently no difference in VT provisioning type.
3967 return ims.isVtProvisionedOnDevice();
3968 }
3969 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3970 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3971 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3972 }
3973 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003974 throw new IllegalArgumentException(
3975 "Tried to get provisioning for MmTel capability '" + capability
3976 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003977 }
3978 }
3979
3980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
3983 }
3984
3985 @Override
3986 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3987 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3988 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3989 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3990 }
3991 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3992 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3993 return (provisionedBits & capability) > 0;
3994 }
3995
3996 @Override
3997 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3998 boolean isProvisioned) {
3999 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4000 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4001 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4002 }
4003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4004 "setProvisioningStatusForCapability");
4005 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4006 // If the current provisioning status for capability already matches isProvisioned,
4007 // do nothing.
4008 if (((provisionedBits & capability) > 0) == isProvisioned) {
4009 return;
4010 }
4011 if (isProvisioned) {
4012 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4013 } else {
4014 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4015 }
4016 }
4017
4018 /**
4019 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4020 * technology. The bitfield should mirror the bitfield defined by
4021 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4022 */
4023 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4024 String key = getMmTelProvisioningKey(subId, tech);
4025 // Default is no capabilities are provisioned.
4026 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4027 }
4028
4029 /**
4030 * Sets the MmTel capability provisioning bitfield (defined by
4031 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4032 * technology specified.
4033 *
4034 * Note: This is a synchronous command and should not be called on UI thread.
4035 */
4036 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4037 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4038 String key = getMmTelProvisioningKey(subId, tech);
4039 editor.putInt(key, newField);
4040 editor.commit();
4041 }
4042
4043 private static String getMmTelProvisioningKey(int subId, int tech) {
4044 // resulting key is provision_ims_mmtel_{subId}_{tech}
4045 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4046 }
4047
4048 /**
4049 * Query CarrierConfig to see if the specified capability requires provisioning for the
4050 * carrier associated with the subscription id.
4051 */
4052 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4053 int capability) {
4054 CarrierConfigManager configManager = new CarrierConfigManager(context);
4055 PersistableBundle c = configManager.getConfigForSubId(subId);
4056 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004057 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004058 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4059 false);
4060 boolean requireVoiceVtProvisioning = c.getBoolean(
4061 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4062
4063 // First check to make sure that the capability requires provisioning.
4064 switch (capability) {
4065 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4066 // intentional fallthrough
4067 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4068 if (requireVoiceVtProvisioning) {
4069 // Voice and Video requires provisioning
4070 return true;
4071 }
4072 break;
4073 }
4074 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4075 if (requireUtProvisioning) {
4076 // UT requires provisioning
4077 return true;
4078 }
4079 break;
4080 }
4081 }
4082 return false;
4083 }
4084
allenwtsu99c623b2020-01-03 18:24:23 +08004085 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4086 int capability) {
4087 CarrierConfigManager configManager = new CarrierConfigManager(context);
4088 PersistableBundle c = configManager.getConfigForSubId(subId);
4089
4090 boolean requireRcsProvisioning = c.getBoolean(
4091 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4092
4093 // First check to make sure that the capability requires provisioning.
4094 switch (capability) {
4095 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4096 // intentional fallthrough
4097 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4098 if (requireRcsProvisioning) {
4099 // OPTION or PRESENCE requires provisioning
4100 return true;
4101 }
4102 break;
4103 }
4104 }
4105 return false;
4106 }
4107
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004108 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004109 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4111 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4112 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004113 enforceReadPrivilegedPermission("getImsProvisioningInt");
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004117 int slotId = getSlotIndex(subId);
4118 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4119 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4120 + subId + "' for key:" + key);
4121 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4122 }
4123 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004125 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4126 + subId + "' for key:" + key);
4127 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
4131 }
4132
4133 @Override
4134 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004135 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4136 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4137 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004138 enforceReadPrivilegedPermission("getImsProvisioningString");
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004142 int slotId = getSlotIndex(subId);
4143 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4144 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4145 + subId + "' for key:" + key);
4146 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4147 }
4148 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004149 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004150 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4151 + subId + "' for key:" + key);
4152 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004160 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4161 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4162 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4164 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004168 int slotId = getSlotIndex(subId);
4169 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4170 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4171 + subId + "' for key:" + key);
4172 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4173 }
4174 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004175 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004176 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4177 + "' for key:" + key);
4178 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
4182 }
4183
4184 @Override
4185 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4187 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4188 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4190 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004194 int slotId = getSlotIndex(subId);
4195 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4196 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4197 + subId + "' for key:" + key);
4198 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4199 }
4200 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004202 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4203 + "' for key:" + key);
4204 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 int slotId = SubscriptionManager.getSlotIndex(subId);
4212 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004213 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4214 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 }
4216 return slotId;
4217 }
4218
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004219 private int getSlotIndex(int subId) {
4220 int slotId = SubscriptionManager.getSlotIndex(subId);
4221 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4222 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4223 }
4224 return slotId;
4225 }
4226
Wink Saville36469e72014-06-11 15:17:00 -07004227 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004228 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004229 */
4230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004231 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4232 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004233 final int targetSdk = getTargetSdk(callingPackage);
4234 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004235 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004236 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004237 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004238 mApp, subId, callingPackage, callingFeatureId,
4239 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004240 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4241 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 final long identity = Binder.clearCallingIdentity();
4244 try {
4245 final Phone phone = getPhone(subId);
4246 if (phone != null) {
4247 return phone.getServiceState().getDataNetworkType();
4248 } else {
4249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4250 }
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004254 }
4255
4256 /**
4257 * Returns the data network type
4258 */
4259 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004260 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4261 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4262 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004263 }
4264
4265 /**
4266 * Returns the data network type for a subId
4267 */
4268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4270 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4275 }
4276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final Phone phone = getPhone(subId);
4280 if (phone != null) {
4281 return phone.getServiceState().getDataNetworkType();
4282 } else {
4283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004288 }
4289
4290 /**
Wink Saville36469e72014-06-11 15:17:00 -07004291 * Returns the Voice network type for a subId
4292 */
4293 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004294 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4295 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004297 mApp, subId, callingPackage, callingFeatureId,
4298 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004299 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4300 }
4301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302 final long identity = Binder.clearCallingIdentity();
4303 try {
4304 final Phone phone = getPhone(subId);
4305 if (phone != null) {
4306 return phone.getServiceState().getVoiceNetworkType();
4307 } else {
4308 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4309 }
4310 } finally {
4311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004313 }
4314
4315 /**
4316 * @return true if a ICC card is present
4317 */
4318 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004319 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004320 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4321 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004322 }
4323
4324 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004325 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004326 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004327 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004328 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 final Phone phone = PhoneFactory.getPhone(slotIndex);
4332 if (phone != null) {
4333 return phone.getIccCard().hasIccCard();
4334 } else {
4335 return false;
4336 }
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004340 }
4341
4342 /**
4343 * Return if the current radio is LTE on CDMA. This
4344 * is a tri-state return value as for a period of time
4345 * the mode may be unknown.
4346 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004347 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004348 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004349 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004350 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004352 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4353 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4354 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004355 }
4356
Sanket Padawe356d7632015-06-22 14:03:32 -07004357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004358 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4359 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004360 try {
4361 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4362 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004363 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4364 }
4365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 final long identity = Binder.clearCallingIdentity();
4367 try {
4368 final Phone phone = getPhone(subId);
4369 if (phone == null) {
4370 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4371 } else {
4372 return phone.getLteOnCdmaMode();
4373 }
4374 } finally {
4375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004376 }
Wink Saville36469e72014-06-11 15:17:00 -07004377 }
4378
Wink Saville36469e72014-06-11 15:17:00 -07004379 /**
4380 * {@hide}
4381 * Returns Default subId, 0 in the case of single standby.
4382 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004383 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004384 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004385 }
4386
Shishir Agrawala9f32182016-04-12 12:00:16 -07004387 private int getSlotForDefaultSubscription() {
4388 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4389 }
4390
Wink Savilleb564aae2014-10-23 10:18:09 -07004391 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004392 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004393 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004394
Pengquan Menge92a50d2018-09-21 15:54:48 -07004395 private boolean isActiveSubscription(int subId) {
4396 return mSubscriptionController.isActiveSubId(subId);
4397 }
4398
Ihab Awadf2177b72013-11-25 13:33:23 -08004399 /**
4400 * @see android.telephony.TelephonyManager.WifiCallingChoices
4401 */
4402 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004405 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4407 getWhenToMakeWifiCallsDefaultPreference());
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004411 }
4412
4413 /**
4414 * @see android.telephony.TelephonyManager.WifiCallingChoices
4415 */
4416 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417 final long identity = Binder.clearCallingIdentity();
4418 try {
4419 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004420 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004425 }
4426
Sailesh Nepald1e68152013-12-12 19:08:02 -08004427 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004428 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004429 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004430 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004431
Jordan Liu4c733742019-02-28 12:03:40 -08004432 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4433 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4434 if (phoneId == -1) {
4435 throw new IllegalArgumentException("Given slot index: " + slotIndex
4436 + " does not correspond to an active phone");
4437 }
4438 return PhoneFactory.getPhone(phoneId);
4439 }
4440
Shishir Agrawal566b7612013-10-28 14:41:00 -07004441 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004442 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4443 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4445 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004447 if (DBG) {
4448 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4449 }
4450 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4451 p2);
4452 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004453
Jordan Liu4c733742019-02-28 12:03:40 -08004454
4455 @Override
4456 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4457 int slotIndex, String callingPackage, String aid, int p2) {
4458 enforceModifyPermission();
4459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4460 if (DBG) {
4461 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4462 }
4463 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4464 callingPackage, aid, p2);
4465 }
4466
4467 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4468 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 if (TextUtils.equals(ISDR_AID, aid)) {
4472 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004473 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4474 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 if (bestComponent == null
4476 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4477 loge("The calling package is not allowed to access ISD-R.");
4478 throw new SecurityException(
4479 "The calling package is not allowed to access ISD-R.");
4480 }
Derek Tan740e1672017-06-27 14:56:27 -07004481 }
Derek Tan740e1672017-06-27 14:56:27 -07004482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004484 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4485 null /* workSource */);
4486 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 return response;
4488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004491 }
4492
4493 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004494 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4496 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004497 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4498 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4499 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004500
Jordan Liu4c733742019-02-28 12:03:40 -08004501 @Override
4502 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4503 enforceModifyPermission();
4504 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4505 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4506 channel);
4507 }
4508
4509 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510 final long identity = Binder.clearCallingIdentity();
4511 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 if (channel < 0) {
4513 return false;
4514 }
Jordan Liu4c733742019-02-28 12:03:40 -08004515 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4516 null /* workSource */);
4517 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 return success;
4519 } finally {
4520 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004521 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004522 }
4523
4524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004525 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004526 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4528 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004529 if (DBG) {
4530 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4531 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4532 + p3 + " data=" + data);
4533 }
4534 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4535 command, p1, p2, p3, data);
4536 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004537
Jordan Liu4c733742019-02-28 12:03:40 -08004538 @Override
4539 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4540 int command, int p1, int p2, int p3, String data) {
4541 enforceModifyPermission();
4542 if (DBG) {
4543 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4544 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4545 + p3 + " data=" + data);
4546 }
4547 return iccTransmitApduLogicalChannelWithPermission(
4548 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4549 data);
4550 }
4551
4552 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4553 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004556 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 return "";
4558 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004561 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4562 null /* workSource */);
4563 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 // Append the returned status code to the end of the response payload.
4566 String s = Integer.toHexString(
4567 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4568 if (response.payload != null) {
4569 s = IccUtils.bytesToHexString(response.payload) + s;
4570 }
4571 return s;
4572 } finally {
4573 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004575 }
Jake Hambye994d462014-02-03 13:10:13 -08004576
Evan Charltonc66da362014-05-16 14:06:40 -07004577 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004578 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4579 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4581 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004583 if (DBG) {
4584 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4585 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4586 }
4587 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4588 cla, command, p1, p2, p3, data);
4589 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004590
Jordan Liu4c733742019-02-28 12:03:40 -08004591 @Override
4592 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4593 int command, int p1, int p2, int p3, String data) {
4594 enforceModifyPermission();
4595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4596 if (DBG) {
4597 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4598 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4599 + " data=" + data);
4600 }
4601
4602 return iccTransmitApduBasicChannelWithPermission(
4603 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4604 p2, p3, data);
4605 }
4606
4607 // open APDU basic channel assuming the caller has sufficient permissions
4608 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4609 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 final long identity = Binder.clearCallingIdentity();
4611 try {
4612 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4613 && TextUtils.equals(ISDR_AID, data)) {
4614 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004615 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4616 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 if (bestComponent == null
4618 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4619 loge("The calling package is not allowed to select ISD-R.");
4620 throw new SecurityException(
4621 "The calling package is not allowed to select ISD-R.");
4622 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004623 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004626 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4627 null /* workSource */);
4628 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 // Append the returned status code to the end of the response payload.
4631 String s = Integer.toHexString(
4632 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4633 if (response.payload != null) {
4634 s = IccUtils.bytesToHexString(response.payload) + s;
4635 }
4636 return s;
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004639 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004640 }
4641
4642 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004643 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004644 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4646 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 if (DBG) {
4651 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4652 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4653 }
4654
4655 IccIoResult response =
4656 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4657 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4658 subId);
4659
4660 if (DBG) {
4661 log("Exchange SIM_IO [R]" + response);
4662 }
4663
4664 byte[] result = null;
4665 int length = 2;
4666 if (response.payload != null) {
4667 length = 2 + response.payload.length;
4668 result = new byte[length];
4669 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4670 } else {
4671 result = new byte[length];
4672 }
4673
4674 result[length - 1] = (byte) response.sw2;
4675 result[length - 2] = (byte) response.sw1;
4676 return result;
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004679 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004680 }
4681
Nathan Haroldb3014052017-01-25 15:57:32 -08004682 /**
4683 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4684 * on a particular subscription
4685 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004686 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4687 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004689 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004690 return null;
4691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692
4693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 if (appType != TelephonyManager.APPTYPE_USIM
4696 && appType != TelephonyManager.APPTYPE_SIM) {
4697 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4698 return null;
4699 }
4700 Object response = sendRequest(
4701 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4702 if (response instanceof String[]) {
4703 return (String[]) response;
4704 }
yincheng zhao2737e882019-09-06 17:06:54 -07004705 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004707 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004710 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004711 }
4712
yincheng zhao2737e882019-09-06 17:06:54 -07004713 /**
4714 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4715 * subscription.
4716 *
4717 * @param subId the id of the subscription.
4718 * @param appType the uicc app type, must be USIM or SIM.
4719 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4720 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004721 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004722 * @return number of fplmns that is successfully written to the SIM.
4723 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004724 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4725 String callingFeatureId) {
4726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4727 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004728 if (DBG) logv("no permissions for setForbiddenplmns");
4729 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4730 }
4731 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4732 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4733 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4734 }
4735 if (fplmns == null) {
4736 throw new IllegalArgumentException("Fplmn List provided is null");
4737 }
4738 for (String fplmn : fplmns) {
4739 if (!CellIdentity.isValidPlmn(fplmn)) {
4740 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4741 }
4742 }
4743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 Object response = sendRequest(
4746 CMD_SET_FORBIDDEN_PLMNS,
4747 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4748 subId);
4749 return (int) response;
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
4753 }
4754
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004755 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004756 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4758 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4763 if (response.payload == null) {
4764 return "";
4765 }
Evan Charltonc66da362014-05-16 14:06:40 -07004766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 // Append the returned status code to the end of the response payload.
4768 String s = Integer.toHexString(
4769 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4770 s = IccUtils.bytesToHexString(response.payload) + s;
4771 return s;
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
4774 }
Evan Charltonc66da362014-05-16 14:06:40 -07004775 }
4776
Jake Hambye994d462014-02-03 13:10:13 -08004777 /**
4778 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4779 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4780 *
4781 * @param itemID the ID of the item to read
4782 * @return the NV item as a String, or null on error.
4783 */
4784 @Override
4785 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4788 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789
4790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004793 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4795 return value;
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
4798 }
Jake Hambye994d462014-02-03 13:10:13 -08004799 }
4800
4801 /**
4802 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4803 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4804 *
4805 * @param itemID the ID of the item to read
4806 * @param itemValue the value to write, as a String
4807 * @return true on success; false on any failure
4808 */
4809 @Override
4810 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4813 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814
4815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4818 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004819 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4821 return success;
4822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
Jake Hambye994d462014-02-03 13:10:13 -08004825 }
4826
4827 /**
4828 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4829 * Used for device configuration by some CDMA operators.
4830 *
4831 * @param preferredRoamingList byte array containing the new PRL
4832 * @return true on success; false on any failure
4833 */
4834 @Override
4835 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4837 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838
4839 final long identity = Binder.clearCallingIdentity();
4840 try {
4841 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4842 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4843 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4844 return success;
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Jake Hambye994d462014-02-03 13:10:13 -08004848 }
4849
4850 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004851 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004852 * Used for device configuration by some CDMA operators.
4853 *
chen xu6dac5ab2018-10-26 17:39:23 -07004854 * @param slotIndex - device slot.
4855 *
Jake Hambye994d462014-02-03 13:10:13 -08004856 * @return true on success; false on any failure
4857 */
4858 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004859 public boolean resetModemConfig(int slotIndex) {
4860 Phone phone = PhoneFactory.getPhone(slotIndex);
4861 if (phone != null) {
4862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4863 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864
chen xu6dac5ab2018-10-26 17:39:23 -07004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4868 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4869 return success;
4870 } finally {
4871 Binder.restoreCallingIdentity(identity);
4872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 }
chen xu6dac5ab2018-10-26 17:39:23 -07004874 return false;
4875 }
4876
4877 /**
4878 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4879 *
4880 * @param slotIndex - device slot.
4881 *
4882 * @return true on success; false on any failure
4883 */
4884 @Override
4885 public boolean rebootModem(int slotIndex) {
4886 Phone phone = PhoneFactory.getPhone(slotIndex);
4887 if (phone != null) {
4888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4889 mApp, phone.getSubId(), "rebootModem");
4890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4894 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4895 return success;
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
4899 }
4900 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004901 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004902
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004903 public String[] getPcscfAddress(String apnType, String callingPackage,
4904 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004905 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4907 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004908 return new String[0];
4909 }
4910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 final long identity = Binder.clearCallingIdentity();
4912 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004913 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
Wink Saville36469e72014-06-11 15:17:00 -07004917 }
4918
Brad Ebinger51f743a2017-01-23 13:50:20 -08004919 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004920 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4921 * {@link #disableIms(int)}.
4922 * @param slotIndex device slot.
4923 */
4924 public void resetIms(int slotIndex) {
4925 enforceModifyPermission();
4926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 if (mImsResolver == null) {
4930 // may happen if the does not support IMS.
4931 return;
4932 }
4933 mImsResolver.disableIms(slotIndex);
4934 mImsResolver.enableIms(slotIndex);
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
4938 }
4939
4940 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004941 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4942 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004943 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004944 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946
4947 final long identity = Binder.clearCallingIdentity();
4948 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004949 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004950 // may happen if the device does not support IMS.
4951 return;
4952 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004953 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004957 }
4958
4959 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4961 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004962 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004963 public void disableIms(int slotId) {
4964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004968 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004969 // may happen if the device does not support IMS.
4970 return;
4971 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004972 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004976 }
4977
4978 /**
4979 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4980 * feature or {@link null} if the service is not available. If the feature is available, the
4981 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4982 */
4983 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004984 IImsServiceFeatureCallback callback) {
4985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986
4987 final long identity = Binder.clearCallingIdentity();
4988 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004989 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004990 // may happen if the device does not support IMS.
4991 return null;
4992 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004993 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004997 }
4998
4999 /**
5000 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5001 * feature during emergency calling or {@link null} if the service is not available. If the
5002 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5003 * listener for feature updates.
5004 */
5005 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007
5008 final long identity = Binder.clearCallingIdentity();
5009 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005010 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005011 // may happen if the device does not support IMS.
5012 return null;
5013 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005014 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 } finally {
5016 Binder.restoreCallingIdentity(identity);
5017 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005018 }
5019
Brad Ebinger5f64b052017-12-14 14:26:15 -08005020 /**
5021 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005022 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005023 */
5024 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026
5027 final long identity = Binder.clearCallingIdentity();
5028 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005029 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005030 // may happen if the device does not support IMS.
5031 return null;
5032 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005033 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005037 }
5038
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005039 /**
5040 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005041 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005042 */
5043 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5044 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005048 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005049 // may happen if the device does not support IMS.
5050 return null;
5051 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005052 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 } finally {
5054 Binder.restoreCallingIdentity(identity);
5055 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005056 }
5057
Brad Ebinger884c07b2018-02-15 16:17:40 -08005058 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005059 * Sets the ImsService Package Name that Telephony will bind to.
5060 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 * @param slotIndex the slot ID that the ImsService should bind for.
5062 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005063 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005064 * @param featureTypes An integer array of feature types associated with a packageName.
5065 * @param packageName The name of the package that the current configuration will be replaced
5066 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005067 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005068 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005069 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5070 int[] featureTypes, String packageName) {
5071 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5072 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5074 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005075 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005079 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005080 // may happen if the device does not support IMS.
5081 return false;
5082 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005083 Map<Integer, String> featureConfig = new HashMap<>();
5084 for (int featureType : featureTypes) {
5085 featureConfig.put(featureType, packageName);
5086 }
5087 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5088 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005092 }
5093
5094 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005095 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005096 *
5097 * @param slotId The slot that the ImsService is associated with.
5098 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5099 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005100 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005101 * @return the package name of the ImsService configuration.
5102 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005103 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5104 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005105 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005106 TelephonyPermissions
5107 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5108 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5109 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005113 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005114 // may happen if the device does not support IMS.
5115 return "";
5116 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005117 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005118 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5119 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005123 }
5124
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005125 /**
5126 * Get the MmTelFeature state associated with the requested subscription id.
5127 * @param subId The subscription that the MmTelFeature is associated with.
5128 * @param callback A callback with an integer containing the
5129 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5130 */
5131 @Override
5132 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5133 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5134 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5135 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5136 "IMS not available on device.");
5137 }
5138 final long token = Binder.clearCallingIdentity();
5139 try {
5140 int slotId = getSlotIndex(subId);
5141 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5142 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5143 + subId + "'");
5144 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5145 }
5146 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5147 try {
5148 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5149 } catch (RemoteException e) {
5150 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5151 + "Ignore");
5152 }
5153 });
5154 } finally {
5155 Binder.restoreCallingIdentity(token);
5156 }
5157 }
5158
Wink Saville36469e72014-06-11 15:17:00 -07005159 public void setImsRegistrationState(boolean registered) {
5160 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161
5162 final long identity = Binder.clearCallingIdentity();
5163 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005164 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
5170 /**
Stuart Scott54788802015-03-30 13:18:01 -07005171 * Set the network selection mode to automatic.
5172 *
5173 */
5174 @Override
5175 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5177 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178
5179 final long identity = Binder.clearCallingIdentity();
5180 try {
shilufc958392020-01-20 11:36:01 -08005181 if (!isActiveSubscription(subId)) {
5182 return;
5183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5185 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Stuart Scott54788802015-03-30 13:18:01 -07005189 }
5190
Pengquan Mengea84e042018-09-20 14:57:26 -07005191 /**
5192 * Ask the radio to connect to the input network and change selection mode to manual.
5193 *
5194 * @param subId the id of the subscription.
5195 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5196 * the operator to attach to.
5197 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5198 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5199 * normal network selection next time.
5200 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005201 */
5202 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005203 public boolean setNetworkSelectionModeManual(
5204 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5206 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005207
5208 if (!isActiveSubscription(subId)) {
5209 return false;
5210 }
5211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 final long identity = Binder.clearCallingIdentity();
5213 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005214 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005216 if (DBG) {
5217 log("setNetworkSelectionModeManual: subId: " + subId
5218 + " operator: " + operatorInfo);
5219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005224 }
shilu84f6e8b2019-12-19 13:58:01 -08005225 /**
5226 * Get the manual network selection
5227 *
5228 * @param subId the id of the subscription.
5229 *
5230 * @return the previously saved user selected PLMN
5231 */
5232 @Override
5233 public String getManualNetworkSelectionPlmn(int subId) {
5234 TelephonyPermissions
5235 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5236 mApp, subId, "getManualNetworkSelectionPlmn");
5237
5238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 if (!isActiveSubscription(subId)) {
5241 return "";
5242 }
5243
5244 final Phone phone = getPhone(subId);
5245 if (phone == null) {
5246 return "";
5247 }
5248 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5249 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5250 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005255
5256 /**
5257 * Scans for available networks.
5258 */
5259 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005260 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5261 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5263 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005264 LocationAccessPolicy.LocationPermissionResult locationResult =
5265 LocationAccessPolicy.checkLocationPermission(mApp,
5266 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5267 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005268 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005269 .setCallingPid(Binder.getCallingPid())
5270 .setCallingUid(Binder.getCallingUid())
5271 .setMethod("getCellNetworkScanResults")
5272 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5273 .build());
5274 switch (locationResult) {
5275 case DENIED_HARD:
5276 throw new SecurityException("Not allowed to access scan results -- location");
5277 case DENIED_SOFT:
5278 return null;
5279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280
Pengquan Menga1bb6272018-09-06 09:59:22 -07005281 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 try {
5283 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005284 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005289 }
5290
5291 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005292 * Get the call forwarding info, given the call forwarding reason.
5293 */
5294 @Override
5295 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5296 enforceReadPrivilegedPermission("getCallForwarding");
5297 long identity = Binder.clearCallingIdentity();
5298 try {
5299 if (DBG) {
5300 log("getCallForwarding: subId " + subId
5301 + " callForwardingReason" + callForwardingReason);
5302 }
5303 return (CallForwardingInfo) sendRequest(
5304 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
5308 }
5309
5310 /**
5311 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5312 * reason, the number to forward, and the timeout before the forwarding is attempted.
5313 */
5314 @Override
5315 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5316 enforceModifyPermission();
5317 long identity = Binder.clearCallingIdentity();
5318 try {
5319 if (DBG) {
5320 log("setCallForwarding: subId " + subId
5321 + " callForwardingInfo" + callForwardingInfo);
5322 }
5323 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
5327 }
5328
5329 /**
5330 * Get the call forwarding info, given the call forwarding reason.
5331 */
5332 @Override
5333 public int getCallWaitingStatus(int subId) {
5334 enforceReadPrivilegedPermission("getCallForwarding");
5335 long identity = Binder.clearCallingIdentity();
5336 try {
5337 if (DBG) log("getCallWaitingStatus: subId " + subId);
5338 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
5345 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5346 * reason, the number to forward, and the timeout before the forwarding is attempted.
5347 */
5348 @Override
5349 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5350 enforceModifyPermission();
5351 long identity = Binder.clearCallingIdentity();
5352 try {
5353 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5354 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
5358 }
5359
5360 /**
yinxub1bed742017-04-17 11:45:04 -07005361 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005362 *
yinxub1bed742017-04-17 11:45:04 -07005363 * @param subId id of the subscription
5364 * @param request contains the radio access networks with bands/channels to scan
5365 * @param messenger callback messenger for scan results or errors
5366 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005367 * @return the id of the requested scan which can be used to stop the scan.
5368 */
5369 @Override
5370 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005371 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5373 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005374 LocationAccessPolicy.LocationPermissionResult locationResult =
5375 LocationAccessPolicy.checkLocationPermission(mApp,
5376 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5377 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005378 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005379 .setCallingPid(Binder.getCallingPid())
5380 .setCallingUid(Binder.getCallingUid())
5381 .setMethod("requestNetworkScan")
5382 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5383 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005384 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005385 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005386 if (e != null) {
5387 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5388 throw e;
5389 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005390 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005391 return TelephonyScanManager.INVALID_SCAN_ID;
5392 }
5393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 }
Hall Liu912dfd32019-04-25 14:02:26 -07005395 int callingUid = Binder.getCallingUid();
5396 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 return mNetworkScanRequestTracker.startNetworkScan(
5400 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005401 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005402 } finally {
5403 Binder.restoreCallingIdentity(identity);
5404 }
yinxu504e1392017-04-12 16:03:22 -07005405 }
5406
Hall Liub2ac8ef2019-02-28 15:56:23 -08005407 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005408 NetworkScanRequest request, int subId) {
5409 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5410 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5411 boolean hasNetworkScanPermission =
5412 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5413 == PERMISSION_GRANTED;
5414
5415 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5416 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5417 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 }
5419
5420 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5421 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005422 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5423 return new SecurityException("Specific channels must not be"
5424 + " scanned without location access.");
5425 }
5426 }
5427 }
5428
Hall Liub2ac8ef2019-02-28 15:56:23 -08005429 return null;
5430 }
5431
yinxu504e1392017-04-12 16:03:22 -07005432 /**
5433 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005434 *
5435 * @param subId id of the subscription
5436 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005437 */
5438 @Override
5439 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5441 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442
Hall Liu912dfd32019-04-25 14:02:26 -07005443 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005446 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
yinxu504e1392017-04-12 16:03:22 -07005450 }
5451
5452 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005453 * Get the calculated preferred network type.
5454 * Used for debugging incorrect network type.
5455 *
5456 * @return the preferred network type, defined in RILConstants.java.
5457 */
5458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005459 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005460 final Phone defaultPhone = getDefaultPhone();
5461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005462 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005463 return RILConstants.PREFERRED_NETWORK_MODE;
5464 }
5465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005469 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
Junda Liu84d15a22014-07-02 11:21:04 -07005473 }
5474
5475 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005476 * Get the preferred network type.
5477 * Used for device configuration by some CDMA operators.
5478 *
5479 * @return the preferred network type, defined in RILConstants.java.
5480 */
5481 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005482 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005483 TelephonyPermissions
5484 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5485 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486
5487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 if (DBG) log("getPreferredNetworkType");
5490 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5491 int networkType = (result != null ? result[0] : -1);
5492 if (DBG) log("getPreferredNetworkType: " + networkType);
5493 return networkType;
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005497 }
5498
5499 /**
5500 * Set the preferred network type.
5501 * Used for device configuration by some CDMA operators.
5502 *
5503 * @param networkType the preferred network type, defined in RILConstants.java.
5504 * @return true on success; false on any failure.
5505 */
5506 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005507 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5509 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005513 Settings.Global.putInt(mApp.getContentResolver(),
5514 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5515 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005518 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005519 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005520
5521 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005522 * Get the allowed network types that store in the telephony provider.
5523 *
5524 * @param subId the id of the subscription.
5525 * @return allowedNetworkTypes the allowed network types.
5526 */
5527 @Override
5528 public long getAllowedNetworkTypes(int subId) {
5529 TelephonyPermissions
5530 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5531 mApp, subId, "getAllowedNetworkTypes");
5532
5533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 return SubscriptionManager.getLongSubscriptionProperty(
5536 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
5540 }
5541
5542 /**
5543 * Set the allowed network types.
5544 *
5545 * @param subId the id of the subscription.
5546 * @param allowedNetworkTypes the allowed network types.
5547 * @return true on success; false on any failure.
5548 */
5549 @Override
5550 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5552 mApp, subId, "setAllowedNetworkTypes");
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 SubscriptionManager.setSubscriptionProperty(subId,
5556 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5557 String.valueOf(allowedNetworkTypes));
5558 return setPreferredNetworkTypesInternal(subId);
5559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
5562 }
5563
5564 private boolean setPreferredNetworkTypesInternal(int subId) {
5565 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5566 Settings.Global.getInt(mApp.getContentResolver(),
5567 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5568 RILConstants.PREFERRED_NETWORK_MODE));
5569 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5570 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5571 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5572 (int) (networkTypeBitMask & allowedNetworkTypes));
5573
5574 if (DBG) {
5575 log("setPreferredNetworkTypesInternal: subId " + subId
5576 + " networkTypes " + networkTypeBitMask
5577 + " allowedNetworkTypes " + allowedNetworkTypes
5578 + " networkMode " + networkMode);
5579 }
5580
5581 Boolean success = (Boolean) sendRequest(
5582 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5583 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5584 return success;
5585 }
5586
5587 /**
Miaoa84611c2019-03-15 09:21:10 +08005588 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005589 *
Miaoa84611c2019-03-15 09:21:10 +08005590 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005591 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005592 * @hide
5593 */
5594 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005595 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005598 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 try {
Miaoa84611c2019-03-15 09:21:10 +08005600 if (phone != null) {
5601 return phone.hasMatchedTetherApnSetting();
5602 } else {
5603 return false;
5604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005607 }
Junda Liu475951f2014-11-07 16:45:03 -08005608 }
5609
5610 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005611 * Set mobile data enabled
5612 * Used by the user through settings etc to turn on/off mobile data
5613 *
5614 * @param enable {@code true} turn turn data on, else {@code false}
5615 */
5616 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005617 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5619 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620
5621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 int phoneId = mSubscriptionController.getPhoneId(subId);
5624 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5625 Phone phone = PhoneFactory.getPhone(phoneId);
5626 if (phone != null) {
5627 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005628 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005630 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631 }
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005634 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005635 }
5636
5637 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005638 * Enable or disable always reporting signal strength changes from radio.
5639 *
5640 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5641 */
5642 @Override
5643 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5644 enforceModifyPermission();
5645 enforceSystemCaller();
5646
5647 final long identity = Binder.clearCallingIdentity();
5648 final Phone phone = getPhone(subId);
5649 try {
5650 if (phone != null) {
5651 if (DBG) {
5652 log("setAlwaysReportSignalStrength: subId=" + subId
5653 + " isEnable=" + isEnable);
5654 }
5655 phone.setAlwaysReportSignalStrength(isEnable);
5656 } else {
5657 loge("setAlwaysReportSignalStrength: no phone found for subId="
5658 + subId);
5659 }
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
5664
5665 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005666 * Get the user enabled state of Mobile Data.
5667 *
5668 * TODO: remove and use isUserDataEnabled.
5669 * This can't be removed now because some vendor codes
5670 * calls through ITelephony directly while they should
5671 * use TelephonyManager.
5672 *
5673 * @return true on enabled
5674 */
5675 @Override
5676 public boolean getDataEnabled(int subId) {
5677 return isUserDataEnabled(subId);
5678 }
5679
5680 /**
5681 * Get whether mobile data is enabled per user setting.
5682 *
5683 * There are other factors deciding whether mobile data is actually enabled, but they are
5684 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005685 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005686 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005687 *
5688 * @return {@code true} if data is enabled else {@code false}
5689 */
5690 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005691 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005692 try {
5693 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5694 null);
5695 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5697 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699
5700 final long identity = Binder.clearCallingIdentity();
5701 try {
5702 int phoneId = mSubscriptionController.getPhoneId(subId);
5703 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5704 Phone phone = PhoneFactory.getPhone(phoneId);
5705 if (phone != null) {
5706 boolean retVal = phone.isUserDataEnabled();
5707 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5708 return retVal;
5709 } else {
5710 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5711 return false;
5712 }
5713 } finally {
5714 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005715 }
5716 }
5717
5718 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005719 * Checks if the device is capable of mobile data by considering whether whether the
5720 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5721 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005722 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005723 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005724 */
5725 @Override
5726 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005727 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 int phoneId = mSubscriptionController.getPhoneId(subId);
5732 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5733 Phone phone = PhoneFactory.getPhone(phoneId);
5734 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005735 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5737 return retVal;
5738 } else {
5739 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5740 return false;
5741 }
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005744 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005745 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005746
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005747 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5748 Phone phone) {
5749 //load access rules from carrier configs, and check those as well: b/139133814
5750 SubscriptionController subController = SubscriptionController.getInstance();
5751 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5752 || subController == null) return privilegeFromSim;
5753
5754 int uid = Binder.getCallingUid();
5755 PackageManager pkgMgr = phone.getContext().getPackageManager();
5756 String[] packages = pkgMgr.getPackagesForUid(uid);
5757
5758 final long identity = Binder.clearCallingIdentity();
5759 try {
5760 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5761 SubscriptionManager subManager = (SubscriptionManager)
5762 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5763 for (String pkg : packages) {
5764 if (subManager.canManageSubscription(subInfo, pkg)) {
5765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5766 }
5767 }
5768 return privilegeFromSim;
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773
5774 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5775 String pkgName) {
5776 //load access rules from carrier configs, and check those as well: b/139133814
5777 SubscriptionController subController = SubscriptionController.getInstance();
5778 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5779 || subController == null) return privilegeFromSim;
5780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5784 SubscriptionManager subManager = (SubscriptionManager)
5785 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5786 return subManager.canManageSubscription(subInfo, pkgName)
5787 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
5791 }
5792
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005793 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005794 public int getCarrierPrivilegeStatus(int subId) {
5795 final Phone phone = getPhone(subId);
5796 if (phone == null) {
5797 loge("getCarrierPrivilegeStatus: Invalid subId");
5798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5799 }
5800 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005801 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005802 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005803 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5804 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005805
5806 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5807 card.getCarrierPrivilegeStatusForCurrentTransaction(
5808 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005809 }
Junda Liu29340342014-07-10 15:23:27 -07005810
5811 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005812 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005813 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005814 final Phone phone = getPhone(subId);
5815 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005816 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5818 }
5819 UiccProfile profile =
5820 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5821 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005822 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005823 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5824 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005825 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005826 profile.getCarrierPrivilegeStatusForUid(
5827 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005828 }
5829
5830 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005831 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5832 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005833 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005834 }
5835
5836 int phoneId = SubscriptionManager.getPhoneId(subId);
5837 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005838 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005839 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005840 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5841 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005842 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5843 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5844 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005845 }
5846
5847 @Override
5848 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005849 if (TextUtils.isEmpty(pkgName))
5850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005851 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5852 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5853 UiccCard card = UiccController.getInstance().getUiccCard(i);
5854 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005855 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005856 continue;
5857 }
5858
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005859 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5860 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5861 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005862 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5863 break;
5864 }
5865 }
5866
5867 return result;
Junda Liu29340342014-07-10 15:23:27 -07005868 }
Derek Tan89e89d42014-07-08 17:00:10 -07005869
5870 @Override
Junda Liue64de782015-04-16 17:19:16 -07005871 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5872 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5873 loge("phoneId " + phoneId + " is not valid.");
5874 return null;
5875 }
5876 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005877 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005878 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005879 return null ;
5880 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005881 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005882 }
5883
Amith Yamasani6e118872016-02-19 12:53:51 -08005884 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005885 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005886 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005887 List<String> privilegedPackages = new ArrayList<>();
5888 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005889 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5890 // has UICC in that slot.
5891 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005892 if (card.hasCarrierPrivilegeRules()) {
5893 if (packages == null) {
5894 // Only check packages in user 0 for now
5895 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005896 PackageManager.MATCH_DISABLED_COMPONENTS
5897 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005898 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005899 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005900 }
5901 for (int p = packages.size() - 1; p >= 0; p--) {
5902 PackageInfo pkgInfo = packages.get(p);
5903 if (pkgInfo != null && pkgInfo.packageName != null
5904 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005905 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005906 privilegedPackages.add(pkgInfo.packageName);
5907 }
5908 }
5909 }
5910 }
5911 return privilegedPackages;
5912 }
5913
chen xuf7e9fe82019-05-09 19:31:02 -07005914 @Override
5915 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005916 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5917
5918 final long identity = Binder.clearCallingIdentity();
5919
chen xuf7e9fe82019-05-09 19:31:02 -07005920 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005921 try {
5922 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5923 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5924 }
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005927 }
5928 return privilegedPackages;
5929 }
5930
Wink Savilleb564aae2014-10-23 10:18:09 -07005931 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005932 final Phone phone = getPhone(subId);
5933 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005934 if (card == null) {
5935 loge("getIccId: No UICC");
5936 return null;
5937 }
5938 String iccId = card.getIccId();
5939 if (TextUtils.isEmpty(iccId)) {
5940 loge("getIccId: ICC ID is null or empty.");
5941 return null;
5942 }
5943 return iccId;
5944 }
5945
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005946 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005947 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5948 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005949 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005950 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 final String iccId = getIccId(subId);
5955 final Phone phone = getPhone(subId);
5956 if (phone == null) {
5957 return false;
5958 }
5959 final String subscriberId = phone.getSubscriberId();
5960
5961 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005962 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 + subscriberId + " to " + number);
5964 }
5965
5966 if (TextUtils.isEmpty(iccId)) {
5967 return false;
5968 }
5969
5970 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5971
5972 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5973 if (alphaTag == null) {
5974 editor.remove(alphaTagPrefKey);
5975 } else {
5976 editor.putString(alphaTagPrefKey, alphaTag);
5977 }
5978
5979 // Record both the line number and IMSI for this ICCID, since we need to
5980 // track all merged IMSIs based on line number
5981 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5982 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5983 if (number == null) {
5984 editor.remove(numberPrefKey);
5985 editor.remove(subscriberPrefKey);
5986 } else {
5987 editor.putString(numberPrefKey, number);
5988 editor.putString(subscriberPrefKey, subscriberId);
5989 }
5990
5991 editor.commit();
5992 return true;
5993 } finally {
5994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005995 }
Derek Tan7226c842014-07-02 17:42:23 -07005996 }
5997
5998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005999 public String getLine1NumberForDisplay(int subId, String callingPackage,
6000 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006001 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006003 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006004 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006005 return null;
6006 }
Derek Tan97ebb422014-09-05 16:55:38 -07006007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 String iccId = getIccId(subId);
6011 if (iccId != null) {
6012 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6013 if (DBG_MERGE) {
6014 log("getLine1NumberForDisplay returning "
6015 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6016 }
6017 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6020 return null;
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006023 }
Derek Tan7226c842014-07-02 17:42:23 -07006024 }
6025
6026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006027 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6028 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006030 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006031 return null;
6032 }
Derek Tan97ebb422014-09-05 16:55:38 -07006033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 String iccId = getIccId(subId);
6037 if (iccId != null) {
6038 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6039 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6040 }
6041 return null;
6042 } finally {
6043 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006044 }
Derek Tan7226c842014-07-02 17:42:23 -07006045 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006046
6047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006048 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6049 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006050 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6051 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006053 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006054 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006055 return null;
6056 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006057
Jordan Liub49b04b2019-05-06 14:45:15 -07006058 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6059 // the process, where TelephonyManager was instantiated.
6060 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006061 final long identity = Binder.clearCallingIdentity();
6062 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006063 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 final TelephonyManager tele = TelephonyManager.from(context);
6065 final SubscriptionManager sub = SubscriptionManager.from(context);
6066
6067 // Figure out what subscribers are currently active
6068 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069
Jordan Liub49b04b2019-05-06 14:45:15 -07006070 // Only consider subs which match the current subId
6071 // This logic can be simplified. See b/131189269 for progress.
6072 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006073 activeSubscriberIds.add(tele.getSubscriberId(subId));
6074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075
6076 // First pass, find a number override for an active subscriber
6077 String mergeNumber = null;
6078 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6079 for (String key : prefs.keySet()) {
6080 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6081 final String subscriberId = (String) prefs.get(key);
6082 if (activeSubscriberIds.contains(subscriberId)) {
6083 final String iccId = key.substring(
6084 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6085 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6086 mergeNumber = (String) prefs.get(numberKey);
6087 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006088 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 + " for active subscriber " + subscriberId);
6090 }
6091 if (!TextUtils.isEmpty(mergeNumber)) {
6092 break;
6093 }
6094 }
6095 }
6096 }
6097
6098 // Shortcut when no active merged subscribers
6099 if (TextUtils.isEmpty(mergeNumber)) {
6100 return null;
6101 }
6102
6103 // Second pass, find all subscribers under that line override
6104 final ArraySet<String> result = new ArraySet<>();
6105 for (String key : prefs.keySet()) {
6106 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6107 final String number = (String) prefs.get(key);
6108 if (mergeNumber.equals(number)) {
6109 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6110 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6111 final String subscriberId = (String) prefs.get(subscriberKey);
6112 if (!TextUtils.isEmpty(subscriberId)) {
6113 result.add(subscriberId);
6114 }
6115 }
6116 }
6117 }
6118
6119 final String[] resultArray = result.toArray(new String[result.size()]);
6120 Arrays.sort(resultArray);
6121 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006122 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6124 }
6125 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006126 } finally {
6127 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006128 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006129 }
6130
6131 @Override
zoey chen38003472019-12-13 17:16:31 +08006132 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6133 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006134
6135 final long identity = Binder.clearCallingIdentity();
6136 try {
6137 final TelephonyManager telephonyManager = mApp.getSystemService(
6138 TelephonyManager.class);
6139 String subscriberId = telephonyManager.getSubscriberId(subId);
6140 if (subscriberId == null) {
6141 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006142 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006143 + subId);
6144 }
6145 return null;
6146 }
6147
6148 final SubscriptionInfo info = SubscriptionController.getInstance()
6149 .getSubscriptionInfo(subId);
6150 final ParcelUuid groupUuid = info.getGroupUuid();
6151 // If it doesn't belong to any group, return just subscriberId of itself.
6152 if (groupUuid == null) {
6153 return new String[]{subscriberId};
6154 }
6155
6156 // Get all subscriberIds from the group.
6157 final List<String> mergedSubscriberIds = new ArrayList<>();
6158 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006159 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6160 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006161 for (SubscriptionInfo subInfo : groupInfos) {
6162 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6163 if (subscriberId != null) {
6164 mergedSubscriberIds.add(subscriberId);
6165 }
6166 }
6167
6168 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171
6172 }
6173 }
6174
6175 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006176 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006178 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 final Phone phone = getPhone(subId);
6183 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
6186 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006187 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006188
6189 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006190 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006191 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6192 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006193 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6194 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195
6196 final long identity = Binder.clearCallingIdentity();
6197 try {
6198 final Phone phone = getPhone(subId);
6199 if (phone == null) {
6200 return false;
6201 }
6202 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6203 cdmaNonRoamingList);
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006206 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006207 }
6208
6209 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006210 @Deprecated
6211 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6212 enforceModifyPermission();
6213
6214 int returnValue = 0;
6215 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006216 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006217 if(result.exception == null) {
6218 if (result.result != null) {
6219 byte[] responseData = (byte[])(result.result);
6220 if(responseData.length > oemResp.length) {
6221 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6222 responseData.length + "bytes. Buffer Size is " +
6223 oemResp.length + "bytes.");
6224 }
6225 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6226 returnValue = responseData.length;
6227 }
6228 } else {
6229 CommandException ex = (CommandException) result.exception;
6230 returnValue = ex.getCommandError().ordinal();
6231 if(returnValue > 0) returnValue *= -1;
6232 }
6233 } catch (RuntimeException e) {
6234 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6235 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6236 if(returnValue > 0) returnValue *= -1;
6237 }
6238
6239 return returnValue;
6240 }
6241
6242 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006243 public void setRadioCapability(RadioAccessFamily[] rafs) {
6244 try {
6245 ProxyController.getInstance().setRadioCapability(rafs);
6246 } catch (RuntimeException e) {
6247 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6248 }
6249 }
6250
6251 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006252 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006253 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006254 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006255 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006256 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 final long identity = Binder.clearCallingIdentity();
6259 try {
chen xub97461a2018-10-26 14:17:57 -07006260 TelephonyPermissions
6261 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6262 mApp, phone.getSubId(), "getRadioAccessFamily");
6263 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 } finally {
6265 Binder.restoreCallingIdentity(identity);
6266 }
chen xub97461a2018-10-26 14:17:57 -07006267 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006268 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006269
6270 @Override
6271 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006272 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006277 ImsManager.getInstance(defaultPhone.getContext(),
6278 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006282 }
6283
6284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006285 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006286 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6288 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006289 return false;
6290 }
Svet Ganovb320e182015-04-16 12:30:10 -07006291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 final long identity = Binder.clearCallingIdentity();
6293 try {
6294 // Check the user preference and the system-level IMS setting. Even if the user has
6295 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6296 // In the long run, we may instead need to check if there exists a connection service
6297 // which can support video calling.
6298 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006299 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 return imsManager.isVtEnabledByPlatform()
6301 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6302 && imsManager.isVtEnabledByUser();
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006306 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006307
Andrew Leea1239f22015-03-02 17:44:07 -08006308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006309 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6310 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006312 mApp, subId, callingPackage, callingFeatureId,
6313 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 return false;
6315 }
6316
6317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 CarrierConfigManager configManager =
6320 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006321 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
Andrew Leea1239f22015-03-02 17:44:07 -08006326 }
6327
6328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006329 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006331 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 return false;
6333 }
6334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 CarrierConfigManager configManager =
6338 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006339 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
Andrew Leea1239f22015-03-02 17:44:07 -08006344 }
6345
Andrew Lee9431b832015-03-09 18:46:45 -07006346 @Override
6347 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006348 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006349 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006350 }
6351
6352 @Override
6353 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 final long identity = Binder.clearCallingIdentity();
6355 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006356 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
Andrew Lee9431b832015-03-09 18:46:45 -07006360 }
6361
Hall Liuf6668912018-10-31 17:05:23 -07006362 /**
6363 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6364 * support for the feature and device firmware support.
6365 *
6366 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6367 */
6368 @Override
6369 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006371 final Phone phone = getPhone(subscriptionId);
6372 if (phone == null) {
6373 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6374 return false;
6375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006377 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6379 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006380 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 return isCarrierSupported && isDeviceSupported;
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Hall Liu98187582018-01-22 19:15:32 -08006385 }
6386
Hall Liuf6668912018-10-31 17:05:23 -07006387 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006388 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6389 * RTT setting, will return true if the device and carrier both support RTT.
6390 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006391 */
6392 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 final long identity = Binder.clearCallingIdentity();
6394 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006395 boolean isRttSupported = isRttSupported(subscriptionId);
6396 boolean isUserRttSettingOn = Settings.Secure.getInt(
6397 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6398 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6399 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6400 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006404 }
6405
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006406 @Deprecated
6407 @Override
6408 public String getDeviceId(String callingPackage) {
6409 return getDeviceIdWithFeature(callingPackage, null);
6410 }
6411
Sanket Padawe7310cc72015-01-14 09:53:20 -08006412 /**
6413 * Returns the unique device ID of phone, for example, the IMEI for
6414 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6415 *
6416 * <p>Requires Permission:
6417 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6418 */
6419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006420 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006421 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006422 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006423 return null;
6424 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006425 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006426 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006427 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006428 return null;
6429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430
6431 final long identity = Binder.clearCallingIdentity();
6432 try {
6433 return phone.getDeviceId();
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006437 }
6438
Ping Sunc67b7c22016-03-02 19:16:45 +08006439 /**
6440 * {@hide}
6441 * Returns the IMS Registration Status on a particular subid
6442 *
6443 * @param subId
6444 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006445 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006446 Phone phone = getPhone(subId);
6447 if (phone != null) {
6448 return phone.isImsRegistered();
6449 } else {
6450 return false;
6451 }
6452 }
6453
Santos Cordon7a1885b2015-02-03 11:15:19 -08006454 @Override
6455 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 final long identity = Binder.clearCallingIdentity();
6457 try {
6458 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006462 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006463
Tyler Gunnf70ed162019-04-03 15:28:53 -07006464 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006465 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006466 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006468 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006469 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6470 }
6471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
6477 }
6478
6479 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006480 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 Phone phone = getPhone(subscriptionId);
6484 if (phone == null) {
6485 return null;
6486 }
6487 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
6492
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006493 /**
6494 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006495 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006496 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 Phone phone = getPhone(subId);
6500 if (phone != null) {
6501 return phone.isWifiCallingEnabled();
6502 } else {
6503 return false;
6504 }
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006507 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006508 }
6509
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006510 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006511 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006512 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006513 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 Phone phone = getPhone(subId);
6517 if (phone != null) {
6518 return phone.isVideoEnabled();
6519 } else {
6520 return false;
6521 }
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006524 }
6525 }
6526
6527 /**
6528 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6529 * defined in {@link ImsRegistrationImplBase}.
6530 */
6531 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 Phone phone = getPhone(subId);
6535 if (phone != null) {
6536 return phone.getImsRegistrationTech();
6537 } else {
6538 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6539 }
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006542 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006543 }
6544
Stuart Scott8eef64f2015-04-08 15:13:54 -07006545 @Override
6546 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006547 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006548 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6549 return;
6550 }
6551
Svet Ganovcc087f82015-05-12 20:35:54 -07006552 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006553
Svet Ganovcc087f82015-05-12 20:35:54 -07006554 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006555 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6556 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006557 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006558 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006559 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006560 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6561 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006562 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006563 // There has been issues when Sms raw table somehow stores orphan
6564 // fragments. They lead to garbled message when new fragments come
6565 // in and combined with those stale ones. In case this happens again,
6566 // user can reset all network settings which will clean up this table.
6567 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006568 // Clean up IMS settings as well here.
6569 int slotId = getSlotIndex(subId);
6570 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6571 ImsManager.getInstance(mApp, slotId).factoryReset();
6572 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006573
6574 // Erase modem config if erase modem on network setting is enabled.
6575 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6576 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6577 if (configValue != null && Boolean.parseBoolean(configValue)) {
6578 sendEraseModemConfig(getDefaultPhone());
6579 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006582 }
6583 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006584
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006585 private void cleanUpSmsRawTable(Context context) {
6586 ContentResolver resolver = context.getContentResolver();
6587 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6588 resolver.delete(uri, null, null);
6589 }
6590
Narayan Kamath1c496c22015-04-16 14:40:19 +01006591 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006592 public String getSimLocaleForSubscriber(int subId) {
6593 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6594 final Phone phone = getPhone(subId);
6595 if (phone == null) {
6596 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006597 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 final long identity = Binder.clearCallingIdentity();
6600 try {
chen xu5d3637b2019-01-21 23:31:38 -08006601 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006602 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006603 if (info == null) {
6604 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6605 return null;
6606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 // Try and fetch the locale from the carrier properties or from the SIM language
6608 // preferences (EF-PL and EF-LI)...
6609 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006611 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6612 if (localeFromDefaultSim != null) {
6613 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6614 if (DBG) log("Using locale from subId: " + subId + " locale: "
6615 + localeFromDefaultSim);
6616 return localeFromDefaultSim.toLanguageTag();
6617 } else {
6618 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 }
6620 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 // The SIM language preferences only store a language (e.g. fr = French), not an
6623 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6624 // the SIM and carrier preferences does not include a country we add the country
6625 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006626 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006628 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 return mccLocale.toLanguageTag();
6630 }
6631
6632 if (DBG) log("No locale found - returning null");
6633 return null;
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
6636 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006637 }
6638
6639 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006640 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6641 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006642 }
6643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644 /**
6645 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6646 */
6647 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006648 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6649 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006650 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006651
Chenjie Yu1ba97252018-01-11 18:16:20 -08006652 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006653 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006654
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006655 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006656 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6657 * representing the state of the modem.
6658 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006659 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6660 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006661 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006662 */
6663 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006664 public void requestModemActivityInfo(ResultReceiver result) {
6665 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006666 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667
6668 final long identity = Binder.clearCallingIdentity();
6669 try {
6670 ModemActivityInfo ret = null;
6671 synchronized (mLastModemActivityInfo) {
6672 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6673 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006674 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006675 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006677 int[] txTimeMs = info.getTransmitTimeMillis();
6678 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006680 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 }
6682 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006683 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6684 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 mLastModemActivityInfo.setIdleTimeMillis(
6686 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006687 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6688 mLastModemActivityInfo.setReceiveTimeMillis(
6689 info.getReceiveTimeMillis() + mLastModemActivityInfo
6690 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006691 }
Chen Xud78231e2019-09-10 18:49:52 -07006692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6694 mLastModemActivityInfo.getSleepTimeMillis(),
6695 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006696 mLastModemActivityInfo.getTransmitTimeMillis(),
6697 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 Bundle bundle = new Bundle();
6700 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6701 result.send(0, bundle);
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006704 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006705 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006706
Siddharth Rayb8114062018-06-17 15:02:38 -07006707 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6708 // less than total activity duration.
6709 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6710 if (info == null) {
6711 return false;
6712 }
6713 int activityDurationMs =
6714 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6715 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006716 int[] txTimeMs = info.getTransmitTimeMillis();
6717 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6718 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006719 }
6720 return (info.isValid()
6721 && (info.getSleepTimeMillis() <= activityDurationMs)
6722 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006723 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006724 && (totalTxTimeMs <= activityDurationMs));
6725 }
6726
Jack Yu85bd38a2015-11-09 11:34:32 -08006727 /**
6728 * {@hide}
6729 * Returns the service state information on specified subscription.
6730 */
6731 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006732 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006735 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006736 return null;
6737 }
6738
Hall Liuf19c44f2018-11-27 14:38:17 -08006739 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6740 LocationAccessPolicy.checkLocationPermission(mApp,
6741 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6742 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006743 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006744 .setCallingPid(Binder.getCallingPid())
6745 .setCallingUid(Binder.getCallingUid())
6746 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006747 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006748 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6749 .build());
6750
6751 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6752 LocationAccessPolicy.checkLocationPermission(mApp,
6753 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6754 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006755 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006756 .setCallingPid(Binder.getCallingPid())
6757 .setCallingUid(Binder.getCallingUid())
6758 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006759 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006760 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6761 .build());
6762 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6763 boolean hasFinePermission =
6764 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6765 boolean hasCoarsePermission =
6766 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 final Phone phone = getPhone(subId);
6771 if (phone == null) {
6772 return null;
6773 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006774
Hall Liuf19c44f2018-11-27 14:38:17 -08006775 ServiceState ss = phone.getServiceState();
6776
6777 // Scrub out the location info in ServiceState depending on what level of access
6778 // the caller has.
6779 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006780 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6781 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 } finally {
6783 Binder.restoreCallingIdentity(identity);
6784 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006785 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006786
6787 /**
6788 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6789 *
6790 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6791 * voicemail ringtone.
6792 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6793 * PhoneAccount.
6794 */
6795 @Override
6796 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
6798 try {
6799 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6800 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006801 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006808 }
6809
6810 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006811 * Sets the per-account voicemail ringtone.
6812 *
6813 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6814 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6815 *
6816 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6817 * voicemail ringtone.
6818 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6819 * PhoneAccount.
6820 */
6821 @Override
6822 public void setVoicemailRingtoneUri(String callingPackage,
6823 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006824 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006825 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006826 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6827 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6829 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6830 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832
6833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6836 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006837 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 }
6839 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006842 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006843 }
6844
6845 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006846 * Returns whether vibration is set for voicemail notification in Phone settings.
6847 *
6848 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6849 * voicemail vibration setting.
6850 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6851 */
6852 @Override
6853 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6857 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006865 }
6866
Youhan Wange64578a2016-05-02 15:32:42 -07006867 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006868 * Sets the per-account voicemail vibration.
6869 *
6870 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6871 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6872 *
6873 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6874 * voicemail vibration setting.
6875 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6876 * specific PhoneAccount.
6877 */
6878 @Override
6879 public void setVoicemailVibrationEnabled(String callingPackage,
6880 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006881 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006882 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006883 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6884 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6886 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6887 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006888 }
6889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6893 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006894 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 }
6896 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6897 } finally {
6898 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006899 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006900 }
6901
6902 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006903 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6904 *
6905 * @throws SecurityException if the caller does not have the required permission
6906 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006907 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006908 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006909 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006910 }
6911
6912 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006913 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6914 * permission.
6915 *
6916 * @throws SecurityException if the caller does not have the required permission
6917 */
6918 private void enforceSendSmsPermission() {
6919 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6920 }
6921
6922 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006923 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006924 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006925 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006926 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006927 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006931 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 if (componentName == null) {
6933 throw new SecurityException(
6934 "Caller not current active visual voicemail package[null]");
6935 }
6936 String vvmPackage = componentName.getPackageName();
6937 if (!callingPackage.equals(vvmPackage)) {
6938 throw new SecurityException("Caller not current active visual voicemail package["
6939 + vvmPackage + "]");
6940 }
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006943 }
6944 }
6945
6946 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006947 * Return the application ID for the app type.
6948 *
6949 * @param subId the subscription ID that this request applies to.
6950 * @param appType the uicc app type.
6951 * @return Application ID for specificied app type, or null if no uicc.
6952 */
6953 @Override
6954 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006955 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006956 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957
6958 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006959 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 if (phone == null) {
6961 return null;
6962 }
6963 String aid = null;
6964 try {
6965 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6966 .getApplicationByType(appType).getAid();
6967 } catch (Exception e) {
6968 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6969 }
6970 return aid;
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006973 }
Youhan Wange64578a2016-05-02 15:32:42 -07006974 }
6975
Youhan Wang4001d252016-05-11 10:29:41 -07006976 /**
6977 * Return the Electronic Serial Number.
6978 *
6979 * @param subId the subscription ID that this request applies to.
6980 * @return ESN or null if error.
6981 */
6982 @Override
6983 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006984 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006985 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986
6987 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006988 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989 if (phone == null) {
6990 return null;
6991 }
6992 String esn = null;
6993 try {
6994 esn = phone.getEsn();
6995 } catch (Exception e) {
6996 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6997 }
6998 return esn;
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007001 }
Youhan Wang4001d252016-05-11 10:29:41 -07007002 }
7003
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007004 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007005 * Return the Preferred Roaming List Version.
7006 *
7007 * @param subId the subscription ID that this request applies to.
7008 * @return PRLVersion or null if error.
7009 */
7010 @Override
7011 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007012 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007013 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007016 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 if (phone == null) {
7018 return null;
7019 }
7020 String cdmaPrlVersion = null;
7021 try {
7022 cdmaPrlVersion = phone.getCdmaPrlVersion();
7023 } catch (Exception e) {
7024 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7025 }
7026 return cdmaPrlVersion;
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007029 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007030 }
7031
7032 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007033 * Get snapshot of Telephony histograms
7034 * @return List of Telephony histograms
7035 * @hide
7036 */
7037 @Override
7038 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7040 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 return RIL.getTelephonyRILTimingHistograms();
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007048 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007049
7050 /**
7051 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007052 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7053 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007054 * Require system privileges. In the future we may add this to carrier APIs.
7055 *
Michele Berionne482f8202018-11-27 18:57:59 -08007056 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007057 */
7058 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007059 @TelephonyManager.SetCarrierRestrictionResult
7060 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007061 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007062 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007063
Michele Berionne482f8202018-11-27 18:57:59 -08007064 if (carrierRestrictionRules == null) {
7065 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007066 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 final long identity = Binder.clearCallingIdentity();
7069 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007070 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007071 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007075 }
7076
7077 /**
7078 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007079 * Get the allowed carrier list and the excluded carrier list, including the priority between
7080 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007081 * Require system privileges. In the future we may add this to carrier APIs.
7082 *
Michele Berionne482f8202018-11-27 18:57:59 -08007083 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007084 */
7085 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007086 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007087 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007088 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089
7090 final long identity = Binder.clearCallingIdentity();
7091 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007092 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7093 if (response instanceof CarrierRestrictionRules) {
7094 return (CarrierRestrictionRules) response;
7095 }
7096 // Response is an Exception of some kind,
7097 // which is signalled to the user as a NULL retval
7098 return null;
7099 } catch (Exception e) {
7100 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7101 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007105 }
7106
fionaxu59545b42016-05-25 15:53:37 -07007107 /**
7108 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7109 * @param subId the subscription ID that this action applies to.
7110 * @param enabled control enable or disable metered apns.
7111 * {@hide}
7112 */
7113 @Override
7114 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7115 enforceModifyPermission();
7116 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117
7118 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007119 if (phone == null) {
7120 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7121 return;
7122 }
7123 try {
7124 phone.carrierActionSetMeteredApnsEnabled(enabled);
7125 } catch (Exception e) {
7126 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007129 }
7130 }
7131
7132 /**
7133 * Action set from carrier signalling broadcast receivers to enable/disable radio
7134 * @param subId the subscription ID that this action applies to.
7135 * @param enabled control enable or disable radio.
7136 * {@hide}
7137 */
7138 @Override
7139 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7140 enforceModifyPermission();
7141 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142
7143 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007144 if (phone == null) {
7145 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7146 return;
7147 }
7148 try {
7149 phone.carrierActionSetRadioEnabled(enabled);
7150 } catch (Exception e) {
7151 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152 } finally {
7153 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007154 }
7155 }
7156
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007157 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007158 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7159 * network status based on which carrier apps could apply actions accordingly,
7160 * enable/disable default url handler for example.
7161 *
7162 * @param subId the subscription ID that this action applies to.
7163 * @param report control start/stop reporting the default network status.
7164 * {@hide}
7165 */
7166 @Override
7167 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7168 enforceModifyPermission();
7169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170
7171 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007172 if (phone == null) {
7173 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7174 return;
7175 }
7176 try {
7177 phone.carrierActionReportDefaultNetworkStatus(report);
7178 } catch (Exception e) {
7179 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 } finally {
7181 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007182 }
7183 }
7184
7185 /**
fionaxud9622282017-07-17 17:51:30 -07007186 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7187 * @param subId the subscription ID that this action applies to.
7188 * {@hide}
7189 */
7190 @Override
7191 public void carrierActionResetAll(int subId) {
7192 enforceModifyPermission();
7193 final Phone phone = getPhone(subId);
7194 if (phone == null) {
7195 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7196 return;
7197 }
7198 try {
7199 phone.carrierActionResetAll();
7200 } catch (Exception e) {
7201 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7202 }
7203 }
7204
7205 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007206 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7207 * bug report is being generated.
7208 */
7209 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007210 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007211 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7212 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007213 writer.println("Permission Denial: can't dump Phone from pid="
7214 + Binder.getCallingPid()
7215 + ", uid=" + Binder.getCallingUid()
7216 + "without permission "
7217 + android.Manifest.permission.DUMP);
7218 return;
7219 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007220 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007221 }
Jack Yueb89b242016-06-22 13:27:47 -07007222
Brad Ebingerdac2f002018-04-03 15:17:52 -07007223 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007224 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7225 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7226 @NonNull String[] args) {
7227 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7228 this, in.getFileDescriptor(), out.getFileDescriptor(),
7229 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007230 }
7231
Jack Yueb89b242016-06-22 13:27:47 -07007232 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007233 * Get aggregated video call data usage since boot.
7234 *
7235 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7236 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007237 * {@hide}
7238 */
7239 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007240 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007241 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7242 null);
7243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 // NetworkStatsService keeps tracking the active network interface and identity. It
7247 // records the delta with the corresponding network identity.
7248 // We just return the total video call data usage snapshot since boot.
7249 Phone phone = getPhone(subId);
7250 if (phone != null) {
7251 return phone.getVtDataUsage(perUidStats);
7252 }
7253 return null;
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007256 }
Jack Yueb89b242016-06-22 13:27:47 -07007257 }
Jack Yu75ab2952016-07-08 14:29:33 -07007258
7259 /**
7260 * Policy control of data connection. Usually used when data limit is passed.
7261 * @param enabled True if enabling the data, otherwise disabling.
7262 * @param subId Subscription index
7263 * {@hide}
7264 */
7265 @Override
7266 public void setPolicyDataEnabled(boolean enabled, int subId) {
7267 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 Phone phone = getPhone(subId);
7272 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007273 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 }
7275 } finally {
7276 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007277 }
7278 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007279
7280 /**
7281 * Get Client request stats
7282 * @return List of Client Request Stats
7283 * @hide
7284 */
7285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007286 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7287 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007289 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007290 return null;
7291 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007292 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 if (phone != null) {
7297 return phone.getClientRequestStats();
7298 }
7299
7300 return null;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007304 }
7305
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007306 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007307 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007308 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007309 }
Jack Yueb4124c2017-02-16 15:32:43 -08007310
7311 /**
Grace Chen70990072017-03-24 17:21:30 -07007312 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007313 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007314 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007315 * @param state State of SIM (power down, power up, pass through)
7316 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7317 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7318 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007319 *
7320 **/
7321 @Override
Grace Chen70990072017-03-24 17:21:30 -07007322 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007323 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007324 Phone phone = PhoneFactory.getPhone(slotIndex);
7325
vagdeviaf9a5b92018-08-15 16:01:53 -07007326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007331 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 }
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007335 }
7336 }
Shuo Qiandd210312017-04-12 22:11:33 +00007337
Tyler Gunn65d45c22017-06-05 11:22:26 -07007338 private boolean isUssdApiAllowed(int subId) {
7339 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007340 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007341 if (configManager == null) {
7342 return false;
7343 }
7344 PersistableBundle pb = configManager.getConfigForSubId(subId);
7345 if (pb == null) {
7346 return false;
7347 }
7348 return pb.getBoolean(
7349 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7350 }
7351
Shuo Qiandd210312017-04-12 22:11:33 +00007352 /**
7353 * Check if phone is in emergency callback mode
7354 * @return true if phone is in emergency callback mode
7355 * @param subId sub id
7356 */
goneil9c5f4872017-12-05 14:07:56 -08007357 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007358 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007359 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007360 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 if (phone != null) {
7365 return phone.isInEcm();
7366 } else {
7367 return false;
7368 }
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007371 }
7372 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007373
7374 /**
7375 * Get the current signal strength information for the given subscription.
7376 * Because this information is not updated when the device is in a low power state
7377 * it should not be relied-upon to be current.
7378 * @param subId Subscription index
7379 * @return the most recent cached signal strength info from the modem
7380 */
7381 @Override
7382 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final long identity = Binder.clearCallingIdentity();
7384 try {
7385 Phone p = getPhone(subId);
7386 if (p == null) {
7387 return null;
7388 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 return p.getSignalStrength();
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007394 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007395
Pengquan Meng77b7f132018-08-22 14:49:57 -07007396 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007397 * Get the current modem radio state for the given slot.
7398 * @param slotIndex slot index.
7399 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007400 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007401 * @return the current radio power state from the modem
7402 */
7403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007404 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007405 Phone phone = PhoneFactory.getPhone(slotIndex);
7406 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7408 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007409 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7410 }
7411
7412 final long identity = Binder.clearCallingIdentity();
7413 try {
7414 return phone.getRadioPowerState();
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 }
7419 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7420 }
7421
7422 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007423 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7424 *
7425 * <p>Requires one of the following permissions:
7426 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7427 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7428 * privileges.
7429 *
7430 * @param subId subscription id
7431 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7432 * {@code false}.
7433 */
7434 @Override
7435 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7437 null /* message */);
7438
Pengquan Menga1bb6272018-09-06 09:59:22 -07007439 boolean isEnabled = false;
7440 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007441 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007442 Phone phone = getPhone(subId);
7443 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007444 } catch (Exception e) {
7445 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7446 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007447 } finally {
7448 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007449 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007450 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007451 }
7452
7453
7454 /**
7455 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7456 *
7457 * <p> Requires permission:
7458 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7459 * privileges.
7460 *
7461 * @param subId subscription id
7462 * @param isEnabled {@code true} means enable, {@code false} means disable.
7463 */
7464 @Override
7465 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7467 mApp, subId, "setDataRoamingEnabled");
7468
Pengquan Menga1bb6272018-09-06 09:59:22 -07007469 final long identity = Binder.clearCallingIdentity();
7470 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007471 Phone phone = getPhone(subId);
7472 if (phone != null) {
7473 phone.setDataRoamingEnabled(isEnabled);
7474 }
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007477 }
7478 }
7479
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007480 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007481 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007482 TelephonyPermissions
7483 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007484 mApp, subId, "isManualNetworkSelectionAllowed");
7485
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007486 boolean isAllowed = true;
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007489 Phone phone = getPhone(subId);
7490 if (phone != null) {
7491 isAllowed = phone.isCspPlmnEnabled();
7492 }
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
7496 return isAllowed;
7497 }
7498
7499 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007500 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007501 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007502 try {
7503 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007504 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007505 } catch (SecurityException e) {
7506 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7507 // has carrier privileges on an active UICC
7508 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7509 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007510 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007511 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007512 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007513
7514 final long identity = Binder.clearCallingIdentity();
7515 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007516 UiccController uiccController = UiccController.getInstance();
7517 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007518 if (hasReadPermission) {
7519 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007520 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007521
7522 // Remove private info if the caller doesn't have access
7523 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7524 for (UiccCardInfo cardInfo : cardInfos) {
7525 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7526 // is available
7527 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7528 if (card == null || card.getUiccProfile() == null) {
7529 // assume no access if the card or profile is unavailable
7530 filteredInfos.add(cardInfo.getUnprivileged());
7531 continue;
7532 }
7533 UiccProfile profile = card.getUiccProfile();
7534 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7535 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7536 filteredInfos.add(cardInfo);
7537 } else {
7538 filteredInfos.add(cardInfo.getUnprivileged());
7539 }
7540 }
7541 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
7545 }
7546
7547 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007548 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007549 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
7553 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7554 if (slots == null) {
7555 Rlog.i(LOG_TAG, "slots is null.");
7556 return null;
7557 }
7558
7559 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7560 for (int i = 0; i < slots.length; i++) {
7561 UiccSlot slot = slots[i];
7562 if (slot == null) {
7563 continue;
7564 }
7565
Jordan Liu7be7e652019-05-06 18:55:02 +00007566 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 UiccCard card = slot.getUiccCard();
7568 if (card != null) {
7569 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007570 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007571 cardId = slot.getEid();
7572 if (TextUtils.isEmpty(cardId)) {
7573 cardId = slot.getIccId();
7574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 }
7576
Jordan Liu857451f2019-05-09 16:35:35 -07007577 if (cardId != null) {
7578 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7579 // if cardId is an EID, it's all digits so this is fine
7580 cardId = IccUtils.stripTrailingFs(cardId);
7581 }
7582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 int cardState = 0;
7584 switch (slot.getCardState()) {
7585 case CARDSTATE_ABSENT:
7586 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7587 break;
7588 case CARDSTATE_PRESENT:
7589 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7590 break;
7591 case CARDSTATE_ERROR:
7592 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7593 break;
7594 case CARDSTATE_RESTRICTED:
7595 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7596 break;
7597 default:
7598 break;
7599
7600 }
7601
7602 infos[i] = new UiccSlotInfo(
7603 slot.isActive(),
7604 slot.isEuicc(),
7605 cardId,
7606 cardState,
7607 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007608 slot.isExtendedApduSupported(),
7609 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 }
7611 return infos;
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007614 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007615 }
7616
7617 @Override
7618 public boolean switchSlots(int[] physicalSlots) {
7619 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620
7621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007627 }
Jack Yu4c988042018-02-27 15:30:01 -08007628
7629 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007630 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 return UiccController.getInstance().getCardIdForDefaultEuicc();
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 }
7638
Pengquan Meng85728fb2018-03-12 16:31:21 -07007639 /**
goneil47ffb6e2018-04-06 15:40:58 -07007640 * A test API to reload the UICC profile.
7641 *
7642 * <p>Requires that the calling app has permission
7643 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7644 * @hide
7645 */
7646 @Override
7647 public void refreshUiccProfile(int subId) {
7648 enforceModifyPermission();
7649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Phone phone = getPhone(subId);
7653 if (phone == null) {
7654 return;
7655 }
7656 UiccCard uiccCard = phone.getUiccCard();
7657 if (uiccCard == null) {
7658 return;
7659 }
7660 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7661 if (uiccProfile == null) {
7662 return;
7663 }
7664 uiccProfile.refresh();
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
7669
7670 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007671 * Returns false if the mobile data is disabled by default, otherwise return true.
7672 */
7673 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007674 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007675 }
7676
7677 /**
7678 * Returns true if the data roaming is enabled by default, i.e the system property
7679 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7680 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7681 */
7682 private boolean getDefaultDataRoamingEnabled(int subId) {
7683 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007684 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007685 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007686 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7687 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7688 return isDataRoamingEnabled;
7689 }
7690
7691 /**
7692 * Returns the default network type for the given {@code subId}, if the default network type is
7693 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7694 */
7695 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007696 List<Integer> list = TelephonyProperties.default_network();
7697 int phoneId = mSubscriptionController.getPhoneId(subId);
7698 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7699 return list.get(phoneId);
7700 }
7701 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007702 }
fionaxua13278b2018-03-21 00:08:13 -07007703
7704 @Override
7705 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007706 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 final Phone phone = getPhone(subId);
7712 if (phone == null) {
7713 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7714 return;
7715 }
chen xueaba88a2019-03-15 13:15:10 -07007716 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7717 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 } finally {
7719 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007720 }
fionaxua13278b2018-03-21 00:08:13 -07007721 }
7722
7723 @Override
7724 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007725 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726
7727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 final Phone phone = getPhone(subId);
7730 if (phone == null) {
7731 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7732 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7733 }
7734 return phone.getCarrierIdListVersion();
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007737 }
fionaxua13278b2018-03-21 00:08:13 -07007738 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007739
7740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007741 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7742 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007744 mApp, subId, callingPackage, callingFeatureId,
7745 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007746 return -1;
7747 }
7748
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
7751 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7752 } finally {
7753 Binder.restoreCallingIdentity(identity);
7754 }
7755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007756
7757 @Override
7758 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007759 TelephonyPermissions
7760 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007761 mApp, subId, "getCdmaRoamingMode");
7762
7763 final long identity = Binder.clearCallingIdentity();
7764 try {
7765 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
7769 }
7770
7771 @Override
7772 public boolean setCdmaRoamingMode(int subId, int mode) {
7773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7774 mApp, subId, "setCdmaRoamingMode");
7775
7776 final long identity = Binder.clearCallingIdentity();
7777 try {
7778 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
7782 }
7783
7784 @Override
7785 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7787 mApp, subId, "setCdmaSubscriptionMode");
7788
7789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7792 } finally {
7793 Binder.restoreCallingIdentity(identity);
7794 }
7795 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007796
sqianc5eccab2018-10-19 18:46:41 -07007797 @Override
sqian8c685422019-02-22 15:55:18 -08007798 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007799 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007801 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7802 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007803 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7804 }
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
sqian854d44b2018-12-12 16:48:18 -08007807 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7808 for (Phone phone: PhoneFactory.getPhones()) {
7809 if (phone.getEmergencyNumberTracker() != null
7810 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7811 emergencyNumberListInternal.put(
7812 phone.getSubId(),
7813 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7814 }
sqian11b7a0e2018-12-05 18:48:28 -08007815 }
sqian854d44b2018-12-12 16:48:18 -08007816 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
sqianc5eccab2018-10-19 18:46:41 -07007820 }
7821
7822 @Override
sqian8c685422019-02-22 15:55:18 -08007823 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007824 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007825 if (!exactMatch) {
7826 TelephonyPermissions
7827 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007828 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007829 }
7830 final long identity = Binder.clearCallingIdentity();
7831 try {
sqian854d44b2018-12-12 16:48:18 -08007832 for (Phone phone: PhoneFactory.getPhones()) {
7833 if (phone.getEmergencyNumberTracker() != null
7834 && phone.getEmergencyNumberTracker() != null) {
7835 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7836 number, exactMatch)) {
7837 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007838 }
7839 }
sqian11b7a0e2018-12-05 18:48:28 -08007840 }
7841 return false;
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
7845 }
7846
sqianf4ca7ed2019-01-15 18:32:07 -08007847 /**
7848 * Update emergency number list for test mode.
7849 */
7850 @Override
7851 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7853 "updateEmergencyNumberListTestMode");
7854
7855 final long identity = Binder.clearCallingIdentity();
7856 try {
7857 for (Phone phone: PhoneFactory.getPhones()) {
7858 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7859 if (tracker != null) {
7860 tracker.executeEmergencyNumberTestModeCommand(action, num);
7861 }
7862 }
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
7865 }
7866 }
7867
7868 /**
7869 * Get the full emergency number list for test mode.
7870 */
7871 @Override
7872 public List<String> getEmergencyNumberListTestMode() {
7873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7874 "getEmergencyNumberListTestMode");
7875
7876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 Set<String> emergencyNumbers = new HashSet<>();
7879 for (Phone phone: PhoneFactory.getPhones()) {
7880 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7881 if (tracker != null) {
7882 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7883 emergencyNumbers.add(num.getNumber());
7884 }
7885 }
7886 }
7887 return new ArrayList<>(emergencyNumbers);
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
7890 }
7891 }
7892
chen xud6b45bd2018-10-30 22:27:10 -07007893 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007894 public int getEmergencyNumberDbVersion(int subId) {
7895 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7896
7897 final long identity = Binder.clearCallingIdentity();
7898 try {
7899 final Phone phone = getPhone(subId);
7900 if (phone == null) {
7901 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7902 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7903 }
7904 return phone.getEmergencyNumberDbVersion();
7905 } finally {
7906 Binder.restoreCallingIdentity(identity);
7907 }
7908 }
7909
7910 @Override
7911 public void notifyOtaEmergencyNumberDbInstalled() {
7912 enforceModifyPermission();
7913
7914 final long identity = Binder.clearCallingIdentity();
7915 try {
7916 for (Phone phone: PhoneFactory.getPhones()) {
7917 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7918 if (tracker != null) {
7919 tracker.updateOtaEmergencyNumberDatabase();
7920 }
7921 }
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
7925 }
7926
7927 @Override
7928 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7929 enforceActiveEmergencySessionPermission();
7930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 for (Phone phone: PhoneFactory.getPhones()) {
7934 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7935 if (tracker != null) {
7936 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7937 }
7938 }
7939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
7942 }
7943
7944 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007945 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7946 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7947 Phone phone = getPhone(subId);
7948 if (phone == null) {
7949 return null;
7950 }
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 UiccProfile profile = UiccController.getInstance()
7954 .getUiccProfileForPhone(phone.getPhoneId());
7955 if (profile != null) {
7956 return profile.getCertsFromCarrierPrivilegeAccessRules();
7957 }
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
7961 return null;
7962 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007963
7964 /**
7965 * Enable or disable a modem stack.
7966 */
7967 @Override
7968 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7969 enforceModifyPermission();
7970
7971 final long identity = Binder.clearCallingIdentity();
7972 try {
7973 Phone phone = PhoneFactory.getPhone(slotIndex);
7974 if (phone == null) {
7975 return false;
7976 } else {
7977 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7978 }
7979 } finally {
7980 Binder.restoreCallingIdentity(identity);
7981 }
7982 }
Michelecea4cf22018-12-21 15:00:11 -08007983
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007984 /**
7985 * Whether a modem stack is enabled or not.
7986 */
7987 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007988 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7989 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007990 Phone phone = PhoneFactory.getPhone(slotIndex);
7991 if (phone == null) return false;
7992
7993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007994 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7995 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007996 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7997 }
7998
7999 final long identity = Binder.clearCallingIdentity();
8000 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008001 try {
8002 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8003 } catch (NoSuchElementException ex) {
8004 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8005 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008 }
8009 }
8010
Michelecea4cf22018-12-21 15:00:11 -08008011 @Override
Michele0ea7d782019-03-19 14:58:42 -07008012 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008013 enforceModifyPermission();
8014
8015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008018 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008019 .commit();
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
8022 }
8023 }
8024
8025 @Override
Michele0ea7d782019-03-19 14:58:42 -07008026 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008027 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008029 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8030 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008031 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008032 }
Michelecea4cf22018-12-21 15:00:11 -08008033
8034 final long identity = Binder.clearCallingIdentity();
8035 try {
Michele0ea7d782019-03-19 14:58:42 -07008036 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008037 } finally {
8038 Binder.restoreCallingIdentity(identity);
8039 }
8040 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008041
Michele0ea7d782019-03-19 14:58:42 -07008042 @TelephonyManager.IsMultiSimSupportedResult
8043 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008044 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8045 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8046 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008047 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8048 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008049 }
8050 // Check if the hardware supports multisim functionality. If usage of multisim is not
8051 // supported by the modem, indicate that it is restricted.
8052 PhoneCapability staticCapability =
8053 mPhoneConfigurationManager.getStaticPhoneCapability();
8054 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008055 loge("isMultiSimSupportedInternal: no static configuration available");
8056 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008057 }
Sarah Chin0605abf2019-12-06 10:24:18 -08008058 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008059 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8060 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008061 }
8062 // Check if support of multiple SIMs is restricted by carrier
8063 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008064 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008065 }
8066
Michele0ea7d782019-03-19 14:58:42 -07008067 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008068 }
8069
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008070 /**
8071 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008072 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8073 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8074 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008075 * @param numOfSims number of active sims we want to switch to
8076 */
8077 @Override
8078 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008079 if (numOfSims == 1) {
8080 enforceModifyPermission();
8081 } else {
8082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8083 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8084 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008085 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008086
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008087 try {
Michele30b57b22019-03-01 12:01:14 -08008088 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008089 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008090 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8091 return;
8092 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008093 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
8097 }
8098
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008099 @Override
8100 public boolean isApplicationOnUicc(int subId, int appType) {
8101 enforceReadPrivilegedPermission("isApplicationOnUicc");
8102 Phone phone = getPhone(subId);
8103 if (phone == null) {
8104 return false;
8105 }
8106 final long identity = Binder.clearCallingIdentity();
8107 try {
8108 UiccCard uiccCard = phone.getUiccCard();
8109 if (uiccCard == null) {
8110 return false;
8111 }
8112 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8113 if (uiccProfile == null) {
8114 return false;
8115 }
8116 if (TelephonyManager.APPTYPE_SIM <= appType
8117 && appType <= TelephonyManager.APPTYPE_ISIM) {
8118 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8119 }
8120 return false;
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
8125
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008126 /**
chen xub4baa772019-04-03 10:23:41 -07008127 * Get whether making changes to modem configurations will trigger reboot.
8128 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008129 */
8130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008131 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8132 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008134 mApp, subId, callingPackage, callingFeatureId,
8135 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008136 return false;
8137 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008138 final long identity = Binder.clearCallingIdentity();
8139 try {
8140 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8141 } finally {
8142 Binder.restoreCallingIdentity(identity);
8143 }
8144 }
8145
Nathan Harold29f5f052019-02-15 13:41:57 -08008146 private void updateModemStateMetrics() {
8147 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8148 // TODO: check the state for each modem if the api is ready.
8149 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8150 }
8151
Pengquan Meng3889a572019-01-23 11:16:29 -08008152 @Override
8153 public int[] getSlotsMapping() {
8154 enforceReadPrivilegedPermission("getSlotsMapping");
8155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8159 // All logical slots should have a mapping to a physical slot.
8160 int[] logicalSlotsMapping = new int[phoneCount];
8161 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8162 for (int i = 0; i < slotInfos.length; i++) {
8163 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8164 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8165 }
8166 }
8167 return logicalSlotsMapping;
8168 } finally {
8169 Binder.restoreCallingIdentity(identity);
8170 }
8171 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008172
8173 /**
8174 * Get the IRadio HAL Version
8175 */
8176 @Override
8177 public int getRadioHalVersion() {
8178 Phone phone = getDefaultPhone();
8179 if (phone == null) return -1;
8180 HalVersion hv = phone.getHalVersion();
8181 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8182 return hv.major * 100 + hv.minor;
8183 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008184
8185 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008186 * Get the current calling package name.
8187 * @return the current calling package name
8188 */
8189 @Override
8190 public String getCurrentPackageName() {
8191 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8192 }
8193
8194 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008195 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8196 * corresponding network requests on a subId.
8197 *
8198 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008199 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008200 * 2) APN is un-metered for this subscription, or
8201 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008202 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008203 *
8204 * @return whether data is allowed for a apn type.
8205 *
8206 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008207 */
8208 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008209 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008210 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8211 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008212
8213 // Now that all security checks passes, perform the operation as ourselves.
8214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone phone = getPhone(subId);
8217 if (phone == null) return false;
8218
Jack Yu41407ee2019-05-13 16:54:09 -07008219 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008220 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
8224 }
8225
8226 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008227 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008228 enforceReadPrivilegedPermission("isApnMetered");
8229
8230 // Now that all security checks passes, perform the operation as ourselves.
8231 final long identity = Binder.clearCallingIdentity();
8232 try {
8233 Phone phone = getPhone(subId);
8234 if (phone == null) return true; // By default return true.
8235
Jack Yu41407ee2019-05-13 16:54:09 -07008236 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008241
8242 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008243 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8244 int subscriptionId, IBooleanConsumer resultCallback) {
8245 enforceModifyPermission();
8246 long token = Binder.clearCallingIdentity();
8247 try {
8248 Phone phone = getPhone(subscriptionId);
8249 if (phone == null) {
8250 try {
8251 if (resultCallback != null) {
8252 resultCallback.accept(false);
8253 }
8254 } catch (RemoteException e) {
8255 // ignore
8256 }
8257 return;
8258 }
8259 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8260 Pair.create(specifiers, (x) -> {
8261 try {
8262 if (resultCallback != null) {
8263 resultCallback.accept(x);
8264 }
8265 } catch (RemoteException e) {
8266 // ignore
8267 }
8268 });
8269 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8270 } finally {
8271 Binder.restoreCallingIdentity(token);
8272 }
8273 }
8274
8275 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008276 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8277 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8278 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8279 if (iccRecords == null) {
8280 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8281 return false;
8282 }
8283 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8284 }
8285
8286 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008287 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008288 if (callingPackage == null) {
8289 callingPackage = getCurrentPackageName();
8290 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008291 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8292 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8293 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8294 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8295 }
8296 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8297 Intent intent = new Intent();
8298 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8299 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8300 // Bring up choose default SMS subscription dialog right now
8301 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8302 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8303 mApp.startActivity(intent);
8304 }
chen xud5ca2d52019-05-28 15:20:57 -07008305
8306 @Override
8307 public String getMmsUAProfUrl(int subId) {
8308 //TODO investigate if this API should require proper permission check in R b/133791609
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
Daniel Bright9a8791d2020-02-11 18:19:36 -08008311 return TelephonyResourceUtils
8312 .getResourcesForSubId(getDefaultPhone().getContext(), subId)
8313 .getString(com.android.telephony.resources.R.string
8314 .config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
8318 }
8319
8320 @Override
8321 public String getMmsUserAgent(int subId) {
8322 //TODO investigate if this API should require proper permission check in R b/133791609
8323 final long identity = Binder.clearCallingIdentity();
8324 try {
Daniel Bright9a8791d2020-02-11 18:19:36 -08008325 return TelephonyResourceUtils
8326 .getResourcesForSubId(getDefaultPhone().getContext(), subId)
8327 .getString(com.android.telephony.resources.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
8331 }
Jack Yub07d4972019-05-28 16:12:25 -07008332
8333 @Override
8334 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8335 enforceModifyPermission();
8336
8337 // Now that all security checks passes, perform the operation as ourselves.
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 Phone phone = getPhone(subId);
8341 if (phone == null) return false;
8342
8343 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
8347 }
8348
8349 @Override
8350 public boolean isDataAllowedInVoiceCall(int subId) {
8351 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8352
8353 // Now that all security checks passes, perform the operation as ourselves.
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 Phone phone = getPhone(subId);
8357 if (phone == null) return false;
8358
8359 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008364
changbettyd5c246e2019-12-24 15:40:37 +08008365 @Override
8366 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8367 enforceModifyPermission();
8368
8369 // Now that all security checks passes, perform the operation as ourselves.
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 Phone phone = getPhone(subId);
8373 if (phone == null) return false;
8374
8375 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
8379 }
8380
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008381 /**
8382 * Updates whether conference event pacakge handling is enabled.
8383 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8384 * otherwise.
8385 */
8386 @Override
8387 public void setCepEnabled(boolean isCepEnabled) {
8388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8389
8390 final long identity = Binder.clearCallingIdentity();
8391 try {
8392 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8393 for (Phone phone : PhoneFactory.getPhones()) {
8394 Phone defaultPhone = phone.getImsPhone();
8395 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8396 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8397 ImsPhoneCallTracker imsPhoneCallTracker =
8398 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8399 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8400 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8401 + imsPhone.getMsisdn());
8402 }
8403 }
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
allenwtsu46dcc572020-01-08 18:24:03 +08008408
8409 /**
8410 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8411 *
8412 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8413 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8414 * before being read.
8415 */
8416 @Override
8417 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8418 isCompressed) {
8419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8420 mApp, subId, "notifyRcsAutoConfigurationReceived");
8421 try {
8422 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8423 if (configBinder == null) {
8424 Rlog.e(LOG_TAG, "null result for getImsConfig");
8425 } else {
8426 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8427 }
8428 } catch (RemoteException e) {
8429 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8430 }
8431 }
zoey chene02881a2019-12-30 16:11:23 +08008432
8433 @Override
8434 public boolean isIccLockEnabled(int subId) {
8435 enforceReadPrivilegedPermission("isIccLockEnabled");
8436
8437 // Now that all security checks passes, perform the operation as ourselves.
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 Phone phone = getPhone(subId);
8441 if (phone != null && phone.getIccCard() != null) {
8442 return phone.getIccCard().getIccLockEnabled();
8443 } else {
8444 return false;
8445 }
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
8449 }
8450
8451 /**
8452 * Set the ICC pin lock enabled or disabled.
8453 *
8454 * @return an integer representing the status of IccLock enabled or disabled in the following
8455 * three cases:
8456 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8457 * successfully.
8458 * - Positive number and zero for remaining password attempts.
8459 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8460 *
8461 */
8462 @Override
8463 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8464 enforceModifyPermission();
8465
8466 Phone phone = getPhone(subId);
8467 if (phone == null) {
8468 return 0;
8469 }
8470 // Now that all security checks passes, perform the operation as ourselves.
8471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8474 new Pair<Boolean, String>(enabled, password), phone, null);
8475 return attemptsRemaining;
8476
8477 } catch (Exception e) {
8478 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
8481 }
8482 return 0;
8483 }
8484
8485 /**
8486 * Change the ICC password used in ICC pin lock.
8487 *
8488 * @return an integer representing the status of IccLock changed in the following three cases:
8489 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8490 * - Positive number and zero for remaining password attempts.
8491 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8492 *
8493 */
8494 @Override
8495 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8496 enforceModifyPermission();
8497
8498 Phone phone = getPhone(subId);
8499 if (phone == null) {
8500 return 0;
8501 }
8502 // Now that all security checks passes, perform the operation as ourselves.
8503 final long identity = Binder.clearCallingIdentity();
8504 try {
8505 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8506 new Pair<String, String>(oldPassword, newPassword), phone, null);
8507 return attemptsRemaining;
8508
8509 } catch (Exception e) {
8510 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8511 } finally {
8512 Binder.restoreCallingIdentity(identity);
8513 }
8514 return 0;
8515 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008516
8517 /**
8518 * Request for receiving user activity notification
8519 */
8520 @Override
8521 public void requestUserActivityNotification() {
8522 if (!mNotifyUserActivity.get()
8523 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8524 mNotifyUserActivity.set(true);
8525 }
8526 }
8527
8528 /**
8529 * Called when userActivity is signalled in the power manager.
8530 * This is safe to call from any thread, with any window manager locks held or not.
8531 */
8532 @Override
8533 public void userActivity() {
8534 // ***************************************
8535 // * Inherited from PhoneWindowManager *
8536 // ***************************************
8537 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8538 // WITH ITS LOCKS HELD.
8539 //
8540 // This code must be VERY careful about the locks
8541 // it acquires.
8542 // In fact, the current code acquires way too many,
8543 // and probably has lurking deadlocks.
8544
8545 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8546 throw new SecurityException("Only the OS may call notifyUserActivity()");
8547 }
8548
8549 if (mNotifyUserActivity.getAndSet(false)) {
8550 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8551 USER_ACTIVITY_NOTIFICATION_DELAY);
8552 }
8553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008554}