blob: d882ab2bab2400905b7936a67c6ce063bc28c4d7 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Jordan Liu102b2772020-03-04 13:59:23 -0800123import com.android.internal.annotations.VisibleForTesting;
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;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800764 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 if (ar.result == null) {
766 loge("getPreferredNetworkType: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("getPreferredNetworkType: CommandException: " +
769 ar.exception);
770 } else {
771 loge("getPreferredNetworkType: Unknown exception");
772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case CMD_SET_PREFERRED_NETWORK_TYPE:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
780 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700781 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800782 break;
783
784 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
785 handleNullReturnEvent(msg, "setPreferredNetworkType");
786 break;
787
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
789 request = (MainThreadRequest)msg.obj;
790 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
794 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
795 ar = (AsyncResult)msg.obj;
796 request = (MainThreadRequest)ar.userObj;
797 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000799 break;
800
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 case CMD_SET_VOICEMAIL_NUMBER:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
804 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800805 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
806 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 break;
808
809 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
810 handleNullReturnEvent(msg, "setVoicemailNumber");
811 break;
812
Stuart Scott54788802015-03-30 13:18:01 -0700813 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
816 request);
817 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
822 break;
823
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 case CMD_PERFORM_NETWORK_SCAN:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
827 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
828 break;
829
Shuo Qian4a594052020-01-23 11:59:30 -0800830 case CMD_GET_CALL_FORWARDING:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
833 int callForwardingReason = (Integer) request.argument;
834 getPhoneFromRequest(request).getCallForwardingOption(
835 callForwardingReason, onCompleted);
836 break;
837
838 case EVENT_GET_CALL_FORWARDING_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 CallForwardingInfo callForwardingInfo = null;
842 if (ar.exception == null && ar.result != null) {
843 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
844 for (CallForwardInfo callForwardInfo : callForwardInfos) {
845 // Service Class is a bit mask per 3gpp 27.007. Search for
846 // any service for voice call.
847 if ((callForwardInfo.serviceClass
848 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
849 callForwardingInfo = new CallForwardingInfo(
850 callForwardInfo.serviceClass, callForwardInfo.reason,
851 callForwardInfo.number,
852 callForwardInfo.timeSeconds);
853 break;
854 }
855 }
856 // Didn't find a call forward info for voice call.
857 if (callForwardingInfo == null) {
858 callForwardingInfo = new CallForwardingInfo(
859 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
860 0 /* reason */, null /* number */, 0 /* timeout */);
861 }
862 } else {
863 if (ar.result == null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
865 }
866 if (ar.exception != null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
868 }
869 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
874 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
875 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
877 }
878 }
879 callForwardingInfo = new CallForwardingInfo(
880 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
881 }
882 request.result = callForwardingInfo;
883 notifyRequester(request);
884 break;
885
886 case CMD_SET_CALL_FORWARDING:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
889 CallForwardingInfo callForwardingInfoToSet =
890 (CallForwardingInfo) request.argument;
891 getPhoneFromRequest(request).setCallForwardingOption(
892 callForwardingInfoToSet.getStatus(),
893 callForwardingInfoToSet.getReason(),
894 callForwardingInfoToSet.getNumber(),
895 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
896 break;
897
898 case EVENT_SET_CALL_FORWARDING_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null) {
902 request.result = true;
903 } else {
904 request.result = false;
905 loge("setCallForwarding exception: " + ar.exception);
906 }
907 notifyRequester(request);
908 break;
909
910 case CMD_GET_CALL_WAITING:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
913 getPhoneFromRequest(request).getCallWaiting(onCompleted);
914 break;
915
916 case EVENT_GET_CALL_WAITING_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
920 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800921 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800922 // Service Class is a bit mask per 3gpp 27.007.
923 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800924 if (callForwardResults.length > 1
925 && ((callForwardResults[1]
926 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
927 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800928 ? 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() */
Jordan Liu102b2772020-03-04 13:59:23 -08001621 @VisibleForTesting
1622 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001625 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001626 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1628 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001629 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001630 mTelephonySharedPreferences =
1631 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001632 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001633 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001634 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 publish();
1637 }
1638
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001639 private Phone getDefaultPhone() {
1640 Phone thePhone = getPhone(getDefaultSubscription());
1641 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1642 }
1643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 private void publish() {
1645 if (DBG) log("publish: " + this);
1646
Peter Wangc035ce42020-01-08 21:00:22 -08001647 TelephonyFrameworkInitializer
1648 .getTelephonyServiceManager()
1649 .getTelephonyServiceRegisterer()
1650 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
Stuart Scott584921c2015-01-15 17:10:34 -08001653 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001654 if (request.phone != null) {
1655 return request.phone;
1656 } else {
1657 return getPhoneFromSubId(request.subId);
1658 }
1659 }
1660
1661 private Phone getPhoneFromSubId(int subId) {
1662 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1663 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001664 }
1665
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001666 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1667 Phone phone = getPhoneFromRequest(request);
1668 return phone == null ? null :
1669 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1670 }
1671
Wink Saville36469e72014-06-11 15:17:00 -07001672 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001673 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001674 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676
Naina Nallurid63128d2019-09-17 14:10:30 -07001677 private void sendEraseModemConfig(Phone phone) {
1678 if (phone != null) {
1679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1680 mApp, phone.getSubId(), "eraseModemConfig");
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1684 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
1687 }
1688 }
1689 }
1690
Peter Wang44b186e2020-01-13 23:33:09 -08001691 private boolean isImsAvailableOnDevice() {
1692 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1693 if (pm == null) {
1694 // For some reason package manger is not available.. This will fail internally anyway,
1695 // so do not throw error and allow.
1696 return true;
1697 }
1698 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1699 }
1700
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001702 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001703 }
1704
Wink Savilleb564aae2014-10-23 10:18:09 -07001705 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 if (DBG) log("dial: " + number);
1707 // No permission check needed here: This is just a wrapper around the
1708 // ACTION_DIAL intent, which is available to any app since it puts up
1709 // the UI before it does anything.
1710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 String url = createTelUrl(number);
1714 if (url == null) {
1715 return;
1716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001718 // PENDING: should we just silently fail if phone is offhook or ringing?
1719 PhoneConstants.State state = mCM.getState(subId);
1720 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1721 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1722 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1723 mApp.startActivity(intent);
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728 }
1729
1730 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001731 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001732 }
1733
Wink Savilleb564aae2014-10-23 10:18:09 -07001734 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 if (DBG) log("call: " + number);
1736
1737 // This is just a wrapper around the ACTION_CALL intent, but we still
1738 // need to do a permission check since we're calling startActivity()
1739 // from the context of the phone app.
1740 enforceCallPermission();
1741
Jordan Liu1617b712019-07-10 15:06:26 -07001742 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 != AppOpsManager.MODE_ALLOWED) {
1744 return;
1745 }
1746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 String url = createTelUrl(number);
1750 if (url == null) {
1751 return;
1752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001754 boolean isValid = false;
1755 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1756 if (slist != null) {
1757 for (SubscriptionInfo subInfoRecord : slist) {
1758 if (subInfoRecord.getSubscriptionId() == subId) {
1759 isValid = true;
1760 break;
1761 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001762 }
Wink Saville08874612014-08-31 19:19:58 -07001763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001764 if (!isValid) {
1765 return;
1766 }
Wink Saville08874612014-08-31 19:19:58 -07001767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1769 intent.putExtra(SUBSCRIPTION_KEY, subId);
1770 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1771 mApp.startActivity(intent);
1772 } finally {
1773 Binder.restoreCallingIdentity(identity);
1774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 }
1776
Wink Savilleb564aae2014-10-23 10:18:09 -07001777 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001778 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001779 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1780 }
1781
Wink Savilleb564aae2014-10-23 10:18:09 -07001782 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001783 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001784 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1785 }
1786
Wink Savilleb564aae2014-10-23 10:18:09 -07001787 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1793 checkSimPin.start();
1794 return checkSimPin.unlockSim(null, pin);
1795 } finally {
1796 Binder.restoreCallingIdentity(identity);
1797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 }
1799
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1806 checkSimPuk.start();
1807 return checkSimPuk.unlockSim(puk, pin);
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
1810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
1813 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001814 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 * a synchronous one.
1816 */
1817 private static class UnlockSim extends Thread {
1818
1819 private final IccCard mSimCard;
1820
1821 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001822 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1823 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824
1825 // For replies from SimCard interface
1826 private Handler mHandler;
1827
1828 // For async handler to identify request type
1829 private static final int SUPPLY_PIN_COMPLETE = 100;
1830
1831 public UnlockSim(IccCard simCard) {
1832 mSimCard = simCard;
1833 }
1834
1835 @Override
1836 public void run() {
1837 Looper.prepare();
1838 synchronized (UnlockSim.this) {
1839 mHandler = new Handler() {
1840 @Override
1841 public void handleMessage(Message msg) {
1842 AsyncResult ar = (AsyncResult) msg.obj;
1843 switch (msg.what) {
1844 case SUPPLY_PIN_COMPLETE:
1845 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1846 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001847 mRetryCount = msg.arg1;
1848 if (ar.exception != null) {
1849 if (ar.exception instanceof CommandException &&
1850 ((CommandException)(ar.exception)).getCommandError()
1851 == CommandException.Error.PASSWORD_INCORRECT) {
1852 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1853 } else {
1854 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1855 }
1856 } else {
1857 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 mDone = true;
1860 UnlockSim.this.notifyAll();
1861 }
1862 break;
1863 }
1864 }
1865 };
1866 UnlockSim.this.notifyAll();
1867 }
1868 Looper.loop();
1869 }
1870
1871 /*
1872 * Use PIN or PUK to unlock SIM card
1873 *
1874 * If PUK is null, unlock SIM card with PIN
1875 *
1876 * If PUK is not null, unlock SIM card with PUK and set PIN code
1877 */
Wink Saville9de0f752013-10-22 19:04:03 -07001878 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879
1880 while (mHandler == null) {
1881 try {
1882 wait();
1883 } catch (InterruptedException e) {
1884 Thread.currentThread().interrupt();
1885 }
1886 }
1887 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1888
1889 if (puk == null) {
1890 mSimCard.supplyPin(pin, callback);
1891 } else {
1892 mSimCard.supplyPuk(puk, pin, callback);
1893 }
1894
1895 while (!mDone) {
1896 try {
1897 Log.d(LOG_TAG, "wait for done");
1898 wait();
1899 } catch (InterruptedException e) {
1900 // Restore the interrupted status
1901 Thread.currentThread().interrupt();
1902 }
1903 }
1904 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001905 int[] resultArray = new int[2];
1906 resultArray[0] = mResult;
1907 resultArray[1] = mRetryCount;
1908 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910 }
1911
1912 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001913 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914
1915 }
1916
Wink Savilleb564aae2014-10-23 10:18:09 -07001917 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 // No permission check needed here: this call is harmless, and it's
1919 // needed for the ServiceState.requestStateUpdate() call (which is
1920 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001921 final long identity = Binder.clearCallingIdentity();
1922 try {
1923 final Phone phone = getPhone(subId);
1924 if (phone != null) {
1925 phone.updateServiceLocation();
1926 }
1927 } finally {
1928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 }
1931
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001932 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001933 @Override
1934 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001935 return isRadioOnWithFeature(callingPackage, null);
1936 }
1937
1938
1939 @Override
1940 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1941 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1942 callingFeatureId);
1943 }
1944
1945 @Deprecated
1946 @Override
1947 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1948 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001949 }
1950
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001952 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1953 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001955 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001956 return false;
1957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958
1959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 return isRadioOnForSubscriber(subId);
1962 } finally {
1963 Binder.restoreCallingIdentity(identity);
1964 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 }
1966
1967 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 final long identity = Binder.clearCallingIdentity();
1969 try {
1970 final Phone phone = getPhone(subId);
1971 if (phone != null) {
1972 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1973 } else {
1974 return false;
1975 }
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
1981 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001982 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
Wink Saville36469e72014-06-11 15:17:00 -07001984
Wink Savilleb564aae2014-10-23 10:18:09 -07001985 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987
1988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 final Phone phone = getPhone(subId);
1991 if (phone != null) {
1992 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Wink Saville36469e72014-06-11 15:17:00 -07001997 }
1998
1999 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002000 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002001 }
2002
Wink Savilleb564aae2014-10-23 10:18:09 -07002003 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 final Phone phone = getPhone(subId);
2009 if (phone == null) {
2010 return false;
2011 }
2012 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2013 toggleRadioOnOffForSubscriber(subId);
2014 }
2015 return true;
2016 } finally {
2017 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
Wink Saville36469e72014-06-11 15:17:00 -07002020
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002021 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002022 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002023 /*
2024 * If any of the Radios are available, it will need to be
2025 * shutdown. So return true if any Radio is available.
2026 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027 final long identity = Binder.clearCallingIdentity();
2028 try {
2029 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2030 Phone phone = PhoneFactory.getPhone(i);
2031 if (phone != null && phone.isRadioAvailable()) return true;
2032 }
2033 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2034 return false;
2035 } finally {
2036 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002037 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002038 }
2039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002041 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 enforceModifyPermission();
2043
2044 final long identity = Binder.clearCallingIdentity();
2045 try {
2046 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2047 logv("Shutting down Phone " + i);
2048 shutdownRadioUsingPhoneId(i);
2049 }
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002052 }
2053 }
2054
2055 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002056 Phone phone = PhoneFactory.getPhone(phoneId);
2057 if (phone != null && phone.isRadioAvailable()) {
2058 phone.shutdownRadio();
2059 }
2060 }
2061
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002064
2065 final long identity = Binder.clearCallingIdentity();
2066 try {
2067 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2068 if (defaultPhone != null) {
2069 defaultPhone.setRadioPower(turnOn);
2070 return true;
2071 } else {
2072 loge("There's no default phone.");
2073 return false;
2074 }
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002077 }
Wink Saville36469e72014-06-11 15:17:00 -07002078 }
2079
Wink Savilleb564aae2014-10-23 10:18:09 -07002080 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002082
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
2087 phone.setRadioPower(turnOn);
2088 return true;
2089 } else {
2090 return false;
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
Wink Saville36469e72014-06-11 15:17:00 -07002097 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 public boolean enableDataConnectivity() {
2100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 int subId = mSubscriptionController.getDefaultDataSubId();
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002107 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108 return true;
2109 } else {
2110 return false;
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
Wink Saville36469e72014-06-11 15:17:00 -07002117 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 public boolean disableDataConnectivity() {
2120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121
2122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 int subId = mSubscriptionController.getDefaultDataSubId();
2125 final Phone phone = getPhone(subId);
2126 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002127 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002128 return true;
2129 } else {
2130 return false;
2131 }
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Sanket Padawe356d7632015-06-22 14:03:32 -07002137 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002138 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 final Phone phone = getPhone(subId);
2142 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002143 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002144 } else {
2145 return false;
2146 }
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 }
2151
2152 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002153 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002154 }
2155
pkanwarae03a6b2016-11-06 20:37:09 -08002156 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002157 enforceCallPermission();
2158
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2162 return;
2163 }
2164 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2165 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
pkanwar32d516d2016-10-14 19:37:38 -07002169 };
2170
Wink Savilleb564aae2014-10-23 10:18:09 -07002171 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2177 return false;
2178 }
2179 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002186 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002187 }
2188
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002189 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 Phone phone = PhoneFactory.getPhone(slotIndex);
2193 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2194 PhoneConstantConversions.convertCallState(phone.getState());
2195 } finally {
2196 Binder.restoreCallingIdentity(identity);
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199
Sanket Padawe356d7632015-06-22 14:03:32 -07002200 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002201 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002202 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2203 }
2204
2205 @Override
2206 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002209 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210 if (phone != null) {
2211 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2212 } else {
2213 return PhoneConstantConversions.convertDataState(
2214 PhoneConstants.DataState.DISCONNECTED);
2215 }
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002222 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002223 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2224 }
2225
2226 @Override
2227 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 final long identity = Binder.clearCallingIdentity();
2229 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002230 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 if (phone != null) {
2232 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2233 } else {
2234 return TelephonyManager.DATA_ACTIVITY_NONE;
2235 }
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002242 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002244 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002245
2246 LocationAccessPolicy.LocationPermissionResult locationResult =
2247 LocationAccessPolicy.checkLocationPermission(mApp,
2248 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2249 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002250 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002251 .setCallingPid(Binder.getCallingPid())
2252 .setCallingUid(Binder.getCallingUid())
2253 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002254 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002255 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2256 .build());
2257 switch (locationResult) {
2258 case DENIED_HARD:
2259 throw new SecurityException("Not allowed to access cell location");
2260 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002261 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2262 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 }
2264
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002265 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002269 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002270 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 } finally {
2272 Binder.restoreCallingIdentity(identity);
2273 }
Svetoslav64fad262015-04-14 14:35:21 -07002274 }
2275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002277 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002278 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2279 // registered cell info, so return a NULL country instead.
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002282 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2283 // Get default phone in this case.
2284 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2285 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002286 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002287 // Todo: fix this when we can get the actual cellular network info when the device
2288 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002289 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002290 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2291 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002292 return "";
2293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 Phone phone = PhoneFactory.getPhone(phoneId);
2295 if (phone != null) {
2296 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002297 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 if (sst != null) {
2299 LocaleTracker lt = sst.getLocaleTracker();
2300 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002301 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2302 return lt.getCurrentCountry();
2303 } else if (emergencyNumberTracker != null) {
2304 return emergencyNumberTracker.getEmergencyCountryIso();
2305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 }
2307 }
2308 }
2309 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002313 }
2314
2315 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002317 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002321 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 mApp.enforceCallingOrSelfPermission(
2323 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 final Phone phone = getPhone(subId);
2328 if (phone != null) {
2329 phone.enableLocationUpdates();
2330 }
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
2336 @Override
2337 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002338 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002342 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 mApp.enforceCallingOrSelfPermission(
2344 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 final Phone phone = getPhone(subId);
2349 if (phone != null) {
2350 phone.disableLocationUpdates();
2351 }
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 }
2356
Nathan Harold31d7ff32018-10-15 20:20:30 -07002357 /**
2358 * Returns the target SDK version number for a given package name.
2359 *
Nathan Haroldec184742019-07-10 17:04:16 -07002360 * This call MUST be invoked before clearing the calling UID.
2361 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002362 * @return target SDK if the package is found or INT_MAX.
2363 */
2364 private int getTargetSdk(String packageName) {
2365 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002366 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002367 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002368 if (ai != null) return ai.targetSdkVersion;
2369 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002370 loge("Failed to get package info for pkg="
2371 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002372 }
2373 return Integer.MAX_VALUE;
2374 }
2375
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 @Override
2377 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002378 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2379 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002380 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002381 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2382 throw new SecurityException(
2383 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2384 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002385
Jordan Liu1617b712019-07-10 15:06:26 -07002386 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2388 return null;
2389 }
Svetoslav64fad262015-04-14 14:35:21 -07002390
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002391 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002393 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002394 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395
Nathan Haroldf180aac2018-06-01 18:43:55 -07002396 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2397 for (CellInfo ci : info) {
2398 if (ci instanceof CellInfoGsm) {
2399 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2400 } else if (ci instanceof CellInfoWcdma) {
2401 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002404 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002407 private List<CellInfo> getCachedCellInfo() {
2408 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2409 for (Phone phone : PhoneFactory.getPhones()) {
2410 List<CellInfo> info = phone.getAllCellInfo();
2411 if (info != null) cellInfos.addAll(info);
2412 }
2413 return cellInfos;
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
2416 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002417 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002418 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002419 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002420
2421 LocationAccessPolicy.LocationPermissionResult locationResult =
2422 LocationAccessPolicy.checkLocationPermission(mApp,
2423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2424 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002425 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002426 .setCallingPid(Binder.getCallingPid())
2427 .setCallingUid(Binder.getCallingUid())
2428 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002429 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002430 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2431 .build());
2432 switch (locationResult) {
2433 case DENIED_HARD:
2434 throw new SecurityException("Not allowed to access cell info");
2435 case DENIED_SOFT:
2436 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 final int targetSdk = getTargetSdk(callingPackage);
2440 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2441 return getCachedCellInfo();
2442 }
2443
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002444 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2449 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002450 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002451 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 if (info != null) cellInfos.addAll(info);
2453 }
2454 return cellInfos;
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458 }
2459
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002460 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002461 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2462 String callingFeatureId) {
2463 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2464 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002465 }
2466
2467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002468 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2469 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002470 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002471 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002472 }
2473
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002474 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2475 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002476 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002478
2479 LocationAccessPolicy.LocationPermissionResult locationResult =
2480 LocationAccessPolicy.checkLocationPermission(mApp,
2481 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2482 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002483 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002484 .setCallingPid(Binder.getCallingPid())
2485 .setCallingUid(Binder.getCallingUid())
2486 .setMethod("requestCellInfoUpdate")
2487 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2488 .build());
2489 switch (locationResult) {
2490 case DENIED_HARD:
2491 throw new SecurityException("Not allowed to access cell info");
2492 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002493 try {
2494 cb.onCellInfo(new ArrayList<CellInfo>());
2495 } catch (RemoteException re) {
2496 // Drop without consequences
2497 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002498 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002499 }
2500
Nathan Harolda939a962019-05-09 10:13:47 -07002501
2502 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002503 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2504
2505 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2506 }
2507
2508 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002510 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002515 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516 } finally {
2517 Binder.restoreCallingIdentity(identity);
2518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Shishir Agrawala9f32182016-04-12 12:00:16 -07002521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002522 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002523 Phone phone = PhoneFactory.getPhone(slotIndex);
2524 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002525 return null;
2526 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002527 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002528 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 return null;
2531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 return phone.getImei();
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002539 }
2540
2541 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002542 public String getTypeAllocationCodeForSlot(int slotIndex) {
2543 Phone phone = PhoneFactory.getPhone(slotIndex);
2544 String tac = null;
2545 if (phone != null) {
2546 String imei = phone.getImei();
2547 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2548 }
2549 return tac;
2550 }
2551
2552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002553 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002554 Phone phone = PhoneFactory.getPhone(slotIndex);
2555 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002556 return null;
2557 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002558
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002560 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 return null;
2563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 return phone.getMeid();
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Jack Yu2af8d712017-03-15 17:14:14 -07002571 }
2572
2573 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002574 public String getManufacturerCodeForSlot(int slotIndex) {
2575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 String manufacturerCode = null;
2577 if (phone != null) {
2578 String meid = phone.getMeid();
2579 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2580 }
2581 return manufacturerCode;
2582 }
2583
2584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002585 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2586 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002587 Phone phone = PhoneFactory.getPhone(slotIndex);
2588 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 return null;
2590 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 int subId = phone.getSubId();
2592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 mApp, subId, callingPackage, callingFeatureId,
2594 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002595 return null;
2596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 return phone.getDeviceSvn();
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002604 }
2605
fionaxu43304da2017-11-27 22:51:16 -08002606 @Override
2607 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
2611 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
fionaxu43304da2017-11-27 22:51:16 -08002615 }
2616
2617 @Override
2618 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 final Phone phone = getPhone(subId);
2622 return phone == null ? null : phone.getCarrierName();
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
fionaxu43304da2017-11-27 22:51:16 -08002626 }
2627
calvinpanffe225e2018-11-01 19:43:06 +08002628 @Override
chen xu0026ca62019-03-06 15:28:50 -08002629 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 final Phone phone = getPhone(subId);
2633 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002634 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002635 } finally {
2636 Binder.restoreCallingIdentity(identity);
2637 }
2638 }
2639
2640 @Override
chen xu0026ca62019-03-06 15:28:50 -08002641 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002645 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
2649 }
2650
chen xu651eec72018-11-11 19:03:44 -08002651 @Override
chen xu864e11c2018-12-06 22:10:03 -08002652 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2653 if (!isSubscriptionMccMnc) {
2654 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2655 }
chen xu651eec72018-11-11 19:03:44 -08002656 final Phone phone = PhoneFactory.getPhone(slotIndex);
2657 if (phone == null) {
2658 return TelephonyManager.UNKNOWN_CARRIER_ID;
2659 }
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
2666 }
2667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 //
2669 // Internal helper methods.
2670 //
2671
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002672 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2674 *
2675 * @throws SecurityException if the caller does not have the required permission
2676 */
2677 private void enforceModifyPermission() {
2678 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2679 }
2680
Shuo Qiancd19c462020-01-16 20:51:11 -08002681 /**
2682 * Make sure the caller is system.
2683 *
2684 * @throws SecurityException if the caller is not system.
2685 */
2686 private void enforceSystemCaller() {
2687 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2688 throw new SecurityException("Caller must be system");
2689 }
2690 }
2691
Shuo Qian3b6ee772019-11-13 17:43:31 -08002692 private void enforceActiveEmergencySessionPermission() {
2693 mApp.enforceCallingOrSelfPermission(
2694 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2695 }
2696
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 /**
2698 * Make sure the caller has the CALL_PHONE permission.
2699 *
2700 * @throws SecurityException if the caller does not have the required permission
2701 */
2702 private void enforceCallPermission() {
2703 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2704 }
2705
paulhu5a773602019-08-23 19:17:33 +08002706 private void enforceSettingsPermission() {
2707 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002708 }
2709
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 private String createTelUrl(String number) {
2711 if (TextUtils.isEmpty(number)) {
2712 return null;
2713 }
2714
Jake Hambye994d462014-02-03 13:10:13 -08002715 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
Ihab Awadf9e92732013-12-05 18:02:52 -08002718 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2720 }
2721
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002722 private static void logv(String msg) {
2723 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2724 }
2725
Ihab Awadf9e92732013-12-05 18:02:52 -08002726 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2728 }
2729
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002730 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002732 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002733 }
2734
Sanket Padawe356d7632015-06-22 14:03:32 -07002735 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002736 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 final Phone phone = PhoneFactory.getPhone(slotIndex);
2740 if (phone == null) {
2741 return PhoneConstants.PHONE_TYPE_NONE;
2742 } else {
2743 return phone.getPhoneType();
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
2749
2750 /**
2751 * Returns the CDMA ERI icon index to display
2752 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002754 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2755 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2756 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
Sanket Padawe356d7632015-06-22 14:03:32 -07002759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002760 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2761 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002763 mApp, subId, callingPackage, callingFeatureId,
2764 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002765 return -1;
2766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone != null) {
2772 return phone.getCdmaEriIconIndex();
2773 } else {
2774 return -1;
2775 }
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
2781 /**
2782 * Returns the CDMA ERI icon mode,
2783 * 0 - ON
2784 * 1 - FLASHING
2785 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002786 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002787 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2788 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2789 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002793 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2794 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002796 mApp, subId, callingPackage, callingFeatureId,
2797 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002798 return -1;
2799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 final Phone phone = getPhone(subId);
2804 if (phone != null) {
2805 return phone.getCdmaEriIconMode();
2806 } else {
2807 return -1;
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813
2814 /**
2815 * Returns the CDMA ERI text,
2816 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002817 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002818 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2819 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2820 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002821 }
2822
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002824 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2825 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002827 mApp, subId, callingPackage, callingFeatureId,
2828 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002829 return null;
2830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831
2832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 final Phone phone = getPhone(subId);
2835 if (phone != null) {
2836 return phone.getCdmaEriText();
2837 } else {
2838 return null;
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 }
2844
2845 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002846 * Returns the CDMA MDN.
2847 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002849 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2851 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 return phone.getLine1Number();
2858 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002859 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860 return null;
2861 }
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002864 }
2865 }
2866
2867 /**
2868 * Returns the CDMA MIN.
2869 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002871 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2873 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 final Phone phone = getPhone(subId);
2878 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2879 return phone.getCdmaMin();
2880 } else {
2881 return null;
2882 }
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002885 }
2886 }
2887
Hall Liud892bec2018-11-30 14:51:45 -08002888 @Override
2889 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2890 INumberVerificationCallback callback, String callingPackage) {
2891 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2892 != PERMISSION_GRANTED) {
2893 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2894 }
2895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2896
2897 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2898 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2899 throw new SecurityException("Calling package must be configured in the device config");
2900 }
2901
2902 if (range == null) {
2903 throw new NullPointerException("Range must be non-null");
2904 }
2905
2906 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002907 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002908
2909 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2910 }
2911
Junda Liuca05d5d2014-08-14 22:36:34 -07002912 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 * Returns true if CDMA provisioning needs to run.
2914 */
2915 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002918 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922 }
2923
2924 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002925 * Sets the voice mail number of a given subId.
2926 */
2927 @Override
2928 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2930 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2935 new Pair<String, String>(alphaTag, number), new Integer(subId));
2936 return success;
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002940 }
2941
Ta-wei Yen87c49842016-05-13 21:19:52 -07002942 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002943 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002945 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2946 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002947 if (!TextUtils.equals(callingPackage, systemDialer)) {
2948 throw new SecurityException("caller must be system dialer");
2949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2954 if (phoneAccountHandle == null) {
2955 return null;
2956 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 } finally {
2959 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002960 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002961 }
2962
2963 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002964 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2965 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002966 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002968 mApp, subId, callingPackage, callingFeatureId,
2969 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002970 return null;
2971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002973 final long identity = Binder.clearCallingIdentity();
2974 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002975 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002979 }
2980
2981 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002982 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2983 VisualVoicemailSmsFilterSettings settings) {
2984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002993 }
2994
2995 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002996 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003002 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003006 }
3007
3008 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003009 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3010 String callingPackage, int subId) {
3011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003016 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003020 }
3021
3022 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003023 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025
3026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003029 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003033 }
3034
3035 @Override
3036 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3037 String number, int port, String text, PendingIntent sentIntent) {
3038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003039 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003040 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003041 SmsController smsController = PhoneFactory.getSmsController();
3042 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3043 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003044 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003045
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003046 /**
fionaxu0152e512016-11-14 13:36:14 -08003047 * Sets the voice activation state of a given subId.
3048 */
3049 @Override
3050 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3052 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 final Phone phone = getPhone(subId);
3057 if (phone != null) {
3058 phone.setVoiceActivationState(activationState);
3059 } else {
3060 loge("setVoiceActivationState fails with invalid subId: " + subId);
3061 }
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003064 }
3065 }
3066
3067 /**
3068 * Sets the data activation state of a given subId.
3069 */
3070 @Override
3071 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3073 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 final Phone phone = getPhone(subId);
3078 if (phone != null) {
3079 phone.setDataActivationState(activationState);
3080 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003081 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 }
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003085 }
3086 }
3087
3088 /**
3089 * Returns the voice activation state of a given subId.
3090 */
3091 @Override
3092 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
fionaxu0152e512016-11-14 13:36:14 -08003095 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 if (phone != null) {
3099 return phone.getVoiceActivationState();
3100 } else {
3101 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3102 }
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003105 }
3106 }
3107
3108 /**
3109 * Returns the data activation state of a given subId.
3110 */
3111 @Override
3112 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114
fionaxu0152e512016-11-14 13:36:14 -08003115 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 if (phone != null) {
3119 return phone.getDataActivationState();
3120 } else {
3121 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3122 }
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003125 }
3126 }
3127
3128 /**
Wink Saville36469e72014-06-11 15:17:00 -07003129 * Returns the unread count of voicemails for a subId
3130 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003132 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3133 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003135 mApp, subId, callingPackage, callingFeatureId,
3136 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003137 return 0;
3138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
3142 if (phone != null) {
3143 return phone.getVoiceMessageCount();
3144 } else {
3145 return 0;
3146 }
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151
3152 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003153 * returns true, if the device is in a state where both voice and data
3154 * are supported simultaneously. This can change based on location or network condition.
3155 */
3156 @Override
3157 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003165 }
3166
3167 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003168 * Send the dialer code if called from the current default dialer or the caller has
3169 * carrier privilege.
3170 * @param inputCode The dialer code to send
3171 */
3172 @Override
3173 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003175 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003176 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3177 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003178 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003179 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003180 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003185 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
fionaxu235cc5e2017-03-06 22:25:57 -08003189 }
3190
Pengquan Menga1bb6272018-09-06 09:59:22 -07003191 @Override
3192 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003193 TelephonyPermissions
3194 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3195 mApp, subId, "getNetworkSelectionMode");
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 if (!isActiveSubscription(subId)) {
3199 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3200 }
3201 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003204 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003205 }
3206
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003208 public boolean isInEmergencySmsMode() {
3209 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 for (Phone phone : PhoneFactory.getPhones()) {
3213 if (phone.isInEmergencySmsMode()) {
3214 return true;
3215 }
3216 }
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 return false;
3221 }
3222
shilu366312e2019-12-17 09:28:10 -08003223 /**
3224 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3225 * @param subId The subscription to use to check the configuration.
3226 * @param c The callback that will be used to send the result.
3227 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003228 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003229 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3230 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003231 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3232 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003233
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003234 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3235 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3236 "IMS not available on device.");
3237 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 final long token = Binder.clearCallingIdentity();
3239 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003241 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003243 } catch (ImsException e) {
3244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 } finally {
3246 Binder.restoreCallingIdentity(token);
3247 }
3248 }
3249
shilu366312e2019-12-17 09:28:10 -08003250 /**
3251 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3252 * @param subId The subscription to use to check the configuration.
3253 * @param c The callback that will be used to send the result.
3254 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003256 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003257 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3258 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003259 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3260 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3261 }
Meng Wangafbc5852019-09-19 17:37:13 -07003262 final long token = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3265 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3266 .removeRegistrationCallbackForSubscription(c, subId);
3267 } catch (ImsException e) {
3268 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3269 + "is inactive, ignoring unregister.");
3270 // If the subscription is no longer active, just return, since the callback
3271 // will already have been removed internally.
3272 } finally {
3273 Binder.restoreCallingIdentity(token);
3274 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 }
3276
Brad Ebingera34a6c22019-10-22 17:36:18 -07003277 /**
3278 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3279 */
3280 @Override
3281 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3282 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3283 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3284 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3285 "IMS not available on device.");
3286 }
3287 final long token = Binder.clearCallingIdentity();
3288 try {
3289 Phone phone = getPhone(subId);
3290 if (phone == null) {
3291 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3292 + subId + "'");
3293 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3294 }
3295 phone.getImsRegistrationState(regState -> {
3296 try {
3297 consumer.accept((regState == null)
3298 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3299 } catch (RemoteException e) {
3300 // Ignore if the remote process is no longer available to call back.
3301 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3302 }
3303 });
3304 } finally {
3305 Binder.restoreCallingIdentity(token);
3306 }
3307 }
3308
3309 /**
3310 * Get the transport type for the IMS service registration state.
3311 */
3312 @Override
3313 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003314 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3315 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003316 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3318 "IMS not available on device.");
3319 }
3320 final long token = Binder.clearCallingIdentity();
3321 try {
3322 Phone phone = getPhone(subId);
3323 if (phone == null) {
3324 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3325 + subId + "'");
3326 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3327 }
3328 phone.getImsRegistrationTech(regTech -> {
3329 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3330 int regTechConverted = (regTech == null)
3331 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3332 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3333 regTechConverted);
3334 try {
3335 consumer.accept(regTechConverted);
3336 } catch (RemoteException e) {
3337 // Ignore if the remote process is no longer available to call back.
3338 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3339 }
3340 });
3341 } finally {
3342 Binder.restoreCallingIdentity(token);
3343 }
3344 }
3345
shilu366312e2019-12-17 09:28:10 -08003346 /**
3347 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3348 * @param subId The subscription to use to check the configuration.
3349 * @param c The callback that will be used to send the result.
3350 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003352 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3353 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003354 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3355 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003356 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3357 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3358 "IMS not available on device.");
3359 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3361 final long token = Binder.clearCallingIdentity();
3362 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003365 } catch (ImsException e) {
3366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 } finally {
3368 Binder.restoreCallingIdentity(token);
3369 }
3370 }
3371
shilu366312e2019-12-17 09:28:10 -08003372 /**
3373 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3374 * @param subId The subscription to use to check the configuration.
3375 * @param c The callback that will be used to send the result.
3376 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003378 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003379 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3380 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3382 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3383 }
Meng Wangafbc5852019-09-19 17:37:13 -07003384
3385 final long token = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3388 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003389 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003390 } catch (ImsException e) {
3391 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3392 + "is inactive, ignoring unregister.");
3393 // If the subscription is no longer active, just return, since the callback
3394 // will already have been removed internally.
3395 } finally {
3396 Binder.restoreCallingIdentity(token);
3397 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 }
3399
3400 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003401 public boolean isCapable(int subId, int capability, int regTech) {
3402 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3404 final long token = Binder.clearCallingIdentity();
3405 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003408 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3410 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003412 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3413 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 } finally {
3415 Binder.restoreCallingIdentity(token);
3416 }
3417 }
3418
3419 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003420 public boolean isAvailable(int subId, int capability, int regTech) {
3421 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003422 final long token = Binder.clearCallingIdentity();
3423 try {
3424 Phone phone = getPhone(subId);
3425 if (phone == null) return false;
3426 return phone.isImsCapabilityAvailable(capability, regTech);
3427 } finally {
3428 Binder.restoreCallingIdentity(token);
3429 }
3430 }
3431
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003432 /**
3433 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3434 * subscription.
3435 * @param subId The subscription to use to check the configuration.
3436 * @param callback The callback that will be used to send the result.
3437 * @param capability The MmTelFeature capability that will be used to send the result.
3438 * @param transportType The transport type of the MmTelFeature capability.
3439 */
3440 @Override
3441 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3442 int transportType) {
3443 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3444 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3445 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3446 "IMS not available on device.");
3447 }
3448 final long token = Binder.clearCallingIdentity();
3449 try {
3450 int slotId = getSlotIndex(subId);
3451 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3452 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3453 + subId + "'");
3454 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3455 }
3456 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3457 transportType, aBoolean -> {
3458 try {
3459 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3460 } catch (RemoteException e) {
3461 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3462 + "running. Ignore");
3463 }
3464 });
3465 } finally {
3466 Binder.restoreCallingIdentity(token);
3467 }
3468 }
3469
shilu366312e2019-12-17 09:28:10 -08003470 /**
3471 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3472 * @param subId The subscription to use to check the configuration.
3473 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 @Override
3475 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003476 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3477 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003478
Brad Ebinger35c841c2018-10-01 10:40:55 -07003479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3480 final long token = Binder.clearCallingIdentity();
3481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003482 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003483 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003484 } catch (ImsException e) {
3485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 } finally {
3487 Binder.restoreCallingIdentity(token);
3488 }
3489 }
3490
3491 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003492 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003494 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003498 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003500 } catch (ImsException e) {
3501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
3505 }
3506
shilu366312e2019-12-17 09:28:10 -08003507 /**
3508 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3509 * @param subId The subscription to use to check the configuration.
3510 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003512 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003513 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3514 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003518 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3519 } catch (ImsException e) {
3520 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
3524 }
3525
3526 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003527 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003529 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003533 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003534 } catch (ImsException e) {
3535 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
3539 }
3540
shilu366312e2019-12-17 09:28:10 -08003541 /**
3542 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3543 * @param subId The subscription to use to check the configuration.
3544 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 @Override
3546 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003547 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3548 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003552 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003554 } catch (ImsException e) {
3555 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
3559 }
3560
3561 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003562 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003564 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003568 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003569 } catch (ImsException e) {
3570 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
shilu366312e2019-12-17 09:28:10 -08003576 /**
3577 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3578 * @param subId The subscription to use to check the configuration.
3579 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 @Override
3581 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003582 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3583 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003587 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003589 } catch (ImsException e) {
3590 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
3594 }
3595
3596 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003597 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003599 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003605 } catch (ImsException e) {
3606 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
3610 }
3611
3612 @Override
3613 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3615 "setVoWiFiNonPersistent");
3616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003619 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003620 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003621 } catch (ImsException e) {
3622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
3626 }
3627
shilu366312e2019-12-17 09:28:10 -08003628 /**
3629 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3630 * @param subId The subscription to use to check the configuration.
3631 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 @Override
3633 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003634 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3635 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003641 } catch (ImsException e) {
3642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
3646 }
3647
3648 @Override
3649 public void setVoWiFiModeSetting(int subId, int mode) {
3650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3651 "setVoWiFiModeSetting");
3652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003657 } catch (ImsException e) {
3658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
3663
3664 @Override
3665 public int getVoWiFiRoamingModeSetting(int subId) {
3666 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003670 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003672 } catch (ImsException e) {
3673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
3677 }
3678
3679 @Override
3680 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3682 "setVoWiFiRoamingModeSetting");
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003686 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003688 } catch (ImsException e) {
3689 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693 }
3694
3695 @Override
3696 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3698 "setRttCapabilityEnabled");
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003702 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3703 } catch (ImsException e) {
3704 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
shilu366312e2019-12-17 09:28:10 -08003710 /**
3711 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3712 * @param subId The subscription to use to check the configuration.
3713 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 @Override
3715 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003716 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3717 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003721 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (ImsException e) {
3724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
3728 }
3729
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003730 @Override
3731 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3732 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003735 if (!isImsAvailableOnDevice()) {
3736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3737 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003738 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003741 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (ImsException e) {
3743 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
3747 }
3748
3749 @Override
3750 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3751 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3752 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3754 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3755 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003756 try {
3757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003759 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003760 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003761 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3762 + "is inactive, ignoring unregister.");
3763 // If the subscription is no longer active, just return, since the callback will already
3764 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
3768 }
3769
allenwtsu99c623b2020-01-03 18:24:23 +08003770
3771 private void checkModifyPhoneStatePermission(int subId, String message) {
3772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3773 message);
3774 }
3775
3776 private boolean isImsProvisioningRequired(int subId, int capability,
3777 boolean isMmtelCapability) {
3778 Phone phone = getPhone(subId);
3779 if (phone == null) {
3780 loge("phone instance null for subid " + subId);
3781 return false;
3782 }
3783 if (isMmtelCapability) {
3784 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3785 return false;
3786 }
3787 } else {
3788 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3789 return false;
3790 }
3791 }
3792 return true;
3793 }
3794
3795 @Override
3796 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3797 boolean isProvisioned) {
3798 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3799
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3803 if (!isImsProvisioningRequired(subId, capability, false)) {
3804 return;
3805 }
3806
3807 // this capability requires provisioning, route to the correct API.
3808 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3809 switch (capability) {
3810 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3811 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3812 ims.setEabProvisioned(isProvisioned);
3813 break;
3814 default: {
3815 throw new IllegalArgumentException("Tried to set provisioning for "
3816 + "rcs capability '" + capability + "', which does not require "
3817 + "provisioning.");
3818 }
3819 }
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
3823
3824 }
3825
3826
3827 @Override
3828 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3829 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3833 if (!isImsProvisioningRequired(subId, capability, false)) {
3834 return true;
3835 }
3836
3837 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3838 switch (capability) {
3839 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3840 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3841 return ims.isEabProvisionedOnDevice();
3842
3843 default: {
3844 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3845 + "capability '" + capability + "', which does not require "
3846 + "provisioning.");
3847 }
3848 }
3849
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
3852 }
3853 }
3854
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003855 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003856 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3857 boolean isProvisioned) {
3858 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3859 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3860 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3861 }
allenwtsu99c623b2020-01-03 18:24:23 +08003862 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003866 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003867 return;
3868 }
3869
3870 // this capability requires provisioning, route to the correct API.
3871 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3872 switch (capability) {
3873 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3874 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3875 ims.setVolteProvisioned(isProvisioned);
3876 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3877 ims.setWfcProvisioned(isProvisioned);
3878 }
3879 break;
3880 }
3881 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3882 // There is currently no difference in VT provisioning type.
3883 ims.setVtProvisioned(isProvisioned);
3884 break;
3885 }
3886 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3887 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3888 // change the capability of the feature instead if needed.
3889 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3890 == isProvisioned) {
3891 // No change in provisioning.
3892 return;
3893 }
3894 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3895 try {
3896 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003897 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003898 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3899 + ", Exception" + e.getMessage());
3900 }
3901 break;
3902 }
3903 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003904 throw new IllegalArgumentException("Tried to set provisioning for "
3905 + "MmTel capability '" + capability + "', which does not require "
3906 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 }
3908 }
3909
3910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
3913 }
3914
3915 @Override
3916 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3917 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3918 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3919 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3920 }
3921 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003925 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003926 return true;
3927 }
3928
3929 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3930 switch (capability) {
3931 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3932 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3933 return ims.isVolteProvisionedOnDevice();
3934 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3935 return ims.isWfcProvisionedOnDevice();
3936 }
3937 // This should never happen, since we are checking tech above to make sure it
3938 // is either LTE or IWLAN.
3939 throw new IllegalArgumentException("Invalid radio technology for voice "
3940 + "capability.");
3941 }
3942 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3943 // There is currently no difference in VT provisioning type.
3944 return ims.isVtProvisionedOnDevice();
3945 }
3946 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3947 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3948 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3949 }
3950 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003951 throw new IllegalArgumentException(
3952 "Tried to get provisioning for MmTel capability '" + capability
3953 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003954 }
3955 }
3956
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
3960 }
3961
3962 @Override
3963 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3964 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3965 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3966 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3967 }
3968 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3969 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3970 return (provisionedBits & capability) > 0;
3971 }
3972
3973 @Override
3974 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3975 boolean isProvisioned) {
3976 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3977 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3978 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3979 }
3980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3981 "setProvisioningStatusForCapability");
3982 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3983 // If the current provisioning status for capability already matches isProvisioned,
3984 // do nothing.
3985 if (((provisionedBits & capability) > 0) == isProvisioned) {
3986 return;
3987 }
3988 if (isProvisioned) {
3989 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3990 } else {
3991 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3992 }
3993 }
3994
3995 /**
3996 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3997 * technology. The bitfield should mirror the bitfield defined by
3998 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3999 */
4000 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4001 String key = getMmTelProvisioningKey(subId, tech);
4002 // Default is no capabilities are provisioned.
4003 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4004 }
4005
4006 /**
4007 * Sets the MmTel capability provisioning bitfield (defined by
4008 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4009 * technology specified.
4010 *
4011 * Note: This is a synchronous command and should not be called on UI thread.
4012 */
4013 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4014 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4015 String key = getMmTelProvisioningKey(subId, tech);
4016 editor.putInt(key, newField);
4017 editor.commit();
4018 }
4019
4020 private static String getMmTelProvisioningKey(int subId, int tech) {
4021 // resulting key is provision_ims_mmtel_{subId}_{tech}
4022 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4023 }
4024
4025 /**
4026 * Query CarrierConfig to see if the specified capability requires provisioning for the
4027 * carrier associated with the subscription id.
4028 */
4029 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4030 int capability) {
4031 CarrierConfigManager configManager = new CarrierConfigManager(context);
4032 PersistableBundle c = configManager.getConfigForSubId(subId);
4033 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004034 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004035 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4036 false);
4037 boolean requireVoiceVtProvisioning = c.getBoolean(
4038 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4039
4040 // First check to make sure that the capability requires provisioning.
4041 switch (capability) {
4042 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4043 // intentional fallthrough
4044 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4045 if (requireVoiceVtProvisioning) {
4046 // Voice and Video requires provisioning
4047 return true;
4048 }
4049 break;
4050 }
4051 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4052 if (requireUtProvisioning) {
4053 // UT requires provisioning
4054 return true;
4055 }
4056 break;
4057 }
4058 }
4059 return false;
4060 }
4061
allenwtsu99c623b2020-01-03 18:24:23 +08004062 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4063 int capability) {
4064 CarrierConfigManager configManager = new CarrierConfigManager(context);
4065 PersistableBundle c = configManager.getConfigForSubId(subId);
4066
4067 boolean requireRcsProvisioning = c.getBoolean(
4068 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4069
4070 // First check to make sure that the capability requires provisioning.
4071 switch (capability) {
4072 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4073 // intentional fallthrough
4074 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4075 if (requireRcsProvisioning) {
4076 // OPTION or PRESENCE requires provisioning
4077 return true;
4078 }
4079 break;
4080 }
4081 }
4082 return false;
4083 }
4084
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004085 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004086 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004087 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4088 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4089 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004090 enforceReadPrivilegedPermission("getImsProvisioningInt");
4091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004094 int slotId = getSlotIndex(subId);
4095 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4096 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4097 + subId + "' for key:" + key);
4098 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4099 }
4100 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004102 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4103 + subId + "' for key:" + key);
4104 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
4108 }
4109
4110 @Override
4111 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004112 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4113 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4114 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004115 enforceReadPrivilegedPermission("getImsProvisioningString");
4116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 int slotId = getSlotIndex(subId);
4120 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4121 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4122 + subId + "' for key:" + key);
4123 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4124 }
4125 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004127 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4128 + subId + "' for key:" + key);
4129 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
4133 }
4134
4135 @Override
4136 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4138 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4139 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4141 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004145 int slotId = getSlotIndex(subId);
4146 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4147 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4148 + subId + "' for key:" + key);
4149 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4150 }
4151 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004152 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004153 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4154 + "' for key:" + key);
4155 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
4159 }
4160
4161 @Override
4162 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004163 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4164 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4165 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4167 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004168 final long identity = Binder.clearCallingIdentity();
4169 try {
4170 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004171 int slotId = getSlotIndex(subId);
4172 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4173 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4174 + subId + "' for key:" + key);
4175 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4176 }
4177 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004178 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004179 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4180 + "' for key:" + key);
4181 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
4185 }
4186
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 int slotId = SubscriptionManager.getSlotIndex(subId);
4189 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004190 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4191 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 }
4193 return slotId;
4194 }
4195
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004196 private int getSlotIndex(int subId) {
4197 int slotId = SubscriptionManager.getSlotIndex(subId);
4198 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4199 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4200 }
4201 return slotId;
4202 }
4203
Wink Saville36469e72014-06-11 15:17:00 -07004204 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004205 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004206 */
4207 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004208 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4209 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004210 final int targetSdk = getTargetSdk(callingPackage);
4211 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004212 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004213 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004214 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004215 mApp, subId, callingPackage, callingFeatureId,
4216 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4218 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 final Phone phone = getPhone(subId);
4223 if (phone != null) {
4224 return phone.getServiceState().getDataNetworkType();
4225 } else {
4226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4227 }
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004231 }
4232
4233 /**
4234 * Returns the data network type
4235 */
4236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004237 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4238 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4239 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004240 }
4241
4242 /**
4243 * Returns the data network type for a subId
4244 */
4245 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004246 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4247 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004249 mApp, subId, callingPackage, callingFeatureId,
4250 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4252 }
4253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 final Phone phone = getPhone(subId);
4257 if (phone != null) {
4258 return phone.getServiceState().getDataNetworkType();
4259 } else {
4260 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4261 }
4262 } finally {
4263 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004265 }
4266
4267 /**
Wink Saville36469e72014-06-11 15:17:00 -07004268 * Returns the Voice network type for a subId
4269 */
4270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4272 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004274 mApp, subId, callingPackage, callingFeatureId,
4275 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004276 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4277 }
4278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 final Phone phone = getPhone(subId);
4282 if (phone != null) {
4283 return phone.getServiceState().getVoiceNetworkType();
4284 } else {
4285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4286 }
4287 } finally {
4288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004290 }
4291
4292 /**
4293 * @return true if a ICC card is present
4294 */
4295 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004296 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004297 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4298 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004299 }
4300
4301 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004302 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004303 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004304 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004305 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 final Phone phone = PhoneFactory.getPhone(slotIndex);
4309 if (phone != null) {
4310 return phone.getIccCard().hasIccCard();
4311 } else {
4312 return false;
4313 }
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004317 }
4318
4319 /**
4320 * Return if the current radio is LTE on CDMA. This
4321 * is a tri-state return value as for a period of time
4322 * the mode may be unknown.
4323 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004324 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004325 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004326 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004327 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004329 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4330 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4331 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004332 }
4333
Sanket Padawe356d7632015-06-22 14:03:32 -07004334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004335 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4336 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004337 try {
4338 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4339 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004340 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4341 }
4342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 final Phone phone = getPhone(subId);
4346 if (phone == null) {
4347 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4348 } else {
4349 return phone.getLteOnCdmaMode();
4350 }
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004353 }
Wink Saville36469e72014-06-11 15:17:00 -07004354 }
4355
Wink Saville36469e72014-06-11 15:17:00 -07004356 /**
4357 * {@hide}
4358 * Returns Default subId, 0 in the case of single standby.
4359 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004360 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004361 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004362 }
4363
Shishir Agrawala9f32182016-04-12 12:00:16 -07004364 private int getSlotForDefaultSubscription() {
4365 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4366 }
4367
Wink Savilleb564aae2014-10-23 10:18:09 -07004368 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004369 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004370 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004371
Pengquan Menge92a50d2018-09-21 15:54:48 -07004372 private boolean isActiveSubscription(int subId) {
4373 return mSubscriptionController.isActiveSubId(subId);
4374 }
4375
Ihab Awadf2177b72013-11-25 13:33:23 -08004376 /**
4377 * @see android.telephony.TelephonyManager.WifiCallingChoices
4378 */
4379 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 final long identity = Binder.clearCallingIdentity();
4381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004382 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4384 getWhenToMakeWifiCallsDefaultPreference());
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004388 }
4389
4390 /**
4391 * @see android.telephony.TelephonyManager.WifiCallingChoices
4392 */
4393 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004397 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004402 }
4403
Sailesh Nepald1e68152013-12-12 19:08:02 -08004404 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004405 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004406 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004407 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004408
Jordan Liu4c733742019-02-28 12:03:40 -08004409 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4410 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4411 if (phoneId == -1) {
4412 throw new IllegalArgumentException("Given slot index: " + slotIndex
4413 + " does not correspond to an active phone");
4414 }
4415 return PhoneFactory.getPhone(phoneId);
4416 }
4417
Shishir Agrawal566b7612013-10-28 14:41:00 -07004418 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004419 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4420 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4422 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004424 if (DBG) {
4425 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4426 }
4427 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4428 p2);
4429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004430
Jordan Liu4c733742019-02-28 12:03:40 -08004431
4432 @Override
4433 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4434 int slotIndex, String callingPackage, String aid, int p2) {
4435 enforceModifyPermission();
4436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4437 if (DBG) {
4438 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4439 }
4440 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4441 callingPackage, aid, p2);
4442 }
4443
4444 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4445 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 if (TextUtils.equals(ISDR_AID, aid)) {
4449 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004450 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4451 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 if (bestComponent == null
4453 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4454 loge("The calling package is not allowed to access ISD-R.");
4455 throw new SecurityException(
4456 "The calling package is not allowed to access ISD-R.");
4457 }
Derek Tan740e1672017-06-27 14:56:27 -07004458 }
Derek Tan740e1672017-06-27 14:56:27 -07004459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004461 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4462 null /* workSource */);
4463 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 return response;
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004468 }
4469
4470 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004471 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4473 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004474 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4475 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004477
Jordan Liu4c733742019-02-28 12:03:40 -08004478 @Override
4479 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4480 enforceModifyPermission();
4481 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4482 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4483 channel);
4484 }
4485
4486 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 final long identity = Binder.clearCallingIdentity();
4488 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 if (channel < 0) {
4490 return false;
4491 }
Jordan Liu4c733742019-02-28 12:03:40 -08004492 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4493 null /* workSource */);
4494 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 return success;
4496 } finally {
4497 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004498 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004499 }
4500
4501 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004502 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004503 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4505 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004506 if (DBG) {
4507 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4508 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4509 + p3 + " data=" + data);
4510 }
4511 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4512 command, p1, p2, p3, data);
4513 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004514
Jordan Liu4c733742019-02-28 12:03:40 -08004515 @Override
4516 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4517 int command, int p1, int p2, int p3, String data) {
4518 enforceModifyPermission();
4519 if (DBG) {
4520 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4521 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4522 + p3 + " data=" + data);
4523 }
4524 return iccTransmitApduLogicalChannelWithPermission(
4525 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4526 data);
4527 }
4528
4529 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4530 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004533 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 return "";
4535 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004538 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4539 null /* workSource */);
4540 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004542 // Append the returned status code to the end of the response payload.
4543 String s = Integer.toHexString(
4544 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4545 if (response.payload != null) {
4546 s = IccUtils.bytesToHexString(response.payload) + s;
4547 }
4548 return s;
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004552 }
Jake Hambye994d462014-02-03 13:10:13 -08004553
Evan Charltonc66da362014-05-16 14:06:40 -07004554 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004555 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4556 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4558 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004560 if (DBG) {
4561 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4562 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4563 }
4564 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4565 cla, command, p1, p2, p3, data);
4566 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004567
Jordan Liu4c733742019-02-28 12:03:40 -08004568 @Override
4569 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4570 int command, int p1, int p2, int p3, String data) {
4571 enforceModifyPermission();
4572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4573 if (DBG) {
4574 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4575 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4576 + " data=" + data);
4577 }
4578
4579 return iccTransmitApduBasicChannelWithPermission(
4580 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4581 p2, p3, data);
4582 }
4583
4584 // open APDU basic channel assuming the caller has sufficient permissions
4585 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4586 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4590 && TextUtils.equals(ISDR_AID, data)) {
4591 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004592 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4593 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 if (bestComponent == null
4595 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4596 loge("The calling package is not allowed to select ISD-R.");
4597 throw new SecurityException(
4598 "The calling package is not allowed to select ISD-R.");
4599 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004600 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004603 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4604 null /* workSource */);
4605 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 // Append the returned status code to the end of the response payload.
4608 String s = Integer.toHexString(
4609 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4610 if (response.payload != null) {
4611 s = IccUtils.bytesToHexString(response.payload) + s;
4612 }
4613 return s;
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004616 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004617 }
4618
4619 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004620 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004621 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4623 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 if (DBG) {
4628 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4629 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4630 }
4631
4632 IccIoResult response =
4633 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4634 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4635 subId);
4636
4637 if (DBG) {
4638 log("Exchange SIM_IO [R]" + response);
4639 }
4640
4641 byte[] result = null;
4642 int length = 2;
4643 if (response.payload != null) {
4644 length = 2 + response.payload.length;
4645 result = new byte[length];
4646 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4647 } else {
4648 result = new byte[length];
4649 }
4650
4651 result[length - 1] = (byte) response.sw2;
4652 result[length - 2] = (byte) response.sw1;
4653 return result;
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004656 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004657 }
4658
Nathan Haroldb3014052017-01-25 15:57:32 -08004659 /**
4660 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4661 * on a particular subscription
4662 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004663 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4664 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004666 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004667 return null;
4668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669
4670 final long identity = Binder.clearCallingIdentity();
4671 try {
4672 if (appType != TelephonyManager.APPTYPE_USIM
4673 && appType != TelephonyManager.APPTYPE_SIM) {
4674 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4675 return null;
4676 }
4677 Object response = sendRequest(
4678 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4679 if (response instanceof String[]) {
4680 return (String[]) response;
4681 }
yincheng zhao2737e882019-09-06 17:06:54 -07004682 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004684 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 } finally {
4686 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004687 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004688 }
4689
yincheng zhao2737e882019-09-06 17:06:54 -07004690 /**
4691 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4692 * subscription.
4693 *
4694 * @param subId the id of the subscription.
4695 * @param appType the uicc app type, must be USIM or SIM.
4696 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4697 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004698 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004699 * @return number of fplmns that is successfully written to the SIM.
4700 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004701 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4702 String callingFeatureId) {
4703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4704 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004705 if (DBG) logv("no permissions for setForbiddenplmns");
4706 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4707 }
4708 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4709 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4710 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4711 }
4712 if (fplmns == null) {
4713 throw new IllegalArgumentException("Fplmn List provided is null");
4714 }
4715 for (String fplmn : fplmns) {
4716 if (!CellIdentity.isValidPlmn(fplmn)) {
4717 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4718 }
4719 }
4720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 Object response = sendRequest(
4723 CMD_SET_FORBIDDEN_PLMNS,
4724 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4725 subId);
4726 return (int) response;
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
4730 }
4731
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004732 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004733 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4740 if (response.payload == null) {
4741 return "";
4742 }
Evan Charltonc66da362014-05-16 14:06:40 -07004743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 // Append the returned status code to the end of the response payload.
4745 String s = Integer.toHexString(
4746 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4747 s = IccUtils.bytesToHexString(response.payload) + s;
4748 return s;
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
Evan Charltonc66da362014-05-16 14:06:40 -07004752 }
4753
Jake Hambye994d462014-02-03 13:10:13 -08004754 /**
4755 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4756 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4757 *
4758 * @param itemID the ID of the item to read
4759 * @return the NV item as a String, or null on error.
4760 */
4761 @Override
4762 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004763 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4765 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766
4767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004770 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4772 return value;
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
Jake Hambye994d462014-02-03 13:10:13 -08004776 }
4777
4778 /**
4779 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4780 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4781 *
4782 * @param itemID the ID of the item to read
4783 * @param itemValue the value to write, as a String
4784 * @return true on success; false on any failure
4785 */
4786 @Override
4787 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004788 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4790 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791
4792 final long identity = Binder.clearCallingIdentity();
4793 try {
4794 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4795 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004796 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4798 return success;
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Jake Hambye994d462014-02-03 13:10:13 -08004802 }
4803
4804 /**
4805 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4806 * Used for device configuration by some CDMA operators.
4807 *
4808 * @param preferredRoamingList byte array containing the new PRL
4809 * @return true on success; false on any failure
4810 */
4811 @Override
4812 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4814 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815
4816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4819 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4820 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4821 return success;
4822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
Jake Hambye994d462014-02-03 13:10:13 -08004825 }
4826
4827 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004828 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004829 * Used for device configuration by some CDMA operators.
4830 *
chen xu6dac5ab2018-10-26 17:39:23 -07004831 * @param slotIndex - device slot.
4832 *
Jake Hambye994d462014-02-03 13:10:13 -08004833 * @return true on success; false on any failure
4834 */
4835 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004836 public boolean resetModemConfig(int slotIndex) {
4837 Phone phone = PhoneFactory.getPhone(slotIndex);
4838 if (phone != null) {
4839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4840 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841
chen xu6dac5ab2018-10-26 17:39:23 -07004842 final long identity = Binder.clearCallingIdentity();
4843 try {
4844 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4845 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4846 return success;
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
4849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 }
chen xu6dac5ab2018-10-26 17:39:23 -07004851 return false;
4852 }
4853
4854 /**
4855 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4856 *
4857 * @param slotIndex - device slot.
4858 *
4859 * @return true on success; false on any failure
4860 */
4861 @Override
4862 public boolean rebootModem(int slotIndex) {
4863 Phone phone = PhoneFactory.getPhone(slotIndex);
4864 if (phone != null) {
4865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4866 mApp, phone.getSubId(), "rebootModem");
4867
4868 final long identity = Binder.clearCallingIdentity();
4869 try {
4870 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4871 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4872 return success;
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
4876 }
4877 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004878 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004879
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004880 public String[] getPcscfAddress(String apnType, String callingPackage,
4881 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4884 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004885 return new String[0];
4886 }
4887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004890 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 } finally {
4892 Binder.restoreCallingIdentity(identity);
4893 }
Wink Saville36469e72014-06-11 15:17:00 -07004894 }
4895
Brad Ebinger51f743a2017-01-23 13:50:20 -08004896 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004897 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4898 * {@link #disableIms(int)}.
4899 * @param slotIndex device slot.
4900 */
4901 public void resetIms(int slotIndex) {
4902 enforceModifyPermission();
4903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 if (mImsResolver == null) {
4907 // may happen if the does not support IMS.
4908 return;
4909 }
4910 mImsResolver.disableIms(slotIndex);
4911 mImsResolver.enableIms(slotIndex);
4912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
4915 }
4916
4917 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004918 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4919 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004920 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004921 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004922 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004926 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004927 // may happen if the device does not support IMS.
4928 return;
4929 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004930 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004934 }
4935
4936 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004937 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4938 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004939 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004940 public void disableIms(int slotId) {
4941 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942
4943 final long identity = Binder.clearCallingIdentity();
4944 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004945 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004946 // may happen if the device does not support IMS.
4947 return;
4948 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004949 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004953 }
4954
4955 /**
4956 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4957 * feature or {@link null} if the service is not available. If the feature is available, the
4958 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4959 */
4960 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004961 IImsServiceFeatureCallback callback) {
4962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963
4964 final long identity = Binder.clearCallingIdentity();
4965 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004966 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004967 // may happen if the device does not support IMS.
4968 return null;
4969 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004970 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004974 }
4975
4976 /**
4977 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4978 * feature during emergency calling or {@link null} if the service is not available. If the
4979 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4980 * listener for feature updates.
4981 */
4982 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4983 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984
4985 final long identity = Binder.clearCallingIdentity();
4986 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004987 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004988 // may happen if the device does not support IMS.
4989 return null;
4990 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004991 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004995 }
4996
Brad Ebinger5f64b052017-12-14 14:26:15 -08004997 /**
4998 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004999 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005000 */
5001 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
5004 final long identity = Binder.clearCallingIdentity();
5005 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005006 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005007 // may happen if the device does not support IMS.
5008 return null;
5009 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005010 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005014 }
5015
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005016 /**
5017 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005018 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005019 */
5020 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005025 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005026 // may happen if the device does not support IMS.
5027 return null;
5028 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005029 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005033 }
5034
Brad Ebinger884c07b2018-02-15 16:17:40 -08005035 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005036 * Sets the ImsService Package Name that Telephony will bind to.
5037 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005038 * @param slotIndex the slot ID that the ImsService should bind for.
5039 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005040 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005041 * @param featureTypes An integer array of feature types associated with a packageName.
5042 * @param packageName The name of the package that the current configuration will be replaced
5043 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005044 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005045 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005046 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5047 int[] featureTypes, String packageName) {
5048 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5051 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005052 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005056 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005057 // may happen if the device does not support IMS.
5058 return false;
5059 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005060 Map<Integer, String> featureConfig = new HashMap<>();
5061 for (int featureType : featureTypes) {
5062 featureConfig.put(featureType, packageName);
5063 }
5064 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5065 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005069 }
5070
5071 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005072 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005073 *
5074 * @param slotId The slot that the ImsService is associated with.
5075 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5076 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005077 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005078 * @return the package name of the ImsService configuration.
5079 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005080 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5081 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005082 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005083 TelephonyPermissions
5084 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5085 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5086 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 final long identity = Binder.clearCallingIdentity();
5089 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005090 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005091 // may happen if the device does not support IMS.
5092 return "";
5093 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005094 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005095 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5096 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 } finally {
5098 Binder.restoreCallingIdentity(identity);
5099 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005100 }
5101
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005102 /**
5103 * Get the MmTelFeature state associated with the requested subscription id.
5104 * @param subId The subscription that the MmTelFeature is associated with.
5105 * @param callback A callback with an integer containing the
5106 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5107 */
5108 @Override
5109 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5110 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5111 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5112 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5113 "IMS not available on device.");
5114 }
5115 final long token = Binder.clearCallingIdentity();
5116 try {
5117 int slotId = getSlotIndex(subId);
5118 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5119 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5120 + subId + "'");
5121 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5122 }
5123 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5124 try {
5125 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5126 } catch (RemoteException e) {
5127 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5128 + "Ignore");
5129 }
5130 });
5131 } finally {
5132 Binder.restoreCallingIdentity(token);
5133 }
5134 }
5135
Wink Saville36469e72014-06-11 15:17:00 -07005136 public void setImsRegistrationState(boolean registered) {
5137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138
5139 final long identity = Binder.clearCallingIdentity();
5140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005141 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 } finally {
5143 Binder.restoreCallingIdentity(identity);
5144 }
Wink Saville36469e72014-06-11 15:17:00 -07005145 }
5146
5147 /**
Stuart Scott54788802015-03-30 13:18:01 -07005148 * Set the network selection mode to automatic.
5149 *
5150 */
5151 @Override
5152 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5154 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155
5156 final long identity = Binder.clearCallingIdentity();
5157 try {
shilufc958392020-01-20 11:36:01 -08005158 if (!isActiveSubscription(subId)) {
5159 return;
5160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5162 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
Stuart Scott54788802015-03-30 13:18:01 -07005166 }
5167
Pengquan Mengea84e042018-09-20 14:57:26 -07005168 /**
5169 * Ask the radio to connect to the input network and change selection mode to manual.
5170 *
5171 * @param subId the id of the subscription.
5172 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5173 * the operator to attach to.
5174 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5175 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5176 * normal network selection next time.
5177 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005178 */
5179 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005180 public boolean setNetworkSelectionModeManual(
5181 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5183 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005184
5185 if (!isActiveSubscription(subId)) {
5186 return false;
5187 }
5188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 final long identity = Binder.clearCallingIdentity();
5190 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005191 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005193 if (DBG) {
5194 log("setNetworkSelectionModeManual: subId: " + subId
5195 + " operator: " + operatorInfo);
5196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005201 }
shilu84f6e8b2019-12-19 13:58:01 -08005202 /**
5203 * Get the manual network selection
5204 *
5205 * @param subId the id of the subscription.
5206 *
5207 * @return the previously saved user selected PLMN
5208 */
5209 @Override
5210 public String getManualNetworkSelectionPlmn(int subId) {
5211 TelephonyPermissions
5212 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5213 mApp, subId, "getManualNetworkSelectionPlmn");
5214
5215 final long identity = Binder.clearCallingIdentity();
5216 try {
5217 if (!isActiveSubscription(subId)) {
5218 return "";
5219 }
5220
5221 final Phone phone = getPhone(subId);
5222 if (phone == null) {
5223 return "";
5224 }
5225 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5226 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5227 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
5231 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005232
5233 /**
5234 * Scans for available networks.
5235 */
5236 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005237 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5238 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5240 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005241 LocationAccessPolicy.LocationPermissionResult locationResult =
5242 LocationAccessPolicy.checkLocationPermission(mApp,
5243 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5244 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005245 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005246 .setCallingPid(Binder.getCallingPid())
5247 .setCallingUid(Binder.getCallingUid())
5248 .setMethod("getCellNetworkScanResults")
5249 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5250 .build());
5251 switch (locationResult) {
5252 case DENIED_HARD:
5253 throw new SecurityException("Not allowed to access scan results -- location");
5254 case DENIED_SOFT:
5255 return null;
5256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257
Pengquan Menga1bb6272018-09-06 09:59:22 -07005258 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 try {
5260 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005261 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005266 }
5267
5268 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005269 * Get the call forwarding info, given the call forwarding reason.
5270 */
5271 @Override
5272 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5273 enforceReadPrivilegedPermission("getCallForwarding");
5274 long identity = Binder.clearCallingIdentity();
5275 try {
5276 if (DBG) {
5277 log("getCallForwarding: subId " + subId
5278 + " callForwardingReason" + callForwardingReason);
5279 }
5280 return (CallForwardingInfo) sendRequest(
5281 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
5285 }
5286
5287 /**
5288 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5289 * reason, the number to forward, and the timeout before the forwarding is attempted.
5290 */
5291 @Override
5292 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5293 enforceModifyPermission();
5294 long identity = Binder.clearCallingIdentity();
5295 try {
5296 if (DBG) {
5297 log("setCallForwarding: subId " + subId
5298 + " callForwardingInfo" + callForwardingInfo);
5299 }
5300 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
5304 }
5305
5306 /**
5307 * Get the call forwarding info, given the call forwarding reason.
5308 */
5309 @Override
5310 public int getCallWaitingStatus(int subId) {
5311 enforceReadPrivilegedPermission("getCallForwarding");
5312 long identity = Binder.clearCallingIdentity();
5313 try {
5314 if (DBG) log("getCallWaitingStatus: subId " + subId);
5315 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 /**
5322 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5323 * reason, the number to forward, and the timeout before the forwarding is attempted.
5324 */
5325 @Override
5326 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5327 enforceModifyPermission();
5328 long identity = Binder.clearCallingIdentity();
5329 try {
5330 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5331 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
5335 }
5336
5337 /**
yinxub1bed742017-04-17 11:45:04 -07005338 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005339 *
yinxub1bed742017-04-17 11:45:04 -07005340 * @param subId id of the subscription
5341 * @param request contains the radio access networks with bands/channels to scan
5342 * @param messenger callback messenger for scan results or errors
5343 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005344 * @return the id of the requested scan which can be used to stop the scan.
5345 */
5346 @Override
5347 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005348 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005351 LocationAccessPolicy.LocationPermissionResult locationResult =
5352 LocationAccessPolicy.checkLocationPermission(mApp,
5353 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5354 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005355 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005356 .setCallingPid(Binder.getCallingPid())
5357 .setCallingUid(Binder.getCallingUid())
5358 .setMethod("requestNetworkScan")
5359 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5360 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005361 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005362 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005363 if (e != null) {
5364 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5365 throw e;
5366 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005367 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005368 return TelephonyScanManager.INVALID_SCAN_ID;
5369 }
5370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 }
Hall Liu912dfd32019-04-25 14:02:26 -07005372 int callingUid = Binder.getCallingUid();
5373 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005374 final long identity = Binder.clearCallingIdentity();
5375 try {
5376 return mNetworkScanRequestTracker.startNetworkScan(
5377 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005378 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005379 } finally {
5380 Binder.restoreCallingIdentity(identity);
5381 }
yinxu504e1392017-04-12 16:03:22 -07005382 }
5383
Hall Liub2ac8ef2019-02-28 15:56:23 -08005384 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005385 NetworkScanRequest request, int subId) {
5386 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5387 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5388 boolean hasNetworkScanPermission =
5389 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5390 == PERMISSION_GRANTED;
5391
5392 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5393 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5394 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005395 }
5396
5397 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5398 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005399 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5400 return new SecurityException("Specific channels must not be"
5401 + " scanned without location access.");
5402 }
5403 }
5404 }
5405
Hall Liub2ac8ef2019-02-28 15:56:23 -08005406 return null;
5407 }
5408
yinxu504e1392017-04-12 16:03:22 -07005409 /**
5410 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005411 *
5412 * @param subId id of the subscription
5413 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005414 */
5415 @Override
5416 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5418 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419
Hall Liu912dfd32019-04-25 14:02:26 -07005420 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 final long identity = Binder.clearCallingIdentity();
5422 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005423 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
yinxu504e1392017-04-12 16:03:22 -07005427 }
5428
5429 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005430 * Get the calculated preferred network type.
5431 * Used for debugging incorrect network type.
5432 *
5433 * @return the preferred network type, defined in RILConstants.java.
5434 */
5435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005436 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005437 final Phone defaultPhone = getDefaultPhone();
5438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005439 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005440 return RILConstants.PREFERRED_NETWORK_MODE;
5441 }
5442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005446 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
Junda Liu84d15a22014-07-02 11:21:04 -07005450 }
5451
5452 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005453 * Get the preferred network type.
5454 * Used for device configuration by some CDMA operators.
5455 *
5456 * @return the preferred network type, defined in RILConstants.java.
5457 */
5458 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005459 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005460 TelephonyPermissions
5461 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5462 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463
5464 final long identity = Binder.clearCallingIdentity();
5465 try {
5466 if (DBG) log("getPreferredNetworkType");
5467 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5468 int networkType = (result != null ? result[0] : -1);
5469 if (DBG) log("getPreferredNetworkType: " + networkType);
5470 return networkType;
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005474 }
5475
5476 /**
5477 * Set the preferred network type.
5478 * Used for device configuration by some CDMA operators.
5479 *
5480 * @param networkType the preferred network type, defined in RILConstants.java.
5481 * @return true on success; false on any failure.
5482 */
5483 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005484 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5486 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005490 Settings.Global.putInt(mApp.getContentResolver(),
5491 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5492 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005495 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005496 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005497
5498 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005499 * Get the allowed network types that store in the telephony provider.
5500 *
5501 * @param subId the id of the subscription.
5502 * @return allowedNetworkTypes the allowed network types.
5503 */
5504 @Override
5505 public long getAllowedNetworkTypes(int subId) {
5506 TelephonyPermissions
5507 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5508 mApp, subId, "getAllowedNetworkTypes");
5509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 return SubscriptionManager.getLongSubscriptionProperty(
5513 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
5517 }
5518
5519 /**
5520 * Set the allowed network types.
5521 *
5522 * @param subId the id of the subscription.
5523 * @param allowedNetworkTypes the allowed network types.
5524 * @return true on success; false on any failure.
5525 */
5526 @Override
5527 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, subId, "setAllowedNetworkTypes");
5530 final long identity = Binder.clearCallingIdentity();
5531 try {
5532 SubscriptionManager.setSubscriptionProperty(subId,
5533 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5534 String.valueOf(allowedNetworkTypes));
5535 return setPreferredNetworkTypesInternal(subId);
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
5539 }
5540
5541 private boolean setPreferredNetworkTypesInternal(int subId) {
5542 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5543 Settings.Global.getInt(mApp.getContentResolver(),
5544 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5545 RILConstants.PREFERRED_NETWORK_MODE));
5546 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5547 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5548 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5549 (int) (networkTypeBitMask & allowedNetworkTypes));
5550
5551 if (DBG) {
5552 log("setPreferredNetworkTypesInternal: subId " + subId
5553 + " networkTypes " + networkTypeBitMask
5554 + " allowedNetworkTypes " + allowedNetworkTypes
5555 + " networkMode " + networkMode);
5556 }
5557
5558 Boolean success = (Boolean) sendRequest(
5559 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5560 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5561 return success;
5562 }
5563
5564 /**
Miaoa84611c2019-03-15 09:21:10 +08005565 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005566 *
Miaoa84611c2019-03-15 09:21:10 +08005567 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005568 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005569 * @hide
5570 */
5571 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005572 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005575 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 try {
Miaoa84611c2019-03-15 09:21:10 +08005577 if (phone != null) {
5578 return phone.hasMatchedTetherApnSetting();
5579 } else {
5580 return false;
5581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005584 }
Junda Liu475951f2014-11-07 16:45:03 -08005585 }
5586
5587 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005588 * Set mobile data enabled
5589 * Used by the user through settings etc to turn on/off mobile data
5590 *
5591 * @param enable {@code true} turn turn data on, else {@code false}
5592 */
5593 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005594 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5596 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 int phoneId = mSubscriptionController.getPhoneId(subId);
5601 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5602 Phone phone = PhoneFactory.getPhone(phoneId);
5603 if (phone != null) {
5604 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005605 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005607 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 }
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005611 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005612 }
5613
5614 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005615 * Enable or disable always reporting signal strength changes from radio.
5616 *
5617 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5618 */
5619 @Override
5620 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5621 enforceModifyPermission();
5622 enforceSystemCaller();
5623
5624 final long identity = Binder.clearCallingIdentity();
5625 final Phone phone = getPhone(subId);
5626 try {
5627 if (phone != null) {
5628 if (DBG) {
5629 log("setAlwaysReportSignalStrength: subId=" + subId
5630 + " isEnable=" + isEnable);
5631 }
5632 phone.setAlwaysReportSignalStrength(isEnable);
5633 } else {
5634 loge("setAlwaysReportSignalStrength: no phone found for subId="
5635 + subId);
5636 }
5637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
5640 }
5641
5642 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005643 * Get the user enabled state of Mobile Data.
5644 *
5645 * TODO: remove and use isUserDataEnabled.
5646 * This can't be removed now because some vendor codes
5647 * calls through ITelephony directly while they should
5648 * use TelephonyManager.
5649 *
5650 * @return true on enabled
5651 */
5652 @Override
5653 public boolean getDataEnabled(int subId) {
5654 return isUserDataEnabled(subId);
5655 }
5656
5657 /**
5658 * Get whether mobile data is enabled per user setting.
5659 *
5660 * There are other factors deciding whether mobile data is actually enabled, but they are
5661 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005662 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005663 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005664 *
5665 * @return {@code true} if data is enabled else {@code false}
5666 */
5667 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005668 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005669 try {
5670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5671 null);
5672 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 int phoneId = mSubscriptionController.getPhoneId(subId);
5680 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5681 Phone phone = PhoneFactory.getPhone(phoneId);
5682 if (phone != null) {
5683 boolean retVal = phone.isUserDataEnabled();
5684 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5685 return retVal;
5686 } else {
5687 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5688 return false;
5689 }
5690 } finally {
5691 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005692 }
5693 }
5694
5695 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005696 * Checks if the device is capable of mobile data by considering whether whether the
5697 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5698 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005699 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005700 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005701 */
5702 @Override
5703 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005704 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705
5706 final long identity = Binder.clearCallingIdentity();
5707 try {
5708 int phoneId = mSubscriptionController.getPhoneId(subId);
5709 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5710 Phone phone = PhoneFactory.getPhone(phoneId);
5711 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005712 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5714 return retVal;
5715 } else {
5716 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5717 return false;
5718 }
5719 } finally {
5720 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005721 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005722 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005723
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005724 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5725 Phone phone) {
5726 //load access rules from carrier configs, and check those as well: b/139133814
5727 SubscriptionController subController = SubscriptionController.getInstance();
5728 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5729 || subController == null) return privilegeFromSim;
5730
5731 int uid = Binder.getCallingUid();
5732 PackageManager pkgMgr = phone.getContext().getPackageManager();
5733 String[] packages = pkgMgr.getPackagesForUid(uid);
5734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5738 SubscriptionManager subManager = (SubscriptionManager)
5739 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5740 for (String pkg : packages) {
5741 if (subManager.canManageSubscription(subInfo, pkg)) {
5742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5743 }
5744 }
5745 return privilegeFromSim;
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
5750
5751 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5752 String pkgName) {
5753 //load access rules from carrier configs, and check those as well: b/139133814
5754 SubscriptionController subController = SubscriptionController.getInstance();
5755 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5756 || subController == null) return privilegeFromSim;
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 return subManager.canManageSubscription(subInfo, pkgName)
5764 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
5768 }
5769
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005770 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005771 public int getCarrierPrivilegeStatus(int subId) {
5772 final Phone phone = getPhone(subId);
5773 if (phone == null) {
5774 loge("getCarrierPrivilegeStatus: Invalid subId");
5775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5776 }
5777 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005778 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005779 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5781 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005782
5783 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5784 card.getCarrierPrivilegeStatusForCurrentTransaction(
5785 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005786 }
Junda Liu29340342014-07-10 15:23:27 -07005787
5788 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005789 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005790 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005791 final Phone phone = getPhone(subId);
5792 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005793 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005794 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5795 }
5796 UiccProfile profile =
5797 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5798 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005799 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5801 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005802 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005803 profile.getCarrierPrivilegeStatusForUid(
5804 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005805 }
5806
5807 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005808 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5809 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005810 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005811 }
5812
5813 int phoneId = SubscriptionManager.getPhoneId(subId);
5814 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005815 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005816 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5818 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005819 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5820 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5821 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005822 }
5823
5824 @Override
5825 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005826 if (TextUtils.isEmpty(pkgName))
5827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005828 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5829 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5830 UiccCard card = UiccController.getInstance().getUiccCard(i);
5831 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005832 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005833 continue;
5834 }
5835
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005836 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5837 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5838 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005839 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5840 break;
5841 }
5842 }
5843
5844 return result;
Junda Liu29340342014-07-10 15:23:27 -07005845 }
Derek Tan89e89d42014-07-08 17:00:10 -07005846
5847 @Override
Junda Liue64de782015-04-16 17:19:16 -07005848 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5849 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5850 loge("phoneId " + phoneId + " is not valid.");
5851 return null;
5852 }
5853 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005854 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005855 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005856 return null ;
5857 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005858 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005859 }
5860
Amith Yamasani6e118872016-02-19 12:53:51 -08005861 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005862 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005863 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005864 List<String> privilegedPackages = new ArrayList<>();
5865 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005866 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5867 // has UICC in that slot.
5868 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005869 if (card.hasCarrierPrivilegeRules()) {
5870 if (packages == null) {
5871 // Only check packages in user 0 for now
5872 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005873 PackageManager.MATCH_DISABLED_COMPONENTS
5874 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005875 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005876 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005877 }
5878 for (int p = packages.size() - 1; p >= 0; p--) {
5879 PackageInfo pkgInfo = packages.get(p);
5880 if (pkgInfo != null && pkgInfo.packageName != null
5881 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005882 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005883 privilegedPackages.add(pkgInfo.packageName);
5884 }
5885 }
5886 }
5887 }
5888 return privilegedPackages;
5889 }
5890
chen xuf7e9fe82019-05-09 19:31:02 -07005891 @Override
5892 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005893 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5894
5895 final long identity = Binder.clearCallingIdentity();
5896
chen xuf7e9fe82019-05-09 19:31:02 -07005897 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005898 try {
5899 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5900 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5901 }
5902 } finally {
5903 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005904 }
5905 return privilegedPackages;
5906 }
5907
Wink Savilleb564aae2014-10-23 10:18:09 -07005908 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005909 final Phone phone = getPhone(subId);
5910 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005911 if (card == null) {
5912 loge("getIccId: No UICC");
5913 return null;
5914 }
5915 String iccId = card.getIccId();
5916 if (TextUtils.isEmpty(iccId)) {
5917 loge("getIccId: ICC ID is null or empty.");
5918 return null;
5919 }
5920 return iccId;
5921 }
5922
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005923 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005924 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5925 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 final String iccId = getIccId(subId);
5932 final Phone phone = getPhone(subId);
5933 if (phone == null) {
5934 return false;
5935 }
5936 final String subscriberId = phone.getSubscriberId();
5937
5938 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005939 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 + subscriberId + " to " + number);
5941 }
5942
5943 if (TextUtils.isEmpty(iccId)) {
5944 return false;
5945 }
5946
5947 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5948
5949 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5950 if (alphaTag == null) {
5951 editor.remove(alphaTagPrefKey);
5952 } else {
5953 editor.putString(alphaTagPrefKey, alphaTag);
5954 }
5955
5956 // Record both the line number and IMSI for this ICCID, since we need to
5957 // track all merged IMSIs based on line number
5958 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5959 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5960 if (number == null) {
5961 editor.remove(numberPrefKey);
5962 editor.remove(subscriberPrefKey);
5963 } else {
5964 editor.putString(numberPrefKey, number);
5965 editor.putString(subscriberPrefKey, subscriberId);
5966 }
5967
5968 editor.commit();
5969 return true;
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005972 }
Derek Tan7226c842014-07-02 17:42:23 -07005973 }
5974
5975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005976 public String getLine1NumberForDisplay(int subId, String callingPackage,
5977 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005978 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005980 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005981 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005982 return null;
5983 }
Derek Tan97ebb422014-09-05 16:55:38 -07005984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 final long identity = Binder.clearCallingIdentity();
5986 try {
5987 String iccId = getIccId(subId);
5988 if (iccId != null) {
5989 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5990 if (DBG_MERGE) {
5991 log("getLine1NumberForDisplay returning "
5992 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5993 }
5994 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5997 return null;
5998 } finally {
5999 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006000 }
Derek Tan7226c842014-07-02 17:42:23 -07006001 }
6002
6003 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006004 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6005 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006007 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006008 return null;
6009 }
Derek Tan97ebb422014-09-05 16:55:38 -07006010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 String iccId = getIccId(subId);
6014 if (iccId != null) {
6015 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6016 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6017 }
6018 return null;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006021 }
Derek Tan7226c842014-07-02 17:42:23 -07006022 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006023
6024 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006025 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6026 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006027 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6028 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006030 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006031 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006032 return null;
6033 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006034
Jordan Liub49b04b2019-05-06 14:45:15 -07006035 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6036 // the process, where TelephonyManager was instantiated.
6037 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006038 final long identity = Binder.clearCallingIdentity();
6039 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006040 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 final TelephonyManager tele = TelephonyManager.from(context);
6042 final SubscriptionManager sub = SubscriptionManager.from(context);
6043
6044 // Figure out what subscribers are currently active
6045 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046
Jordan Liub49b04b2019-05-06 14:45:15 -07006047 // Only consider subs which match the current subId
6048 // This logic can be simplified. See b/131189269 for progress.
6049 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006050 activeSubscriberIds.add(tele.getSubscriberId(subId));
6051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
6053 // First pass, find a number override for an active subscriber
6054 String mergeNumber = null;
6055 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6056 for (String key : prefs.keySet()) {
6057 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6058 final String subscriberId = (String) prefs.get(key);
6059 if (activeSubscriberIds.contains(subscriberId)) {
6060 final String iccId = key.substring(
6061 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6062 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6063 mergeNumber = (String) prefs.get(numberKey);
6064 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006065 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 + " for active subscriber " + subscriberId);
6067 }
6068 if (!TextUtils.isEmpty(mergeNumber)) {
6069 break;
6070 }
6071 }
6072 }
6073 }
6074
6075 // Shortcut when no active merged subscribers
6076 if (TextUtils.isEmpty(mergeNumber)) {
6077 return null;
6078 }
6079
6080 // Second pass, find all subscribers under that line override
6081 final ArraySet<String> result = new ArraySet<>();
6082 for (String key : prefs.keySet()) {
6083 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6084 final String number = (String) prefs.get(key);
6085 if (mergeNumber.equals(number)) {
6086 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6087 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6088 final String subscriberId = (String) prefs.get(subscriberKey);
6089 if (!TextUtils.isEmpty(subscriberId)) {
6090 result.add(subscriberId);
6091 }
6092 }
6093 }
6094 }
6095
6096 final String[] resultArray = result.toArray(new String[result.size()]);
6097 Arrays.sort(resultArray);
6098 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006099 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6101 }
6102 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006105 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006106 }
6107
6108 @Override
zoey chen38003472019-12-13 17:16:31 +08006109 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6110 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006111
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
6114 final TelephonyManager telephonyManager = mApp.getSystemService(
6115 TelephonyManager.class);
6116 String subscriberId = telephonyManager.getSubscriberId(subId);
6117 if (subscriberId == null) {
6118 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006119 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006120 + subId);
6121 }
6122 return null;
6123 }
6124
6125 final SubscriptionInfo info = SubscriptionController.getInstance()
6126 .getSubscriptionInfo(subId);
6127 final ParcelUuid groupUuid = info.getGroupUuid();
6128 // If it doesn't belong to any group, return just subscriberId of itself.
6129 if (groupUuid == null) {
6130 return new String[]{subscriberId};
6131 }
6132
6133 // Get all subscriberIds from the group.
6134 final List<String> mergedSubscriberIds = new ArrayList<>();
6135 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006136 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6137 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006138 for (SubscriptionInfo subInfo : groupInfos) {
6139 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6140 if (subscriberId != null) {
6141 mergedSubscriberIds.add(subscriberId);
6142 }
6143 }
6144
6145 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148
6149 }
6150 }
6151
6152 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006153 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006154 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006155 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 final Phone phone = getPhone(subId);
6160 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006164 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006165
6166 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006167 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006168 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6169 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006170 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6171 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172
6173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 final Phone phone = getPhone(subId);
6176 if (phone == null) {
6177 return false;
6178 }
6179 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6180 cdmaNonRoamingList);
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006183 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006184 }
6185
6186 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006187 @Deprecated
6188 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6189 enforceModifyPermission();
6190
6191 int returnValue = 0;
6192 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006193 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006194 if(result.exception == null) {
6195 if (result.result != null) {
6196 byte[] responseData = (byte[])(result.result);
6197 if(responseData.length > oemResp.length) {
6198 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6199 responseData.length + "bytes. Buffer Size is " +
6200 oemResp.length + "bytes.");
6201 }
6202 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6203 returnValue = responseData.length;
6204 }
6205 } else {
6206 CommandException ex = (CommandException) result.exception;
6207 returnValue = ex.getCommandError().ordinal();
6208 if(returnValue > 0) returnValue *= -1;
6209 }
6210 } catch (RuntimeException e) {
6211 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6212 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6213 if(returnValue > 0) returnValue *= -1;
6214 }
6215
6216 return returnValue;
6217 }
6218
6219 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006220 public void setRadioCapability(RadioAccessFamily[] rafs) {
6221 try {
6222 ProxyController.getInstance().setRadioCapability(rafs);
6223 } catch (RuntimeException e) {
6224 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6225 }
6226 }
6227
6228 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006229 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006230 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006231 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006232 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006233 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 final long identity = Binder.clearCallingIdentity();
6236 try {
chen xub97461a2018-10-26 14:17:57 -07006237 TelephonyPermissions
6238 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6239 mApp, phone.getSubId(), "getRadioAccessFamily");
6240 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
6243 }
chen xub97461a2018-10-26 14:17:57 -07006244 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006245 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006246
6247 @Override
6248 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006249 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251
6252 final long identity = Binder.clearCallingIdentity();
6253 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006254 ImsManager.getInstance(defaultPhone.getContext(),
6255 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 } finally {
6257 Binder.restoreCallingIdentity(identity);
6258 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006259 }
6260
6261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006262 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006263 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6265 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006266 return false;
6267 }
Svet Ganovb320e182015-04-16 12:30:10 -07006268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 // Check the user preference and the system-level IMS setting. Even if the user has
6272 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6273 // In the long run, we may instead need to check if there exists a connection service
6274 // which can support video calling.
6275 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006276 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 return imsManager.isVtEnabledByPlatform()
6278 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6279 && imsManager.isVtEnabledByUser();
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006283 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006284
Andrew Leea1239f22015-03-02 17:44:07 -08006285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006286 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6287 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006289 mApp, subId, callingPackage, callingFeatureId,
6290 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 return false;
6292 }
6293
6294 final long identity = Binder.clearCallingIdentity();
6295 try {
6296 CarrierConfigManager configManager =
6297 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006298 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
Andrew Leea1239f22015-03-02 17:44:07 -08006303 }
6304
6305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006306 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006308 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 return false;
6310 }
6311
6312 final long identity = Binder.clearCallingIdentity();
6313 try {
6314 CarrierConfigManager configManager =
6315 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006316 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
Andrew Leea1239f22015-03-02 17:44:07 -08006321 }
6322
Andrew Lee9431b832015-03-09 18:46:45 -07006323 @Override
6324 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006325 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006326 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006327 }
6328
6329 @Override
6330 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 final long identity = Binder.clearCallingIdentity();
6332 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006333 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
Andrew Lee9431b832015-03-09 18:46:45 -07006337 }
6338
Hall Liuf6668912018-10-31 17:05:23 -07006339 /**
6340 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6341 * support for the feature and device firmware support.
6342 *
6343 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6344 */
6345 @Override
6346 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006348 final Phone phone = getPhone(subscriptionId);
6349 if (phone == null) {
6350 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6351 return false;
6352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006354 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6356 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 return isCarrierSupported && isDeviceSupported;
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
6361 }
Hall Liu98187582018-01-22 19:15:32 -08006362 }
6363
Hall Liuf6668912018-10-31 17:05:23 -07006364 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006365 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6366 * RTT setting, will return true if the device and carrier both support RTT.
6367 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006368 */
6369 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 final long identity = Binder.clearCallingIdentity();
6371 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006372 boolean isRttSupported = isRttSupported(subscriptionId);
6373 boolean isUserRttSettingOn = Settings.Secure.getInt(
6374 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6375 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6376 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6377 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006381 }
6382
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006383 @Deprecated
6384 @Override
6385 public String getDeviceId(String callingPackage) {
6386 return getDeviceIdWithFeature(callingPackage, null);
6387 }
6388
Sanket Padawe7310cc72015-01-14 09:53:20 -08006389 /**
6390 * Returns the unique device ID of phone, for example, the IMEI for
6391 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6392 *
6393 * <p>Requires Permission:
6394 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6395 */
6396 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006397 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006398 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006399 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006400 return null;
6401 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006402 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006403 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006404 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006405 return null;
6406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 return phone.getDeviceId();
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006414 }
6415
Ping Sunc67b7c22016-03-02 19:16:45 +08006416 /**
6417 * {@hide}
6418 * Returns the IMS Registration Status on a particular subid
6419 *
6420 * @param subId
6421 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006422 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006423 Phone phone = getPhone(subId);
6424 if (phone != null) {
6425 return phone.isImsRegistered();
6426 } else {
6427 return false;
6428 }
6429 }
6430
Santos Cordon7a1885b2015-02-03 11:15:19 -08006431 @Override
6432 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006439 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006440
Tyler Gunnf70ed162019-04-03 15:28:53 -07006441 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006442 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006443 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006445 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006446 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6447 }
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
6454 }
6455
6456 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006457 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 Phone phone = getPhone(subscriptionId);
6461 if (phone == null) {
6462 return null;
6463 }
6464 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6465 } finally {
6466 Binder.restoreCallingIdentity(identity);
6467 }
6468 }
6469
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006470 /**
6471 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006473 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 Phone phone = getPhone(subId);
6477 if (phone != null) {
6478 return phone.isWifiCallingEnabled();
6479 } else {
6480 return false;
6481 }
6482 } finally {
6483 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006484 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006485 }
6486
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006487 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006488 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006489 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006490 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 Phone phone = getPhone(subId);
6494 if (phone != null) {
6495 return phone.isVideoEnabled();
6496 } else {
6497 return false;
6498 }
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006501 }
6502 }
6503
6504 /**
6505 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6506 * defined in {@link ImsRegistrationImplBase}.
6507 */
6508 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 final long identity = Binder.clearCallingIdentity();
6510 try {
6511 Phone phone = getPhone(subId);
6512 if (phone != null) {
6513 return phone.getImsRegistrationTech();
6514 } else {
6515 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6516 }
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006519 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006520 }
6521
Stuart Scott8eef64f2015-04-08 15:13:54 -07006522 @Override
6523 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006524 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006525 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6526 return;
6527 }
6528
Svet Ganovcc087f82015-05-12 20:35:54 -07006529 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006530
Svet Ganovcc087f82015-05-12 20:35:54 -07006531 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006532 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6533 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006534 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006535 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006536 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006537 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6538 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006539 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006540 // There has been issues when Sms raw table somehow stores orphan
6541 // fragments. They lead to garbled message when new fragments come
6542 // in and combined with those stale ones. In case this happens again,
6543 // user can reset all network settings which will clean up this table.
6544 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006545 // Clean up IMS settings as well here.
6546 int slotId = getSlotIndex(subId);
6547 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6548 ImsManager.getInstance(mApp, slotId).factoryReset();
6549 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006550
6551 // Erase modem config if erase modem on network setting is enabled.
6552 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6553 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6554 if (configValue != null && Boolean.parseBoolean(configValue)) {
6555 sendEraseModemConfig(getDefaultPhone());
6556 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006559 }
6560 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006561
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006562 private void cleanUpSmsRawTable(Context context) {
6563 ContentResolver resolver = context.getContentResolver();
6564 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6565 resolver.delete(uri, null, null);
6566 }
6567
Narayan Kamath1c496c22015-04-16 14:40:19 +01006568 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006569 public String getSimLocaleForSubscriber(int subId) {
6570 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6571 final Phone phone = getPhone(subId);
6572 if (phone == null) {
6573 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006574 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 final long identity = Binder.clearCallingIdentity();
6577 try {
chen xu5d3637b2019-01-21 23:31:38 -08006578 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006579 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006580 if (info == null) {
6581 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6582 return null;
6583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 // Try and fetch the locale from the carrier properties or from the SIM language
6585 // preferences (EF-PL and EF-LI)...
6586 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006588 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6589 if (localeFromDefaultSim != null) {
6590 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6591 if (DBG) log("Using locale from subId: " + subId + " locale: "
6592 + localeFromDefaultSim);
6593 return localeFromDefaultSim.toLanguageTag();
6594 } else {
6595 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 }
6597 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 // The SIM language preferences only store a language (e.g. fr = French), not an
6600 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6601 // the SIM and carrier preferences does not include a country we add the country
6602 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006603 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006605 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 return mccLocale.toLanguageTag();
6607 }
6608
6609 if (DBG) log("No locale found - returning null");
6610 return null;
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006614 }
6615
6616 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006617 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6618 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006619 }
6620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 /**
6622 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6623 */
6624 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006625 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6626 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006627 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006628
Chenjie Yu1ba97252018-01-11 18:16:20 -08006629 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006630 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006631
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006632 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006633 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6634 * representing the state of the modem.
6635 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006636 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6637 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006638 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006639 */
6640 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006641 public void requestModemActivityInfo(ResultReceiver result) {
6642 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 ModemActivityInfo ret = null;
6648 synchronized (mLastModemActivityInfo) {
6649 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6650 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006651 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006652 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006654 int[] txTimeMs = info.getTransmitTimeMillis();
6655 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006657 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 }
6659 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006660 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6661 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 mLastModemActivityInfo.setIdleTimeMillis(
6663 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006664 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6665 mLastModemActivityInfo.setReceiveTimeMillis(
6666 info.getReceiveTimeMillis() + mLastModemActivityInfo
6667 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006668 }
Chen Xud78231e2019-09-10 18:49:52 -07006669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6671 mLastModemActivityInfo.getSleepTimeMillis(),
6672 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006673 mLastModemActivityInfo.getTransmitTimeMillis(),
6674 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676 Bundle bundle = new Bundle();
6677 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6678 result.send(0, bundle);
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006681 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006682 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006683
Siddharth Rayb8114062018-06-17 15:02:38 -07006684 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6685 // less than total activity duration.
6686 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6687 if (info == null) {
6688 return false;
6689 }
6690 int activityDurationMs =
6691 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6692 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006693 int[] txTimeMs = info.getTransmitTimeMillis();
6694 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6695 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006696 }
6697 return (info.isValid()
6698 && (info.getSleepTimeMillis() <= activityDurationMs)
6699 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006700 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006701 && (totalTxTimeMs <= activityDurationMs));
6702 }
6703
Jack Yu85bd38a2015-11-09 11:34:32 -08006704 /**
6705 * {@hide}
6706 * Returns the service state information on specified subscription.
6707 */
6708 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006709 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006712 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006713 return null;
6714 }
6715
Hall Liuf19c44f2018-11-27 14:38:17 -08006716 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6717 LocationAccessPolicy.checkLocationPermission(mApp,
6718 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6719 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006720 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006721 .setCallingPid(Binder.getCallingPid())
6722 .setCallingUid(Binder.getCallingUid())
6723 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006724 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006725 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6726 .build());
6727
6728 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6729 LocationAccessPolicy.checkLocationPermission(mApp,
6730 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6731 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006732 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006733 .setCallingPid(Binder.getCallingPid())
6734 .setCallingUid(Binder.getCallingUid())
6735 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006736 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006737 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6738 .build());
6739 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6740 boolean hasFinePermission =
6741 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6742 boolean hasCoarsePermission =
6743 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 final long identity = Binder.clearCallingIdentity();
6746 try {
6747 final Phone phone = getPhone(subId);
6748 if (phone == null) {
6749 return null;
6750 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006751
Hall Liuf19c44f2018-11-27 14:38:17 -08006752 ServiceState ss = phone.getServiceState();
6753
6754 // Scrub out the location info in ServiceState depending on what level of access
6755 // the caller has.
6756 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006757 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6758 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006762 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006763
6764 /**
6765 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6766 *
6767 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6768 * voicemail ringtone.
6769 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6770 * PhoneAccount.
6771 */
6772 @Override
6773 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 final long identity = Binder.clearCallingIdentity();
6775 try {
6776 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6777 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006778 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
6784 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006785 }
6786
6787 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006788 * Sets the per-account voicemail ringtone.
6789 *
6790 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6791 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6792 *
6793 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6794 * voicemail ringtone.
6795 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6796 * PhoneAccount.
6797 */
6798 @Override
6799 public void setVoicemailRingtoneUri(String callingPackage,
6800 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006801 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006802 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006803 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6804 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6806 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6807 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809
6810 final long identity = Binder.clearCallingIdentity();
6811 try {
6812 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6813 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006814 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 }
6816 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6817 } finally {
6818 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006819 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006820 }
6821
6822 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006823 * Returns whether vibration is set for voicemail notification in Phone settings.
6824 *
6825 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6826 * voicemail vibration setting.
6827 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6828 */
6829 @Override
6830 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 final long identity = Binder.clearCallingIdentity();
6832 try {
6833 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6834 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006835 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6839 } finally {
6840 Binder.restoreCallingIdentity(identity);
6841 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006842 }
6843
Youhan Wange64578a2016-05-02 15:32:42 -07006844 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006845 * Sets the per-account voicemail vibration.
6846 *
6847 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6848 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6849 *
6850 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6851 * voicemail vibration setting.
6852 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6853 * specific PhoneAccount.
6854 */
6855 @Override
6856 public void setVoicemailVibrationEnabled(String callingPackage,
6857 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006858 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006859 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006860 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6861 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6863 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6864 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006865 }
6866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6870 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006871 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872 }
6873 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006876 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006877 }
6878
6879 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006880 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6881 *
6882 * @throws SecurityException if the caller does not have the required permission
6883 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006884 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006885 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006886 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006887 }
6888
6889 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006890 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6891 * permission.
6892 *
6893 * @throws SecurityException if the caller does not have the required permission
6894 */
6895 private void enforceSendSmsPermission() {
6896 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6897 }
6898
6899 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006900 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006901 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006902 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006903 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006904 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 final long identity = Binder.clearCallingIdentity();
6906 try {
6907 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006908 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 if (componentName == null) {
6910 throw new SecurityException(
6911 "Caller not current active visual voicemail package[null]");
6912 }
6913 String vvmPackage = componentName.getPackageName();
6914 if (!callingPackage.equals(vvmPackage)) {
6915 throw new SecurityException("Caller not current active visual voicemail package["
6916 + vvmPackage + "]");
6917 }
6918 } finally {
6919 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006920 }
6921 }
6922
6923 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006924 * Return the application ID for the app type.
6925 *
6926 * @param subId the subscription ID that this request applies to.
6927 * @param appType the uicc app type.
6928 * @return Application ID for specificied app type, or null if no uicc.
6929 */
6930 @Override
6931 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006932 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006933 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934
6935 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006936 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 if (phone == null) {
6938 return null;
6939 }
6940 String aid = null;
6941 try {
6942 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6943 .getApplicationByType(appType).getAid();
6944 } catch (Exception e) {
6945 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6946 }
6947 return aid;
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006950 }
Youhan Wange64578a2016-05-02 15:32:42 -07006951 }
6952
Youhan Wang4001d252016-05-11 10:29:41 -07006953 /**
6954 * Return the Electronic Serial Number.
6955 *
6956 * @param subId the subscription ID that this request applies to.
6957 * @return ESN or null if error.
6958 */
6959 @Override
6960 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006961 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006962 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963
6964 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006965 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 if (phone == null) {
6967 return null;
6968 }
6969 String esn = null;
6970 try {
6971 esn = phone.getEsn();
6972 } catch (Exception e) {
6973 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6974 }
6975 return esn;
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006978 }
Youhan Wang4001d252016-05-11 10:29:41 -07006979 }
6980
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006981 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006982 * Return the Preferred Roaming List Version.
6983 *
6984 * @param subId the subscription ID that this request applies to.
6985 * @return PRLVersion or null if error.
6986 */
6987 @Override
6988 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006989 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006990 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991
6992 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006993 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 if (phone == null) {
6995 return null;
6996 }
6997 String cdmaPrlVersion = null;
6998 try {
6999 cdmaPrlVersion = phone.getCdmaPrlVersion();
7000 } catch (Exception e) {
7001 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7002 }
7003 return cdmaPrlVersion;
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007006 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007007 }
7008
7009 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007010 * Get snapshot of Telephony histograms
7011 * @return List of Telephony histograms
7012 * @hide
7013 */
7014 @Override
7015 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7017 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 final long identity = Binder.clearCallingIdentity();
7020 try {
7021 return RIL.getTelephonyRILTimingHistograms();
7022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007025 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007026
7027 /**
7028 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007029 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7030 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007031 * Require system privileges. In the future we may add this to carrier APIs.
7032 *
Michele Berionne482f8202018-11-27 18:57:59 -08007033 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007034 */
7035 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007036 @TelephonyManager.SetCarrierRestrictionResult
7037 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007038 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007040
Michele Berionne482f8202018-11-27 18:57:59 -08007041 if (carrierRestrictionRules == null) {
7042 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007043 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 final long identity = Binder.clearCallingIdentity();
7046 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007047 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007048 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007052 }
7053
7054 /**
7055 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007056 * Get the allowed carrier list and the excluded carrier list, including the priority between
7057 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007058 * Require system privileges. In the future we may add this to carrier APIs.
7059 *
Michele Berionne482f8202018-11-27 18:57:59 -08007060 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007061 */
7062 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007063 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007064 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007065 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066
7067 final long identity = Binder.clearCallingIdentity();
7068 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007069 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7070 if (response instanceof CarrierRestrictionRules) {
7071 return (CarrierRestrictionRules) response;
7072 }
7073 // Response is an Exception of some kind,
7074 // which is signalled to the user as a NULL retval
7075 return null;
7076 } catch (Exception e) {
7077 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7078 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007082 }
7083
fionaxu59545b42016-05-25 15:53:37 -07007084 /**
7085 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7086 * @param subId the subscription ID that this action applies to.
7087 * @param enabled control enable or disable metered apns.
7088 * {@hide}
7089 */
7090 @Override
7091 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7092 enforceModifyPermission();
7093 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094
7095 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007096 if (phone == null) {
7097 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7098 return;
7099 }
7100 try {
7101 phone.carrierActionSetMeteredApnsEnabled(enabled);
7102 } catch (Exception e) {
7103 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 } finally {
7105 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007106 }
7107 }
7108
7109 /**
7110 * Action set from carrier signalling broadcast receivers to enable/disable radio
7111 * @param subId the subscription ID that this action applies to.
7112 * @param enabled control enable or disable radio.
7113 * {@hide}
7114 */
7115 @Override
7116 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7117 enforceModifyPermission();
7118 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119
7120 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007121 if (phone == null) {
7122 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7123 return;
7124 }
7125 try {
7126 phone.carrierActionSetRadioEnabled(enabled);
7127 } catch (Exception e) {
7128 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 } finally {
7130 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007131 }
7132 }
7133
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007134 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007135 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7136 * network status based on which carrier apps could apply actions accordingly,
7137 * enable/disable default url handler for example.
7138 *
7139 * @param subId the subscription ID that this action applies to.
7140 * @param report control start/stop reporting the default network status.
7141 * {@hide}
7142 */
7143 @Override
7144 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7145 enforceModifyPermission();
7146 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
7148 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007149 if (phone == null) {
7150 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7151 return;
7152 }
7153 try {
7154 phone.carrierActionReportDefaultNetworkStatus(report);
7155 } catch (Exception e) {
7156 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 } finally {
7158 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007159 }
7160 }
7161
7162 /**
fionaxud9622282017-07-17 17:51:30 -07007163 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7164 * @param subId the subscription ID that this action applies to.
7165 * {@hide}
7166 */
7167 @Override
7168 public void carrierActionResetAll(int subId) {
7169 enforceModifyPermission();
7170 final Phone phone = getPhone(subId);
7171 if (phone == null) {
7172 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7173 return;
7174 }
7175 try {
7176 phone.carrierActionResetAll();
7177 } catch (Exception e) {
7178 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7179 }
7180 }
7181
7182 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007183 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7184 * bug report is being generated.
7185 */
7186 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007187 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007188 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7189 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007190 writer.println("Permission Denial: can't dump Phone from pid="
7191 + Binder.getCallingPid()
7192 + ", uid=" + Binder.getCallingUid()
7193 + "without permission "
7194 + android.Manifest.permission.DUMP);
7195 return;
7196 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007197 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007198 }
Jack Yueb89b242016-06-22 13:27:47 -07007199
Brad Ebingerdac2f002018-04-03 15:17:52 -07007200 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007201 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7202 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7203 @NonNull String[] args) {
7204 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7205 this, in.getFileDescriptor(), out.getFileDescriptor(),
7206 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007207 }
7208
Jack Yueb89b242016-06-22 13:27:47 -07007209 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007210 * Policy control of data connection. Usually used when data limit is passed.
7211 * @param enabled True if enabling the data, otherwise disabling.
7212 * @param subId Subscription index
7213 * {@hide}
7214 */
7215 @Override
7216 public void setPolicyDataEnabled(boolean enabled, int subId) {
7217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218
7219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 Phone phone = getPhone(subId);
7222 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007223 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 }
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007227 }
7228 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007229
7230 /**
7231 * Get Client request stats
7232 * @return List of Client Request Stats
7233 * @hide
7234 */
7235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007236 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7237 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007239 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007240 return null;
7241 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007242 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 if (phone != null) {
7247 return phone.getClientRequestStats();
7248 }
7249
7250 return null;
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007254 }
7255
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007256 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007257 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007258 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007259 }
Jack Yueb4124c2017-02-16 15:32:43 -08007260
7261 /**
Grace Chen70990072017-03-24 17:21:30 -07007262 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007263 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007264 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007265 * @param state State of SIM (power down, power up, pass through)
7266 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7267 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7268 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007269 *
7270 **/
7271 @Override
Grace Chen70990072017-03-24 17:21:30 -07007272 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007273 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007274 Phone phone = PhoneFactory.getPhone(slotIndex);
7275
vagdeviaf9a5b92018-08-15 16:01:53 -07007276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007281 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 }
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007285 }
7286 }
Shuo Qiandd210312017-04-12 22:11:33 +00007287
Tyler Gunn65d45c22017-06-05 11:22:26 -07007288 private boolean isUssdApiAllowed(int subId) {
7289 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007291 if (configManager == null) {
7292 return false;
7293 }
7294 PersistableBundle pb = configManager.getConfigForSubId(subId);
7295 if (pb == null) {
7296 return false;
7297 }
7298 return pb.getBoolean(
7299 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7300 }
7301
Shuo Qiandd210312017-04-12 22:11:33 +00007302 /**
7303 * Check if phone is in emergency callback mode
7304 * @return true if phone is in emergency callback mode
7305 * @param subId sub id
7306 */
goneil9c5f4872017-12-05 14:07:56 -08007307 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007308 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007309 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007310 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 if (phone != null) {
7315 return phone.isInEcm();
7316 } else {
7317 return false;
7318 }
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007321 }
7322 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007323
7324 /**
7325 * Get the current signal strength information for the given subscription.
7326 * Because this information is not updated when the device is in a low power state
7327 * it should not be relied-upon to be current.
7328 * @param subId Subscription index
7329 * @return the most recent cached signal strength info from the modem
7330 */
7331 @Override
7332 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 Phone p = getPhone(subId);
7336 if (p == null) {
7337 return null;
7338 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 return p.getSignalStrength();
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007344 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007345
Pengquan Meng77b7f132018-08-22 14:49:57 -07007346 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007347 * Get the current modem radio state for the given slot.
7348 * @param slotIndex slot index.
7349 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007351 * @return the current radio power state from the modem
7352 */
7353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007354 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007355 Phone phone = PhoneFactory.getPhone(slotIndex);
7356 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7358 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007359 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7360 }
7361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 return phone.getRadioPowerState();
7365 } finally {
7366 Binder.restoreCallingIdentity(identity);
7367 }
7368 }
7369 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7370 }
7371
7372 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007373 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7374 *
7375 * <p>Requires one of the following permissions:
7376 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7377 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7378 * privileges.
7379 *
7380 * @param subId subscription id
7381 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7382 * {@code false}.
7383 */
7384 @Override
7385 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007386 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7387 null /* message */);
7388
Pengquan Menga1bb6272018-09-06 09:59:22 -07007389 boolean isEnabled = false;
7390 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007391 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007392 Phone phone = getPhone(subId);
7393 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007394 } catch (Exception e) {
7395 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7396 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007397 } finally {
7398 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007399 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007400 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007401 }
7402
7403
7404 /**
7405 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7406 *
7407 * <p> Requires permission:
7408 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7409 * privileges.
7410 *
7411 * @param subId subscription id
7412 * @param isEnabled {@code true} means enable, {@code false} means disable.
7413 */
7414 @Override
7415 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7417 mApp, subId, "setDataRoamingEnabled");
7418
Pengquan Menga1bb6272018-09-06 09:59:22 -07007419 final long identity = Binder.clearCallingIdentity();
7420 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007421 Phone phone = getPhone(subId);
7422 if (phone != null) {
7423 phone.setDataRoamingEnabled(isEnabled);
7424 }
7425 } finally {
7426 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007427 }
7428 }
7429
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007430 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007431 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007432 TelephonyPermissions
7433 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007434 mApp, subId, "isManualNetworkSelectionAllowed");
7435
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007436 boolean isAllowed = true;
7437 final long identity = Binder.clearCallingIdentity();
7438 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007439 Phone phone = getPhone(subId);
7440 if (phone != null) {
7441 isAllowed = phone.isCspPlmnEnabled();
7442 }
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
7446 return isAllowed;
7447 }
7448
7449 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007450 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu102b2772020-03-04 13:59:23 -08007451 try {
7452 PackageManager pm = mApp.getPackageManager();
7453 if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) {
7454 throw new SecurityException("Calling package " + callingPackage + " does not match "
7455 + "calling UID");
7456 }
7457 } catch (PackageManager.NameNotFoundException e) {
7458 throw new SecurityException("Invalid calling package. e=" + e);
7459 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007460 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007461 try {
7462 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007463 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007464 } catch (SecurityException e) {
7465 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7466 // has carrier privileges on an active UICC
7467 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7468 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007469 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007470 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007471 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007472
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007475 UiccController uiccController = UiccController.getInstance();
7476 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007477 if (hasReadPermission) {
7478 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007479 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007480
7481 // Remove private info if the caller doesn't have access
7482 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7483 for (UiccCardInfo cardInfo : cardInfos) {
7484 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7485 // is available
7486 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7487 if (card == null || card.getUiccProfile() == null) {
7488 // assume no access if the card or profile is unavailable
7489 filteredInfos.add(cardInfo.getUnprivileged());
7490 continue;
7491 }
7492 UiccProfile profile = card.getUiccProfile();
7493 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7494 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7495 filteredInfos.add(cardInfo);
7496 } else {
7497 filteredInfos.add(cardInfo.getUnprivileged());
7498 }
7499 }
7500 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
7504 }
7505
7506 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007507 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007508 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7513 if (slots == null) {
7514 Rlog.i(LOG_TAG, "slots is null.");
7515 return null;
7516 }
7517
7518 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7519 for (int i = 0; i < slots.length; i++) {
7520 UiccSlot slot = slots[i];
7521 if (slot == null) {
7522 continue;
7523 }
7524
Jordan Liu7be7e652019-05-06 18:55:02 +00007525 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 UiccCard card = slot.getUiccCard();
7527 if (card != null) {
7528 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007529 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007530 cardId = slot.getEid();
7531 if (TextUtils.isEmpty(cardId)) {
7532 cardId = slot.getIccId();
7533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 }
7535
Jordan Liu857451f2019-05-09 16:35:35 -07007536 if (cardId != null) {
7537 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7538 // if cardId is an EID, it's all digits so this is fine
7539 cardId = IccUtils.stripTrailingFs(cardId);
7540 }
7541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 int cardState = 0;
7543 switch (slot.getCardState()) {
7544 case CARDSTATE_ABSENT:
7545 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7546 break;
7547 case CARDSTATE_PRESENT:
7548 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7549 break;
7550 case CARDSTATE_ERROR:
7551 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7552 break;
7553 case CARDSTATE_RESTRICTED:
7554 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7555 break;
7556 default:
7557 break;
7558
7559 }
7560
7561 infos[i] = new UiccSlotInfo(
7562 slot.isActive(),
7563 slot.isEuicc(),
7564 cardId,
7565 cardState,
7566 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007567 slot.isExtendedApduSupported(),
7568 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 }
7570 return infos;
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007573 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007574 }
7575
7576 @Override
7577 public boolean switchSlots(int[] physicalSlots) {
7578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007586 }
Jack Yu4c988042018-02-27 15:30:01 -08007587
7588 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007589 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 return UiccController.getInstance().getCardIdForDefaultEuicc();
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
7596 }
7597
Pengquan Meng85728fb2018-03-12 16:31:21 -07007598 /**
goneil47ffb6e2018-04-06 15:40:58 -07007599 * A test API to reload the UICC profile.
7600 *
7601 * <p>Requires that the calling app has permission
7602 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7603 * @hide
7604 */
7605 @Override
7606 public void refreshUiccProfile(int subId) {
7607 enforceModifyPermission();
7608
7609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 Phone phone = getPhone(subId);
7612 if (phone == null) {
7613 return;
7614 }
7615 UiccCard uiccCard = phone.getUiccCard();
7616 if (uiccCard == null) {
7617 return;
7618 }
7619 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7620 if (uiccProfile == null) {
7621 return;
7622 }
7623 uiccProfile.refresh();
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
7627 }
7628
7629 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007630 * Returns false if the mobile data is disabled by default, otherwise return true.
7631 */
7632 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007633 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007634 }
7635
7636 /**
7637 * Returns true if the data roaming is enabled by default, i.e the system property
7638 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7639 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7640 */
7641 private boolean getDefaultDataRoamingEnabled(int subId) {
7642 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007644 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007645 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7646 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7647 return isDataRoamingEnabled;
7648 }
7649
7650 /**
7651 * Returns the default network type for the given {@code subId}, if the default network type is
7652 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7653 */
7654 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007655 List<Integer> list = TelephonyProperties.default_network();
7656 int phoneId = mSubscriptionController.getPhoneId(subId);
7657 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7658 return list.get(phoneId);
7659 }
7660 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007661 }
fionaxua13278b2018-03-21 00:08:13 -07007662
7663 @Override
7664 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007665 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667
7668 final long identity = Binder.clearCallingIdentity();
7669 try {
7670 final Phone phone = getPhone(subId);
7671 if (phone == null) {
7672 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7673 return;
7674 }
chen xueaba88a2019-03-15 13:15:10 -07007675 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7676 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 } finally {
7678 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007679 }
fionaxua13278b2018-03-21 00:08:13 -07007680 }
7681
7682 @Override
7683 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007684 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685
7686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 final Phone phone = getPhone(subId);
7689 if (phone == null) {
7690 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7691 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7692 }
7693 return phone.getCarrierIdListVersion();
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007696 }
fionaxua13278b2018-03-21 00:08:13 -07007697 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007698
7699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007700 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7701 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007703 mApp, subId, callingPackage, callingFeatureId,
7704 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007705 return -1;
7706 }
7707
7708 final long identity = Binder.clearCallingIdentity();
7709 try {
7710 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
7713 }
7714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007715
7716 @Override
7717 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007718 TelephonyPermissions
7719 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007720 mApp, subId, "getCdmaRoamingMode");
7721
7722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
7727 }
7728 }
7729
7730 @Override
7731 public boolean setCdmaRoamingMode(int subId, int mode) {
7732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7733 mApp, subId, "setCdmaRoamingMode");
7734
7735 final long identity = Binder.clearCallingIdentity();
7736 try {
7737 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7738 } finally {
7739 Binder.restoreCallingIdentity(identity);
7740 }
7741 }
7742
7743 @Override
7744 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7746 mApp, subId, "setCdmaSubscriptionMode");
7747
7748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7751 } finally {
7752 Binder.restoreCallingIdentity(identity);
7753 }
7754 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007755
sqianc5eccab2018-10-19 18:46:41 -07007756 @Override
sqian8c685422019-02-22 15:55:18 -08007757 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007758 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007760 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7761 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007762 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7763 }
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
sqian854d44b2018-12-12 16:48:18 -08007766 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7767 for (Phone phone: PhoneFactory.getPhones()) {
7768 if (phone.getEmergencyNumberTracker() != null
7769 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7770 emergencyNumberListInternal.put(
7771 phone.getSubId(),
7772 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7773 }
sqian11b7a0e2018-12-05 18:48:28 -08007774 }
sqian854d44b2018-12-12 16:48:18 -08007775 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007776 } finally {
7777 Binder.restoreCallingIdentity(identity);
7778 }
sqianc5eccab2018-10-19 18:46:41 -07007779 }
7780
7781 @Override
sqian8c685422019-02-22 15:55:18 -08007782 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007783 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007784 if (!exactMatch) {
7785 TelephonyPermissions
7786 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007787 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007788 }
7789 final long identity = Binder.clearCallingIdentity();
7790 try {
sqian854d44b2018-12-12 16:48:18 -08007791 for (Phone phone: PhoneFactory.getPhones()) {
7792 if (phone.getEmergencyNumberTracker() != null
7793 && phone.getEmergencyNumberTracker() != null) {
7794 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7795 number, exactMatch)) {
7796 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007797 }
7798 }
sqian11b7a0e2018-12-05 18:48:28 -08007799 }
7800 return false;
7801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
7804 }
7805
sqianf4ca7ed2019-01-15 18:32:07 -08007806 /**
7807 * Update emergency number list for test mode.
7808 */
7809 @Override
7810 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7812 "updateEmergencyNumberListTestMode");
7813
7814 final long identity = Binder.clearCallingIdentity();
7815 try {
7816 for (Phone phone: PhoneFactory.getPhones()) {
7817 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7818 if (tracker != null) {
7819 tracker.executeEmergencyNumberTestModeCommand(action, num);
7820 }
7821 }
7822 } finally {
7823 Binder.restoreCallingIdentity(identity);
7824 }
7825 }
7826
7827 /**
7828 * Get the full emergency number list for test mode.
7829 */
7830 @Override
7831 public List<String> getEmergencyNumberListTestMode() {
7832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7833 "getEmergencyNumberListTestMode");
7834
7835 final long identity = Binder.clearCallingIdentity();
7836 try {
7837 Set<String> emergencyNumbers = new HashSet<>();
7838 for (Phone phone: PhoneFactory.getPhones()) {
7839 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7840 if (tracker != null) {
7841 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7842 emergencyNumbers.add(num.getNumber());
7843 }
7844 }
7845 }
7846 return new ArrayList<>(emergencyNumbers);
7847 } finally {
7848 Binder.restoreCallingIdentity(identity);
7849 }
7850 }
7851
chen xud6b45bd2018-10-30 22:27:10 -07007852 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007853 public int getEmergencyNumberDbVersion(int subId) {
7854 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7855
7856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 final Phone phone = getPhone(subId);
7859 if (phone == null) {
7860 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7861 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7862 }
7863 return phone.getEmergencyNumberDbVersion();
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
7867 }
7868
7869 @Override
7870 public void notifyOtaEmergencyNumberDbInstalled() {
7871 enforceModifyPermission();
7872
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 for (Phone phone: PhoneFactory.getPhones()) {
7876 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7877 if (tracker != null) {
7878 tracker.updateOtaEmergencyNumberDatabase();
7879 }
7880 }
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
7884 }
7885
7886 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007887 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007888 enforceActiveEmergencySessionPermission();
7889
7890 final long identity = Binder.clearCallingIdentity();
7891 try {
7892 for (Phone phone: PhoneFactory.getPhones()) {
7893 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7894 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007895 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7896 }
7897 }
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
7900 }
7901 }
7902
7903 @Override
7904 public void resetOtaEmergencyNumberDbFilePath() {
7905 enforceActiveEmergencySessionPermission();
7906
7907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 for (Phone phone: PhoneFactory.getPhones()) {
7910 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7911 if (tracker != null) {
7912 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007913 }
7914 }
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
7918 }
7919
7920 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007921 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7922 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7923 Phone phone = getPhone(subId);
7924 if (phone == null) {
7925 return null;
7926 }
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 UiccProfile profile = UiccController.getInstance()
7930 .getUiccProfileForPhone(phone.getPhoneId());
7931 if (profile != null) {
7932 return profile.getCertsFromCarrierPrivilegeAccessRules();
7933 }
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
7937 return null;
7938 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007939
7940 /**
7941 * Enable or disable a modem stack.
7942 */
7943 @Override
7944 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7945 enforceModifyPermission();
7946
7947 final long identity = Binder.clearCallingIdentity();
7948 try {
7949 Phone phone = PhoneFactory.getPhone(slotIndex);
7950 if (phone == null) {
7951 return false;
7952 } else {
7953 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7954 }
7955 } finally {
7956 Binder.restoreCallingIdentity(identity);
7957 }
7958 }
Michelecea4cf22018-12-21 15:00:11 -08007959
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007960 /**
7961 * Whether a modem stack is enabled or not.
7962 */
7963 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007964 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7965 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007966 Phone phone = PhoneFactory.getPhone(slotIndex);
7967 if (phone == null) return false;
7968
7969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007970 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7971 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007972 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7973 }
7974
7975 final long identity = Binder.clearCallingIdentity();
7976 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007977 try {
7978 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7979 } catch (NoSuchElementException ex) {
7980 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7981 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007982 } finally {
7983 Binder.restoreCallingIdentity(identity);
7984 }
7985 }
7986
Michelecea4cf22018-12-21 15:00:11 -08007987 @Override
Michele0ea7d782019-03-19 14:58:42 -07007988 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007989 enforceModifyPermission();
7990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007994 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007995 .commit();
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
7999 }
8000
8001 @Override
Michele0ea7d782019-03-19 14:58:42 -07008002 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008003 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008005 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8006 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008007 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008008 }
Michelecea4cf22018-12-21 15:00:11 -08008009
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
Michele0ea7d782019-03-19 14:58:42 -07008012 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
8016 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008017
Michele0ea7d782019-03-19 14:58:42 -07008018 @TelephonyManager.IsMultiSimSupportedResult
8019 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008020 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8021 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8022 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008023 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8024 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008025 }
8026 // Check if the hardware supports multisim functionality. If usage of multisim is not
8027 // supported by the modem, indicate that it is restricted.
8028 PhoneCapability staticCapability =
8029 mPhoneConfigurationManager.getStaticPhoneCapability();
8030 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008031 loge("isMultiSimSupportedInternal: no static configuration available");
8032 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008033 }
Sarah Chin7caee492020-02-18 20:49:02 +00008034 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008035 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8036 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008037 }
8038 // Check if support of multiple SIMs is restricted by carrier
8039 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008040 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008041 }
8042
Michele0ea7d782019-03-19 14:58:42 -07008043 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008044 }
8045
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008046 /**
8047 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008048 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8049 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8050 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008051 * @param numOfSims number of active sims we want to switch to
8052 */
8053 @Override
8054 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008055 if (numOfSims == 1) {
8056 enforceModifyPermission();
8057 } else {
8058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8059 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8060 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008061 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008062
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008063 try {
Michele30b57b22019-03-01 12:01:14 -08008064 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008065 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008066 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8067 return;
8068 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008069 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
8073 }
8074
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008075 @Override
8076 public boolean isApplicationOnUicc(int subId, int appType) {
8077 enforceReadPrivilegedPermission("isApplicationOnUicc");
8078 Phone phone = getPhone(subId);
8079 if (phone == null) {
8080 return false;
8081 }
8082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 UiccCard uiccCard = phone.getUiccCard();
8085 if (uiccCard == null) {
8086 return false;
8087 }
8088 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8089 if (uiccProfile == null) {
8090 return false;
8091 }
8092 if (TelephonyManager.APPTYPE_SIM <= appType
8093 && appType <= TelephonyManager.APPTYPE_ISIM) {
8094 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8095 }
8096 return false;
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099 }
8100 }
8101
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008102 /**
chen xub4baa772019-04-03 10:23:41 -07008103 * Get whether making changes to modem configurations will trigger reboot.
8104 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008105 */
8106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008107 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8108 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008110 mApp, subId, callingPackage, callingFeatureId,
8111 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008112 return false;
8113 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008114 final long identity = Binder.clearCallingIdentity();
8115 try {
8116 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
8119 }
8120 }
8121
Nathan Harold29f5f052019-02-15 13:41:57 -08008122 private void updateModemStateMetrics() {
8123 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8124 // TODO: check the state for each modem if the api is ready.
8125 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8126 }
8127
Pengquan Meng3889a572019-01-23 11:16:29 -08008128 @Override
8129 public int[] getSlotsMapping() {
8130 enforceReadPrivilegedPermission("getSlotsMapping");
8131
8132 final long identity = Binder.clearCallingIdentity();
8133 try {
8134 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8135 // All logical slots should have a mapping to a physical slot.
8136 int[] logicalSlotsMapping = new int[phoneCount];
8137 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8138 for (int i = 0; i < slotInfos.length; i++) {
8139 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8140 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8141 }
8142 }
8143 return logicalSlotsMapping;
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
8147 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008148
8149 /**
8150 * Get the IRadio HAL Version
8151 */
8152 @Override
8153 public int getRadioHalVersion() {
8154 Phone phone = getDefaultPhone();
8155 if (phone == null) return -1;
8156 HalVersion hv = phone.getHalVersion();
8157 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8158 return hv.major * 100 + hv.minor;
8159 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008160
8161 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008162 * Get the current calling package name.
8163 * @return the current calling package name
8164 */
8165 @Override
8166 public String getCurrentPackageName() {
8167 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8168 }
8169
8170 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008171 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8172 * corresponding network requests on a subId.
8173 *
8174 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008175 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008176 * 2) APN is un-metered for this subscription, or
8177 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008178 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008179 *
8180 * @return whether data is allowed for a apn type.
8181 *
8182 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008183 */
8184 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008185 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008186 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8187 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008188
8189 // Now that all security checks passes, perform the operation as ourselves.
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 Phone phone = getPhone(subId);
8193 if (phone == null) return false;
8194
Jack Yu41407ee2019-05-13 16:54:09 -07008195 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008196 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
8201
8202 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008203 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008204 enforceReadPrivilegedPermission("isApnMetered");
8205
8206 // Now that all security checks passes, perform the operation as ourselves.
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 Phone phone = getPhone(subId);
8210 if (phone == null) return true; // By default return true.
8211
Jack Yu41407ee2019-05-13 16:54:09 -07008212 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
8216 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008217
8218 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008219 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8220 int subscriptionId, IBooleanConsumer resultCallback) {
8221 enforceModifyPermission();
8222 long token = Binder.clearCallingIdentity();
8223 try {
8224 Phone phone = getPhone(subscriptionId);
8225 if (phone == null) {
8226 try {
8227 if (resultCallback != null) {
8228 resultCallback.accept(false);
8229 }
8230 } catch (RemoteException e) {
8231 // ignore
8232 }
8233 return;
8234 }
8235 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8236 Pair.create(specifiers, (x) -> {
8237 try {
8238 if (resultCallback != null) {
8239 resultCallback.accept(x);
8240 }
8241 } catch (RemoteException e) {
8242 // ignore
8243 }
8244 });
8245 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8246 } finally {
8247 Binder.restoreCallingIdentity(token);
8248 }
8249 }
8250
8251 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008252 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008253 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008254 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8255 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8256 if (iccRecords == null) {
8257 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8258 return false;
8259 }
8260 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8261 }
8262
8263 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008264 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008265 if (callingPackage == null) {
8266 callingPackage = getCurrentPackageName();
8267 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008268 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8269 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8270 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8271 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8272 }
8273 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8274 Intent intent = new Intent();
8275 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8276 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8277 // Bring up choose default SMS subscription dialog right now
8278 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8279 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8280 mApp.startActivity(intent);
8281 }
chen xud5ca2d52019-05-28 15:20:57 -07008282
8283 @Override
8284 public String getMmsUAProfUrl(int subId) {
8285 //TODO investigate if this API should require proper permission check in R b/133791609
8286 final long identity = Binder.clearCallingIdentity();
8287 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008288 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8289 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
8293 }
8294
8295 @Override
8296 public String getMmsUserAgent(int subId) {
8297 //TODO investigate if this API should require proper permission check in R b/133791609
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008300 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8301 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
8305 }
Jack Yub07d4972019-05-28 16:12:25 -07008306
8307 @Override
8308 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8309 enforceModifyPermission();
8310
8311 // Now that all security checks passes, perform the operation as ourselves.
8312 final long identity = Binder.clearCallingIdentity();
8313 try {
8314 Phone phone = getPhone(subId);
8315 if (phone == null) return false;
8316
8317 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8318 } finally {
8319 Binder.restoreCallingIdentity(identity);
8320 }
8321 }
8322
8323 @Override
8324 public boolean isDataAllowedInVoiceCall(int subId) {
8325 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8326
8327 // Now that all security checks passes, perform the operation as ourselves.
8328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 Phone phone = getPhone(subId);
8331 if (phone == null) return false;
8332
8333 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
8337 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008338
changbettyd5c246e2019-12-24 15:40:37 +08008339 @Override
8340 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8341 enforceModifyPermission();
8342
8343 // Now that all security checks passes, perform the operation as ourselves.
8344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 Phone phone = getPhone(subId);
8347 if (phone == null) return false;
8348
8349 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
8354
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008355 /**
8356 * Updates whether conference event pacakge handling is enabled.
8357 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8358 * otherwise.
8359 */
8360 @Override
8361 public void setCepEnabled(boolean isCepEnabled) {
8362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8363
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8367 for (Phone phone : PhoneFactory.getPhones()) {
8368 Phone defaultPhone = phone.getImsPhone();
8369 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8370 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8371 ImsPhoneCallTracker imsPhoneCallTracker =
8372 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8373 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8374 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8375 + imsPhone.getMsisdn());
8376 }
8377 }
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
8381 }
allenwtsu46dcc572020-01-08 18:24:03 +08008382
8383 /**
8384 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8385 *
8386 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8387 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8388 * before being read.
8389 */
8390 @Override
8391 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8392 isCompressed) {
8393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8394 mApp, subId, "notifyRcsAutoConfigurationReceived");
8395 try {
8396 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8397 if (configBinder == null) {
8398 Rlog.e(LOG_TAG, "null result for getImsConfig");
8399 } else {
8400 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8401 }
8402 } catch (RemoteException e) {
8403 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8404 }
8405 }
zoey chene02881a2019-12-30 16:11:23 +08008406
8407 @Override
8408 public boolean isIccLockEnabled(int subId) {
8409 enforceReadPrivilegedPermission("isIccLockEnabled");
8410
8411 // Now that all security checks passes, perform the operation as ourselves.
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 Phone phone = getPhone(subId);
8415 if (phone != null && phone.getIccCard() != null) {
8416 return phone.getIccCard().getIccLockEnabled();
8417 } else {
8418 return false;
8419 }
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
8423 }
8424
8425 /**
8426 * Set the ICC pin lock enabled or disabled.
8427 *
8428 * @return an integer representing the status of IccLock enabled or disabled in the following
8429 * three cases:
8430 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8431 * successfully.
8432 * - Positive number and zero for remaining password attempts.
8433 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8434 *
8435 */
8436 @Override
8437 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8438 enforceModifyPermission();
8439
8440 Phone phone = getPhone(subId);
8441 if (phone == null) {
8442 return 0;
8443 }
8444 // Now that all security checks passes, perform the operation as ourselves.
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8448 new Pair<Boolean, String>(enabled, password), phone, null);
8449 return attemptsRemaining;
8450
8451 } catch (Exception e) {
8452 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 return 0;
8457 }
8458
8459 /**
8460 * Change the ICC password used in ICC pin lock.
8461 *
8462 * @return an integer representing the status of IccLock changed in the following three cases:
8463 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8464 * - Positive number and zero for remaining password attempts.
8465 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8466 *
8467 */
8468 @Override
8469 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8470 enforceModifyPermission();
8471
8472 Phone phone = getPhone(subId);
8473 if (phone == null) {
8474 return 0;
8475 }
8476 // Now that all security checks passes, perform the operation as ourselves.
8477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8480 new Pair<String, String>(oldPassword, newPassword), phone, null);
8481 return attemptsRemaining;
8482
8483 } catch (Exception e) {
8484 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
8488 return 0;
8489 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008490
8491 /**
8492 * Request for receiving user activity notification
8493 */
8494 @Override
8495 public void requestUserActivityNotification() {
8496 if (!mNotifyUserActivity.get()
8497 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8498 mNotifyUserActivity.set(true);
8499 }
8500 }
8501
8502 /**
8503 * Called when userActivity is signalled in the power manager.
8504 * This is safe to call from any thread, with any window manager locks held or not.
8505 */
8506 @Override
8507 public void userActivity() {
8508 // ***************************************
8509 // * Inherited from PhoneWindowManager *
8510 // ***************************************
8511 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8512 // WITH ITS LOCKS HELD.
8513 //
8514 // This code must be VERY careful about the locks
8515 // it acquires.
8516 // In fact, the current code acquires way too many,
8517 // and probably has lurking deadlocks.
8518
8519 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8520 throw new SecurityException("Only the OS may call notifyUserActivity()");
8521 }
8522
8523 if (mNotifyUserActivity.getAndSet(false)) {
8524 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8525 USER_ACTIVITY_NOTIFICATION_DELAY);
8526 }
8527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008528}