blob: b71b5b1988b4d06a4b6379179f61131a9c58bd11 [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);
Shuo Qian1d931ee2020-02-20 17:12:10 -08001031 } else {
1032 ResultReceiver result = (ResultReceiver) request.argument;
1033 Bundle bundle = new Bundle();
1034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1035 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1036 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001037 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001038 break;
1039
1040 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Shuo Qian1d931ee2020-02-20 17:12:10 -08001043 ResultReceiver result = (ResultReceiver) request.argument;
1044
1045 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001046 if (ar.exception == null && ar.result != null) {
Shuo Qian1d931ee2020-02-20 17:12:10 -08001047 // Update the last modem activity info and the result of the request.
1048 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1049 if (isModemActivityInfoValid(info)) {
1050 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1051 int[] txTimeMs = info.getTransmitTimeMillis();
1052 int[] lastModemTxTimeMs = mLastModemActivityInfo
1053 .getTransmitTimeMillis();
1054 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1055 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1056 }
1057 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1058 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1059 + mLastModemActivityInfo.getSleepTimeMillis());
1060 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1061 + mLastModemActivityInfo.getIdleTimeMillis());
1062 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1063 mLastModemActivityInfo.setReceiveTimeMillis(
1064 info.getReceiveTimeMillis()
1065 + mLastModemActivityInfo.getReceiveTimeMillis());
1066 }
1067 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1068 mLastModemActivityInfo.getSleepTimeMillis(),
1069 mLastModemActivityInfo.getIdleTimeMillis(),
1070 mLastModemActivityInfo.getTransmitTimeMillis(),
1071 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001072 } else {
1073 if (ar.result == null) {
1074 loge("queryModemActivityInfo: Empty response");
1075 } else if (ar.exception instanceof CommandException) {
1076 loge("queryModemActivityInfo: CommandException: " +
1077 ar.exception);
1078 } else {
1079 loge("queryModemActivityInfo: Unknown exception");
1080 }
1081 }
Shuo Qian1d931ee2020-02-20 17:12:10 -08001082 Bundle bundle = new Bundle();
1083 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1084 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001085 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 case CMD_SET_ALLOWED_CARRIERS:
1089 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001090 CarrierRestrictionRules argument =
1091 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001092 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001093 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 break;
1095
1096 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result;
1101 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001102 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1103 if (ar.exception instanceof CommandException) {
1104 loge("setAllowedCarriers: CommandException: " + ar.exception);
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 request.result =
1109 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001111 } else {
1112 loge("setAllowedCarriers: Unknown exception");
1113 }
1114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001115 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case CMD_GET_ALLOWED_CARRIERS:
1119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001121 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001122 break;
1123
1124 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null && ar.result != null) {
1128 request.result = ar.result;
1129 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001130 request.result = new IllegalStateException(
1131 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001132 if (ar.result == null) {
1133 loge("getAllowedCarriers: Empty response");
1134 } else if (ar.exception instanceof CommandException) {
1135 loge("getAllowedCarriers: CommandException: " +
1136 ar.exception);
1137 } else {
1138 loge("getAllowedCarriers: Unknown exception");
1139 }
1140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
Nathan Haroldb3014052017-01-25 15:57:32 -08001144 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
1150 request.result = new IllegalArgumentException(
1151 "Failed to retrieve Forbidden Plmns");
1152 if (ar.result == null) {
1153 loge("getForbiddenPlmns: Empty response");
1154 } else {
1155 loge("getForbiddenPlmns: Unknown exception");
1156 }
1157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001159 break;
1160
1161 case CMD_GET_FORBIDDEN_PLMNS:
1162 request = (MainThreadRequest) msg.obj;
1163 uiccCard = getUiccCardFromRequest(request);
1164 if (uiccCard == null) {
1165 loge("getForbiddenPlmns() UiccCard is null");
1166 request.result = new IllegalArgumentException(
1167 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001169 break;
1170 }
1171 Integer appType = (Integer) request.argument;
1172 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1173 if (uiccApp == null) {
1174 loge("getForbiddenPlmns() no app with specified type -- "
1175 + appType);
1176 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001178 break;
1179 } else {
1180 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1181 + " specified type -- " + appType);
1182 }
1183 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1184 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1185 onCompleted);
1186 break;
1187
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001188 case CMD_SWITCH_SLOTS:
1189 request = (MainThreadRequest) msg.obj;
1190 int[] physicalSlots = (int[]) request.argument;
1191 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1192 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1193 break;
1194
1195 case EVENT_SWITCH_SLOTS_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
1200 break;
1201 case CMD_GET_NETWORK_SELECTION_MODE:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1204 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1205 break;
1206
1207 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception != null) {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1212 } else {
1213 int mode = ((int[]) ar.result)[0];
1214 if (mode == 0) {
1215 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1216 } else {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1218 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 notifyRequester(request);
1221 break;
1222 case CMD_GET_CDMA_ROAMING_MODE:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1225 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1226 break;
1227 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
1230 if (ar.exception != null) {
1231 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1232 } else {
1233 request.result = ((int[]) ar.result)[0];
1234 }
1235 notifyRequester(request);
1236 break;
1237 case CMD_SET_CDMA_ROAMING_MODE:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1240 int mode = (int) request.argument;
1241 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1242 break;
1243 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = ar.exception == null;
1247 notifyRequester(request);
1248 break;
1249 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1252 int subscriptionMode = (int) request.argument;
1253 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1254 break;
1255 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 request.result = ar.exception == null;
1259 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001260 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 case CMD_GET_ALL_CELL_INFO:
1262 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001264 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 case EVENT_GET_ALL_CELL_INFO_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001269 // If a timeout occurs, the response will be null
1270 request.result = (ar.exception == null && ar.result != null)
1271 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 synchronized (request) {
1273 request.notifyAll();
1274 }
1275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case CMD_REQUEST_CELL_INFO_UPDATE:
1277 request = (MainThreadRequest) msg.obj;
1278 request.phone.requestCellInfoUpdate(request.workSource,
1279 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1280 break;
1281 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1285 try {
1286 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001288 cb.onError(
1289 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1290 ar.exception.getClass().getName(),
1291 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001294 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 } else {
1296 // use the result as returned
1297 cb.onCellInfo((List<CellInfo>) ar.result);
1298 }
1299 } catch (RemoteException re) {
1300 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1301 }
1302 break;
1303 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 request = (MainThreadRequest) msg.obj;
1305 WorkSource ws = (WorkSource) request.argument;
1306 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001307 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null) {
1313 request.result = ar.result;
1314 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001315 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001317 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 }
1319
1320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001324 case CMD_MODEM_REBOOT:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001328 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001329 case EVENT_CMD_MODEM_REBOOT_DONE:
1330 handleNullReturnEvent(msg, "rebootModem");
1331 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001332 case CMD_REQUEST_ENABLE_MODEM:
1333 request = (MainThreadRequest) msg.obj;
1334 boolean enable = (boolean) request.argument;
1335 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001336 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001337 PhoneConfigurationManager.getInstance()
1338 .enablePhone(request.phone, enable, onCompleted);
1339 break;
1340 case EVENT_ENABLE_MODEM_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001344 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001345 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 if ((boolean) request.result) {
1347 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1348 updateModemStateMetrics();
1349 } else {
1350 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1351 + ar.exception);
1352 }
1353 notifyRequester(request);
1354 break;
1355 case CMD_GET_MODEM_STATUS:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1358 PhoneConfigurationManager.getInstance()
1359 .getPhoneStatusFromModem(request.phone, onCompleted);
1360 break;
1361 case EVENT_GET_MODEM_STATUS_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 int id = request.phone.getPhoneId();
1365 if (ar.exception == null && ar.result != null) {
1366 request.result = ar.result;
1367 //update the cache as modem status has changed
1368 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1369 (boolean) request.result);
1370 } else {
1371 // Return true if modem status cannot be retrieved. For most cases,
1372 // modem status is on. And for older version modems, GET_MODEM_STATUS
1373 // and disable modem are not supported. Modem is always on.
1374 // TODO: this should be fixed in R to support a third
1375 // status UNKNOWN b/131631629
1376 request.result = true;
1377 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1378 + ar.exception);
1379 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 notifyRequester(request);
1381 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001382 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1386 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1387 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1388 break;
1389 }
1390 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
1393 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1394 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1395 args.second.accept(ar.exception == null);
1396 notifyRequester(request);
1397 break;
1398 }
yincheng zhao2737e882019-09-06 17:06:54 -07001399 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
1405 request.result = -1;
1406 loge("Failed to set Forbidden Plmns");
1407 if (ar.result == null) {
1408 loge("setForbidenPlmns: Empty response");
1409 } else if (ar.exception != null) {
1410 loge("setForbiddenPlmns: Exception: " + ar.exception);
1411 request.result = -1;
1412 } else {
1413 loge("setForbiddenPlmns: Unknown exception");
1414 }
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_FORBIDDEN_PLMNS:
1419 request = (MainThreadRequest) msg.obj;
1420 uiccCard = getUiccCardFromRequest(request);
1421 if (uiccCard == null) {
1422 loge("setForbiddenPlmns: UiccCard is null");
1423 request.result = -1;
1424 notifyRequester(request);
1425 break;
1426 }
1427 Pair<Integer, List<String>> setFplmnsArgs =
1428 (Pair<Integer, List<String>>) request.argument;
1429 appType = setFplmnsArgs.first;
1430 List<String> fplmns = setFplmnsArgs.second;
1431 uiccApp = uiccCard.getApplicationByType(appType);
1432 if (uiccApp == null) {
1433 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1434 request.result = -1;
1435 loge("Failed to get UICC App");
1436 notifyRequester(request);
1437 } else {
1438 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1439 ((SIMRecords) uiccApp.getIccRecords())
1440 .setForbiddenPlmns(onCompleted, fplmns);
1441 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001442 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001443 case CMD_ERASE_MODEM_CONFIG:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1446 defaultPhone.eraseModemConfig(onCompleted);
1447 break;
1448 case EVENT_ERASE_MODEM_CONFIG_DONE:
1449 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001450 break;
zoey chene02881a2019-12-30 16:11:23 +08001451
1452 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1455 Pair<String, String> changed = (Pair<String, String>) request.argument;
1456 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1457 changed.first, changed.second, onCompleted);
1458 break;
1459 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1464 } else {
1465 request.result = msg.arg1;
1466 }
1467 notifyRequester(request);
1468 break;
1469
1470 case CMD_SET_ICC_LOCK_ENABLED:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1473 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1474 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1475 enabled.first, enabled.second, onCompleted);
1476 break;
1477 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null) {
1481 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1482 } else {
1483 request.result = msg.arg1;
1484 }
1485 notifyRequester(request);
1486 break;
1487
Peter Wangdafb9ac2020-01-15 14:13:38 -08001488 case MSG_NOTIFY_USER_ACTIVITY:
1489 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001490 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001491 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1492 getDefaultPhone().getContext().sendBroadcastAsUser(
1493 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1494 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 default:
1496 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1497 break;
1498 }
1499 }
Jake Hambye994d462014-02-03 13:10:13 -08001500
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 private void notifyRequester(MainThreadRequest request) {
1502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 }
1506
Jake Hambye994d462014-02-03 13:10:13 -08001507 private void handleNullReturnEvent(Message msg, String command) {
1508 AsyncResult ar = (AsyncResult) msg.obj;
1509 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = true;
1512 } else {
1513 request.result = false;
1514 if (ar.exception instanceof CommandException) {
1515 loge(command + ": CommandException: " + ar.exception);
1516 } else {
1517 loge(command + ": Unknown exception");
1518 }
1519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
1524 /**
1525 * Posts the specified command to be executed on the main thread,
1526 * waits for the request to complete, and returns the result.
1527 * @see #sendRequestAsync
1528 */
1529 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001530 return sendRequest(
1531 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001532 }
1533
1534 /**
1535 * Posts the specified command to be executed on the main thread,
1536 * waits for the request to complete, and returns the result.
1537 * @see #sendRequestAsync
1538 */
1539 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1540 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001541 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 /**
1545 * Posts the specified command to be executed on the main thread,
1546 * waits for the request to complete, and returns the result.
1547 * @see #sendRequestAsync
1548 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001549 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001550 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001551 }
1552
1553 /**
1554 * Posts the specified command to be executed on the main thread,
1555 * waits for the request to complete, and returns the result.
1556 * @see #sendRequestAsync
1557 */
Nathan Harold92bed182018-10-12 18:16:49 -07001558 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1559 return sendRequest(command, argument, subId, null, workSource);
1560 }
1561
1562 /**
1563 * Posts the specified command to be executed on the main thread,
1564 * waits for the request to complete, and returns the result.
1565 * @see #sendRequestAsync
1566 */
1567 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1568 return sendRequest(
1569 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(
1578 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1580 throw new RuntimeException("This method will deadlock if called from the main thread.");
1581 }
1582
Nathan Harold92bed182018-10-12 18:16:49 -07001583 MainThreadRequest request = null;
1584 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1585 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1586 } else if (phone != null) {
1587 request = new MainThreadRequest(argument, phone, workSource);
1588 } else {
1589 request = new MainThreadRequest(argument, subId, workSource);
1590 }
1591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 Message msg = mMainThreadHandler.obtainMessage(command, request);
1593 msg.sendToTarget();
1594
1595 // Wait for the request to complete
1596 synchronized (request) {
1597 while (request.result == null) {
1598 try {
1599 request.wait();
1600 } catch (InterruptedException e) {
1601 // Do nothing, go back and wait until the request is complete
1602 }
1603 }
1604 }
1605 return request.result;
1606 }
1607
1608 /**
1609 * Asynchronous ("fire and forget") version of sendRequest():
1610 * Posts the specified command to be executed on the main thread, and
1611 * returns immediately.
1612 * @see #sendRequest
1613 */
1614 private void sendRequestAsync(int command) {
1615 mMainThreadHandler.sendEmptyMessage(command);
1616 }
1617
1618 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001620 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 */
1622 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001623 sendRequestAsync(command, argument, null, null);
1624 }
1625
1626 /**
1627 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1628 * @see {@link #sendRequest(int,Object)}
1629 */
1630 private void sendRequestAsync(
1631 int command, Object argument, Phone phone, WorkSource workSource) {
1632 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001633 Message msg = mMainThreadHandler.obtainMessage(command, request);
1634 msg.sendToTarget();
1635 }
1636
1637 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 * Initialize the singleton PhoneInterfaceManager instance.
1639 * This is only done once, at startup, from PhoneApp.onCreate().
1640 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001641 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 synchronized (PhoneInterfaceManager.class) {
1643 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001644 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } else {
1646 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1647 }
1648 return sInstance;
1649 }
1650 }
1651
1652 /** Private constructor; @see init() */
Jordan Liu102b2772020-03-04 13:59:23 -08001653 @VisibleForTesting
1654 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001657 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001658 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1660 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001661 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001662 mTelephonySharedPreferences =
1663 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001664 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001665 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001666 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 publish();
1669 }
1670
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001671 private Phone getDefaultPhone() {
1672 Phone thePhone = getPhone(getDefaultSubscription());
1673 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 private void publish() {
1677 if (DBG) log("publish: " + this);
1678
Peter Wangc035ce42020-01-08 21:00:22 -08001679 TelephonyFrameworkInitializer
1680 .getTelephonyServiceManager()
1681 .getTelephonyServiceRegisterer()
1682 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
Stuart Scott584921c2015-01-15 17:10:34 -08001685 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001686 if (request.phone != null) {
1687 return request.phone;
1688 } else {
1689 return getPhoneFromSubId(request.subId);
1690 }
1691 }
1692
1693 private Phone getPhoneFromSubId(int subId) {
1694 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1695 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001696 }
1697
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001698 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1699 Phone phone = getPhoneFromRequest(request);
1700 return phone == null ? null :
1701 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1702 }
1703
Wink Saville36469e72014-06-11 15:17:00 -07001704 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001705 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001706 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708
Naina Nallurid63128d2019-09-17 14:10:30 -07001709 private void sendEraseModemConfig(Phone phone) {
1710 if (phone != null) {
1711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1712 mApp, phone.getSubId(), "eraseModemConfig");
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1716 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
1720 }
1721 }
1722
Peter Wang44b186e2020-01-13 23:33:09 -08001723 private boolean isImsAvailableOnDevice() {
1724 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1725 if (pm == null) {
1726 // For some reason package manger is not available.. This will fail internally anyway,
1727 // so do not throw error and allow.
1728 return true;
1729 }
1730 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1731 }
1732
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001734 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001735 }
1736
Wink Savilleb564aae2014-10-23 10:18:09 -07001737 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 if (DBG) log("dial: " + number);
1739 // No permission check needed here: This is just a wrapper around the
1740 // ACTION_DIAL intent, which is available to any app since it puts up
1741 // the UI before it does anything.
1742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 String url = createTelUrl(number);
1746 if (url == null) {
1747 return;
1748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 // PENDING: should we just silently fail if phone is offhook or ringing?
1751 PhoneConstants.State state = mCM.getState(subId);
1752 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1753 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1754 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1755 mApp.startActivity(intent);
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760 }
1761
1762 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001763 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001764 }
1765
Wink Savilleb564aae2014-10-23 10:18:09 -07001766 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 if (DBG) log("call: " + number);
1768
1769 // This is just a wrapper around the ACTION_CALL intent, but we still
1770 // need to do a permission check since we're calling startActivity()
1771 // from the context of the phone app.
1772 enforceCallPermission();
1773
Jordan Liu1617b712019-07-10 15:06:26 -07001774 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 != AppOpsManager.MODE_ALLOWED) {
1776 return;
1777 }
1778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 String url = createTelUrl(number);
1782 if (url == null) {
1783 return;
1784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 boolean isValid = false;
1787 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1788 if (slist != null) {
1789 for (SubscriptionInfo subInfoRecord : slist) {
1790 if (subInfoRecord.getSubscriptionId() == subId) {
1791 isValid = true;
1792 break;
1793 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001794 }
Wink Saville08874612014-08-31 19:19:58 -07001795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 if (!isValid) {
1797 return;
1798 }
Wink Saville08874612014-08-31 19:19:58 -07001799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1801 intent.putExtra(SUBSCRIPTION_KEY, subId);
1802 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1803 mApp.startActivity(intent);
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
1806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Wink Savilleb564aae2014-10-23 10:18:09 -07001809 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001811 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1812 }
1813
Wink Savilleb564aae2014-10-23 10:18:09 -07001814 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001815 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001816 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1817 }
1818
Wink Savilleb564aae2014-10-23 10:18:09 -07001819 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1825 checkSimPin.start();
1826 return checkSimPin.unlockSim(null, pin);
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
1829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1838 checkSimPuk.start();
1839 return checkSimPuk.unlockSim(puk, pin);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001846 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 * a synchronous one.
1848 */
1849 private static class UnlockSim extends Thread {
1850
1851 private final IccCard mSimCard;
1852
1853 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001854 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1855 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856
1857 // For replies from SimCard interface
1858 private Handler mHandler;
1859
1860 // For async handler to identify request type
1861 private static final int SUPPLY_PIN_COMPLETE = 100;
1862
1863 public UnlockSim(IccCard simCard) {
1864 mSimCard = simCard;
1865 }
1866
1867 @Override
1868 public void run() {
1869 Looper.prepare();
1870 synchronized (UnlockSim.this) {
1871 mHandler = new Handler() {
1872 @Override
1873 public void handleMessage(Message msg) {
1874 AsyncResult ar = (AsyncResult) msg.obj;
1875 switch (msg.what) {
1876 case SUPPLY_PIN_COMPLETE:
1877 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1878 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001879 mRetryCount = msg.arg1;
1880 if (ar.exception != null) {
1881 if (ar.exception instanceof CommandException &&
1882 ((CommandException)(ar.exception)).getCommandError()
1883 == CommandException.Error.PASSWORD_INCORRECT) {
1884 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1885 } else {
1886 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1887 }
1888 } else {
1889 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mDone = true;
1892 UnlockSim.this.notifyAll();
1893 }
1894 break;
1895 }
1896 }
1897 };
1898 UnlockSim.this.notifyAll();
1899 }
1900 Looper.loop();
1901 }
1902
1903 /*
1904 * Use PIN or PUK to unlock SIM card
1905 *
1906 * If PUK is null, unlock SIM card with PIN
1907 *
1908 * If PUK is not null, unlock SIM card with PUK and set PIN code
1909 */
Wink Saville9de0f752013-10-22 19:04:03 -07001910 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911
1912 while (mHandler == null) {
1913 try {
1914 wait();
1915 } catch (InterruptedException e) {
1916 Thread.currentThread().interrupt();
1917 }
1918 }
1919 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1920
1921 if (puk == null) {
1922 mSimCard.supplyPin(pin, callback);
1923 } else {
1924 mSimCard.supplyPuk(puk, pin, callback);
1925 }
1926
1927 while (!mDone) {
1928 try {
1929 Log.d(LOG_TAG, "wait for done");
1930 wait();
1931 } catch (InterruptedException e) {
1932 // Restore the interrupted status
1933 Thread.currentThread().interrupt();
1934 }
1935 }
1936 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001937 int[] resultArray = new int[2];
1938 resultArray[0] = mResult;
1939 resultArray[1] = mRetryCount;
1940 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942 }
1943
1944 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001945 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001946
1947 }
1948
Wink Savilleb564aae2014-10-23 10:18:09 -07001949 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 // No permission check needed here: this call is harmless, and it's
1951 // needed for the ServiceState.requestStateUpdate() call (which is
1952 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 final long identity = Binder.clearCallingIdentity();
1954 try {
1955 final Phone phone = getPhone(subId);
1956 if (phone != null) {
1957 phone.updateServiceLocation();
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001964 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 @Override
1966 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001967 return isRadioOnWithFeature(callingPackage, null);
1968 }
1969
1970
1971 @Override
1972 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1973 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1974 callingFeatureId);
1975 }
1976
1977 @Deprecated
1978 @Override
1979 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1980 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001981 }
1982
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001984 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1985 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001987 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 return false;
1989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990
1991 final long identity = Binder.clearCallingIdentity();
1992 try {
1993 return isRadioOnForSubscriber(subId);
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001997 }
1998
1999 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2005 } else {
2006 return false;
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002014 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
Wink Saville36469e72014-06-11 15:17:00 -07002016
Wink Savilleb564aae2014-10-23 10:18:09 -07002017 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 final Phone phone = getPhone(subId);
2023 if (phone != null) {
2024 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2025 }
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002028 }
Wink Saville36469e72014-06-11 15:17:00 -07002029 }
2030
2031 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002032 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002033 }
2034
Wink Savilleb564aae2014-10-23 10:18:09 -07002035 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037
2038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 final Phone phone = getPhone(subId);
2041 if (phone == null) {
2042 return false;
2043 }
2044 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2045 toggleRadioOnOffForSubscriber(subId);
2046 }
2047 return true;
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
Wink Saville36469e72014-06-11 15:17:00 -07002052
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002054 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002055 /*
2056 * If any of the Radios are available, it will need to be
2057 * shutdown. So return true if any Radio is available.
2058 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2062 Phone phone = PhoneFactory.getPhone(i);
2063 if (phone != null && phone.isRadioAvailable()) return true;
2064 }
2065 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2066 return false;
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002069 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002070 }
2071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002073 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 enforceModifyPermission();
2075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2079 logv("Shutting down Phone " + i);
2080 shutdownRadioUsingPhoneId(i);
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002084 }
2085 }
2086
2087 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002088 Phone phone = PhoneFactory.getPhone(phoneId);
2089 if (phone != null && phone.isRadioAvailable()) {
2090 phone.shutdownRadio();
2091 }
2092 }
2093
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002095 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2100 if (defaultPhone != null) {
2101 defaultPhone.setRadioPower(turnOn);
2102 return true;
2103 } else {
2104 loge("There's no default phone.");
2105 return false;
2106 }
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002109 }
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
Wink Savilleb564aae2014-10-23 10:18:09 -07002112 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 final Phone phone = getPhone(subId);
2118 if (phone != null) {
2119 phone.setRadioPower(turnOn);
2120 return true;
2121 } else {
2122 return false;
2123 }
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Saville36469e72014-06-11 15:17:00 -07002129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 public boolean enableDataConnectivity() {
2132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 int subId = mSubscriptionController.getDefaultDataSubId();
2137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002139 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 return true;
2141 } else {
2142 return false;
2143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148
Wink Saville36469e72014-06-11 15:17:00 -07002149 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002150 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 public boolean disableDataConnectivity() {
2152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
2156 int subId = mSubscriptionController.getDefaultDataSubId();
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002159 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 return true;
2161 } else {
2162 return false;
2163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002170 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002175 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 } else {
2177 return false;
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
2184 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002185 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
pkanwarae03a6b2016-11-06 20:37:09 -08002188 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 enforceCallPermission();
2190
2191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2194 return;
2195 }
2196 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2197 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
pkanwar32d516d2016-10-14 19:37:38 -07002201 };
2202
Wink Savilleb564aae2014-10-23 10:18:09 -07002203 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2209 return false;
2210 }
2211 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002218 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002221 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 Phone phone = PhoneFactory.getPhone(slotIndex);
2225 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2226 PhoneConstantConversions.convertCallState(phone.getState());
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002233 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002234 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2235 }
2236
2237 @Override
2238 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002241 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 if (phone != null) {
2243 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2244 } else {
2245 return PhoneConstantConversions.convertDataState(
2246 PhoneConstants.DataState.DISCONNECTED);
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002254 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002255 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2256 }
2257
2258 @Override
2259 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002262 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 if (phone != null) {
2264 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2265 } else {
2266 return TelephonyManager.DATA_ACTIVITY_NONE;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002274 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002276 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002277
2278 LocationAccessPolicy.LocationPermissionResult locationResult =
2279 LocationAccessPolicy.checkLocationPermission(mApp,
2280 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2281 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002282 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002283 .setCallingPid(Binder.getCallingPid())
2284 .setCallingUid(Binder.getCallingUid())
2285 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002286 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002287 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2288 .build());
2289 switch (locationResult) {
2290 case DENIED_HARD:
2291 throw new SecurityException("Not allowed to access cell location");
2292 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002293 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2294 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002301 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002302 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Svetoslav64fad262015-04-14 14:35:21 -07002306 }
2307
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002309 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002310 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2311 // registered cell info, so return a NULL country instead.
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002314 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2315 // Get default phone in this case.
2316 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2317 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002319 // Todo: fix this when we can get the actual cellular network info when the device
2320 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002321 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002322 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08002323 mApp.getAttributionTag())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002324 return "";
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 Phone phone = PhoneFactory.getPhone(phoneId);
2327 if (phone != null) {
2328 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002329 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330 if (sst != null) {
2331 LocaleTracker lt = sst.getLocaleTracker();
2332 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002333 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2334 return lt.getCurrentCountry();
2335 } else if (emergencyNumberTracker != null) {
2336 return emergencyNumberTracker.getEmergencyCountryIso();
2337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 }
2339 }
2340 }
2341 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002345 }
2346
2347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002349 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002350 }
2351
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 mApp.enforceCallingOrSelfPermission(
2355 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 phone.enableLocationUpdates();
2362 }
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
2368 @Override
2369 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002370 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002371 }
2372
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002374 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 mApp.enforceCallingOrSelfPermission(
2376 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 if (phone != null) {
2382 phone.disableLocationUpdates();
2383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
Nathan Harold31d7ff32018-10-15 20:20:30 -07002389 /**
2390 * Returns the target SDK version number for a given package name.
2391 *
Nathan Haroldec184742019-07-10 17:04:16 -07002392 * This call MUST be invoked before clearing the calling UID.
2393 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002394 * @return target SDK if the package is found or INT_MAX.
2395 */
2396 private int getTargetSdk(String packageName) {
2397 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002398 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002399 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002400 if (ai != null) return ai.targetSdkVersion;
2401 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002402 loge("Failed to get package info for pkg="
2403 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002404 }
2405 return Integer.MAX_VALUE;
2406 }
2407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 @Override
2409 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002410 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2411 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002412 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002413 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2414 throw new SecurityException(
2415 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2416 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002417
Jordan Liu1617b712019-07-10 15:06:26 -07002418 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2420 return null;
2421 }
Svetoslav64fad262015-04-14 14:35:21 -07002422
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002423 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002425 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002426 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427
Nathan Haroldf180aac2018-06-01 18:43:55 -07002428 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2429 for (CellInfo ci : info) {
2430 if (ci instanceof CellInfoGsm) {
2431 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2432 } else if (ci instanceof CellInfoWcdma) {
2433 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002436 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 private List<CellInfo> getCachedCellInfo() {
2440 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2441 for (Phone phone : PhoneFactory.getPhones()) {
2442 List<CellInfo> info = phone.getAllCellInfo();
2443 if (info != null) cellInfos.addAll(info);
2444 }
2445 return cellInfos;
2446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447
2448 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002449 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002450 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002451 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002452
2453 LocationAccessPolicy.LocationPermissionResult locationResult =
2454 LocationAccessPolicy.checkLocationPermission(mApp,
2455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2456 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002457 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002458 .setCallingPid(Binder.getCallingPid())
2459 .setCallingUid(Binder.getCallingUid())
2460 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002462 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2463 .build());
2464 switch (locationResult) {
2465 case DENIED_HARD:
2466 throw new SecurityException("Not allowed to access cell info");
2467 case DENIED_SOFT:
2468 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002471 final int targetSdk = getTargetSdk(callingPackage);
2472 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2473 return getCachedCellInfo();
2474 }
2475
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002476 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2481 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002482 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002483 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 if (info != null) cellInfos.addAll(info);
2485 }
2486 return cellInfos;
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490 }
2491
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002492 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002493 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2494 String callingFeatureId) {
2495 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2496 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 }
2498
2499 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2501 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002502 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002503 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002504 }
2505
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002506 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2507 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002508 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002509 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002510
2511 LocationAccessPolicy.LocationPermissionResult locationResult =
2512 LocationAccessPolicy.checkLocationPermission(mApp,
2513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2514 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002515 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 .setCallingPid(Binder.getCallingPid())
2517 .setCallingUid(Binder.getCallingUid())
2518 .setMethod("requestCellInfoUpdate")
2519 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2520 .build());
2521 switch (locationResult) {
2522 case DENIED_HARD:
2523 throw new SecurityException("Not allowed to access cell info");
2524 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002525 try {
2526 cb.onCellInfo(new ArrayList<CellInfo>());
2527 } catch (RemoteException re) {
2528 // Drop without consequences
2529 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002530 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002531 }
2532
Nathan Harolda939a962019-05-09 10:13:47 -07002533
2534 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002535 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2536
2537 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2538 }
2539
2540 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002542 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002547 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552
Shishir Agrawala9f32182016-04-12 12:00:16 -07002553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002554 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002555 Phone phone = PhoneFactory.getPhone(slotIndex);
2556 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 return null;
2558 }
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, "getImeiForSlot")) {
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.getImei();
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002571 }
2572
2573 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002574 public String getTypeAllocationCodeForSlot(int slotIndex) {
2575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 String tac = null;
2577 if (phone != null) {
2578 String imei = phone.getImei();
2579 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2580 }
2581 return tac;
2582 }
2583
2584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002585 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002586 Phone phone = PhoneFactory.getPhone(slotIndex);
2587 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002588 return null;
2589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002590
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002592 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 return null;
2595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 return phone.getMeid();
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Jack Yu2af8d712017-03-15 17:14:14 -07002603 }
2604
2605 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002606 public String getManufacturerCodeForSlot(int slotIndex) {
2607 Phone phone = PhoneFactory.getPhone(slotIndex);
2608 String manufacturerCode = null;
2609 if (phone != null) {
2610 String meid = phone.getMeid();
2611 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2612 }
2613 return manufacturerCode;
2614 }
2615
2616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002617 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2618 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002619 Phone phone = PhoneFactory.getPhone(slotIndex);
2620 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 return null;
2622 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002623 int subId = phone.getSubId();
2624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002625 mApp, subId, callingPackage, callingFeatureId,
2626 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002627 return null;
2628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 return phone.getDeviceSvn();
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002636 }
2637
fionaxu43304da2017-11-27 22:51:16 -08002638 @Override
2639 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
fionaxu43304da2017-11-27 22:51:16 -08002647 }
2648
2649 @Override
2650 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 return phone == null ? null : phone.getCarrierName();
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
fionaxu43304da2017-11-27 22:51:16 -08002658 }
2659
calvinpanffe225e2018-11-01 19:43:06 +08002660 @Override
chen xu0026ca62019-03-06 15:28:50 -08002661 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002666 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
2670 }
2671
2672 @Override
chen xu0026ca62019-03-06 15:28:50 -08002673 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002677 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
2681 }
2682
chen xu651eec72018-11-11 19:03:44 -08002683 @Override
chen xu864e11c2018-12-06 22:10:03 -08002684 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2685 if (!isSubscriptionMccMnc) {
2686 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2687 }
chen xu651eec72018-11-11 19:03:44 -08002688 final Phone phone = PhoneFactory.getPhone(slotIndex);
2689 if (phone == null) {
2690 return TelephonyManager.UNKNOWN_CARRIER_ID;
2691 }
2692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
2698 }
2699
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 //
2701 // Internal helper methods.
2702 //
2703
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002704 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceModifyPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2711 }
2712
Shuo Qiancd19c462020-01-16 20:51:11 -08002713 /**
2714 * Make sure the caller is system.
2715 *
2716 * @throws SecurityException if the caller is not system.
2717 */
2718 private void enforceSystemCaller() {
2719 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2720 throw new SecurityException("Caller must be system");
2721 }
2722 }
2723
Shuo Qian3b6ee772019-11-13 17:43:31 -08002724 private void enforceActiveEmergencySessionPermission() {
2725 mApp.enforceCallingOrSelfPermission(
2726 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2727 }
2728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 /**
2730 * Make sure the caller has the CALL_PHONE permission.
2731 *
2732 * @throws SecurityException if the caller does not have the required permission
2733 */
2734 private void enforceCallPermission() {
2735 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2736 }
2737
paulhu5a773602019-08-23 19:17:33 +08002738 private void enforceSettingsPermission() {
2739 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002740 }
2741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 private String createTelUrl(String number) {
2743 if (TextUtils.isEmpty(number)) {
2744 return null;
2745 }
2746
Jake Hambye994d462014-02-03 13:10:13 -08002747 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
2749
Ihab Awadf9e92732013-12-05 18:02:52 -08002750 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2752 }
2753
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002754 private static void logv(String msg) {
2755 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2756 }
2757
Ihab Awadf9e92732013-12-05 18:02:52 -08002758 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2760 }
2761
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002764 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002768 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 final Phone phone = PhoneFactory.getPhone(slotIndex);
2772 if (phone == null) {
2773 return PhoneConstants.PHONE_TYPE_NONE;
2774 } else {
2775 return phone.getPhoneType();
2776 }
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
2782 /**
2783 * Returns the CDMA ERI icon index to display
2784 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002786 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2787 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2788 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002792 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 mApp, subId, callingPackage, callingFeatureId,
2796 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002797 return -1;
2798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
2804 return phone.getCdmaEriIconIndex();
2805 } else {
2806 return -1;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
2813 /**
2814 * Returns the CDMA ERI icon mode,
2815 * 0 - ON
2816 * 1 - FLASHING
2817 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2820 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2821 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2826 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002828 mApp, subId, callingPackage, callingFeatureId,
2829 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002830 return -1;
2831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 return phone.getCdmaEriIconMode();
2838 } else {
2839 return -1;
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
2846 /**
2847 * Returns the CDMA ERI text,
2848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002850 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2851 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 mApp, subId, callingPackage, callingFeatureId,
2860 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002861 return null;
2862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 final Phone phone = getPhone(subId);
2867 if (phone != null) {
2868 return phone.getCdmaEriText();
2869 } else {
2870 return null;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
2877 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002878 * Returns the CDMA MDN.
2879 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002880 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002881 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2883 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002888 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 return phone.getLine1Number();
2890 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 return null;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002896 }
2897 }
2898
2899 /**
2900 * Returns the CDMA MIN.
2901 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002902 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002903 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2905 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2911 return phone.getCdmaMin();
2912 } else {
2913 return null;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002917 }
2918 }
2919
Hall Liud892bec2018-11-30 14:51:45 -08002920 @Override
2921 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2922 INumberVerificationCallback callback, String callingPackage) {
2923 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2924 != PERMISSION_GRANTED) {
2925 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2926 }
2927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2928
2929 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2930 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2931 throw new SecurityException("Calling package must be configured in the device config");
2932 }
2933
2934 if (range == null) {
2935 throw new NullPointerException("Range must be non-null");
2936 }
2937
2938 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002939 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002940
2941 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2942 }
2943
Junda Liuca05d5d2014-08-14 22:36:34 -07002944 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 * Returns true if CDMA provisioning needs to run.
2946 */
2947 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 final long identity = Binder.clearCallingIdentity();
2949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
2956 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002957 * Sets the voice mail number of a given subId.
2958 */
2959 @Override
2960 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002961 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2962 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2967 new Pair<String, String>(alphaTag, number), new Integer(subId));
2968 return success;
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002972 }
2973
Ta-wei Yen87c49842016-05-13 21:19:52 -07002974 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002975 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002977 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2978 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002979 if (!TextUtils.equals(callingPackage, systemDialer)) {
2980 throw new SecurityException("caller must be system dialer");
2981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2986 if (phoneAccountHandle == null) {
2987 return null;
2988 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002992 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002993 }
2994
2995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002996 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2997 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003000 mApp, subId, callingPackage, callingFeatureId,
3001 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003002 return null;
3003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003005 final long identity = Binder.clearCallingIdentity();
3006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003011 }
3012
3013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003014 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3015 VisualVoicemailSmsFilterSettings settings) {
3016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003021 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003025 }
3026
3027 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003028 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003038 }
3039
3040 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003041 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3042 String callingPackage, int subId) {
3043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003052 }
3053
3054 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003055 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003065 }
3066
3067 @Override
3068 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3069 String number, int port, String text, PendingIntent sentIntent) {
3070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003071 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003072 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003073 SmsController smsController = PhoneFactory.getSmsController();
3074 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3075 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003076 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003077
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003078 /**
fionaxu0152e512016-11-14 13:36:14 -08003079 * Sets the voice activation state of a given subId.
3080 */
3081 @Override
3082 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3084 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 final Phone phone = getPhone(subId);
3089 if (phone != null) {
3090 phone.setVoiceActivationState(activationState);
3091 } else {
3092 loge("setVoiceActivationState fails with invalid subId: " + subId);
3093 }
3094 } finally {
3095 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003096 }
3097 }
3098
3099 /**
3100 * Sets the data activation state of a given subId.
3101 */
3102 @Override
3103 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3105 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 final Phone phone = getPhone(subId);
3110 if (phone != null) {
3111 phone.setDataActivationState(activationState);
3112 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003113 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003117 }
3118 }
3119
3120 /**
3121 * Returns the voice activation state of a given subId.
3122 */
3123 @Override
3124 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126
fionaxu0152e512016-11-14 13:36:14 -08003127 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 if (phone != null) {
3131 return phone.getVoiceActivationState();
3132 } else {
3133 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003137 }
3138 }
3139
3140 /**
3141 * Returns the data activation state of a given subId.
3142 */
3143 @Override
3144 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146
fionaxu0152e512016-11-14 13:36:14 -08003147 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 if (phone != null) {
3151 return phone.getDataActivationState();
3152 } else {
3153 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003157 }
3158 }
3159
3160 /**
Wink Saville36469e72014-06-11 15:17:00 -07003161 * Returns the unread count of voicemails for a subId
3162 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003164 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3165 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003167 mApp, subId, callingPackage, callingFeatureId,
3168 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003169 return 0;
3170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = getPhone(subId);
3174 if (phone != null) {
3175 return phone.getVoiceMessageCount();
3176 } else {
3177 return 0;
3178 }
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 }
3183
3184 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003185 * returns true, if the device is in a state where both voice and data
3186 * are supported simultaneously. This can change based on location or network condition.
3187 */
3188 @Override
3189 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 final Phone phone = getPhone(subId);
3193 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003197 }
3198
3199 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003200 * Send the dialer code if called from the current default dialer or the caller has
3201 * carrier privilege.
3202 * @param inputCode The dialer code to send
3203 */
3204 @Override
3205 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003207 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003208 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3209 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003210 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003211 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003212 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
fionaxu235cc5e2017-03-06 22:25:57 -08003221 }
3222
Pengquan Menga1bb6272018-09-06 09:59:22 -07003223 @Override
3224 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003225 TelephonyPermissions
3226 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3227 mApp, subId, "getNetworkSelectionMode");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 if (!isActiveSubscription(subId)) {
3231 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3232 }
3233 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003236 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003237 }
3238
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003240 public boolean isInEmergencySmsMode() {
3241 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 for (Phone phone : PhoneFactory.getPhones()) {
3245 if (phone.isInEmergencySmsMode()) {
3246 return true;
3247 }
3248 }
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
3251 }
3252 return false;
3253 }
3254
shilu366312e2019-12-17 09:28:10 -08003255 /**
3256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3257 * @param subId The subscription to use to check the configuration.
3258 * @param c The callback that will be used to send the result.
3259 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003260 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003261 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3262 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003263 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3264 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003265
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003266 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3267 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3268 "IMS not available on device.");
3269 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 final long token = Binder.clearCallingIdentity();
3271 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003272 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003275 } catch (ImsException e) {
3276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 } finally {
3278 Binder.restoreCallingIdentity(token);
3279 }
3280 }
3281
shilu366312e2019-12-17 09:28:10 -08003282 /**
3283 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3284 * @param subId The subscription to use to check the configuration.
3285 * @param c The callback that will be used to send the result.
3286 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003287 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003288 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003289 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3290 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003291 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3292 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3293 }
Meng Wangafbc5852019-09-19 17:37:13 -07003294 final long token = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3297 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3298 .removeRegistrationCallbackForSubscription(c, subId);
3299 } catch (ImsException e) {
3300 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3301 + "is inactive, ignoring unregister.");
3302 // If the subscription is no longer active, just return, since the callback
3303 // will already have been removed internally.
3304 } finally {
3305 Binder.restoreCallingIdentity(token);
3306 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 }
3308
Brad Ebingera34a6c22019-10-22 17:36:18 -07003309 /**
3310 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3311 */
3312 @Override
3313 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3314 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3315 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3316 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3317 "IMS not available on device.");
3318 }
3319 final long token = Binder.clearCallingIdentity();
3320 try {
3321 Phone phone = getPhone(subId);
3322 if (phone == null) {
3323 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3324 + subId + "'");
3325 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3326 }
3327 phone.getImsRegistrationState(regState -> {
3328 try {
3329 consumer.accept((regState == null)
3330 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3331 } catch (RemoteException e) {
3332 // Ignore if the remote process is no longer available to call back.
3333 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3334 }
3335 });
3336 } finally {
3337 Binder.restoreCallingIdentity(token);
3338 }
3339 }
3340
3341 /**
3342 * Get the transport type for the IMS service registration state.
3343 */
3344 @Override
3345 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003346 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3347 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003348 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3349 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3350 "IMS not available on device.");
3351 }
3352 final long token = Binder.clearCallingIdentity();
3353 try {
3354 Phone phone = getPhone(subId);
3355 if (phone == null) {
3356 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3357 + subId + "'");
3358 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3359 }
3360 phone.getImsRegistrationTech(regTech -> {
3361 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3362 int regTechConverted = (regTech == null)
3363 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3364 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3365 regTechConverted);
3366 try {
3367 consumer.accept(regTechConverted);
3368 } catch (RemoteException e) {
3369 // Ignore if the remote process is no longer available to call back.
3370 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3371 }
3372 });
3373 } finally {
3374 Binder.restoreCallingIdentity(token);
3375 }
3376 }
3377
shilu366312e2019-12-17 09:28:10 -08003378 /**
3379 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3380 * @param subId The subscription to use to check the configuration.
3381 * @param c The callback that will be used to send the result.
3382 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3385 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003386 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3387 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003388 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3389 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3390 "IMS not available on device.");
3391 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3393 final long token = Binder.clearCallingIdentity();
3394 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003397 } catch (ImsException e) {
3398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 } finally {
3400 Binder.restoreCallingIdentity(token);
3401 }
3402 }
3403
shilu366312e2019-12-17 09:28:10 -08003404 /**
3405 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3406 * @param subId The subscription to use to check the configuration.
3407 * @param c The callback that will be used to send the result.
3408 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003410 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003411 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3412 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003413 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3414 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3415 }
Meng Wangafbc5852019-09-19 17:37:13 -07003416
3417 final long token = Binder.clearCallingIdentity();
3418 try {
3419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3420 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003421 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003422 } catch (ImsException e) {
3423 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3424 + "is inactive, ignoring unregister.");
3425 // If the subscription is no longer active, just return, since the callback
3426 // will already have been removed internally.
3427 } finally {
3428 Binder.restoreCallingIdentity(token);
3429 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 }
3431
3432 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003433 public boolean isCapable(int subId, int capability, int regTech) {
3434 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3436 final long token = Binder.clearCallingIdentity();
3437 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003440 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3442 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003444 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3445 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 } finally {
3447 Binder.restoreCallingIdentity(token);
3448 }
3449 }
3450
3451 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003452 public boolean isAvailable(int subId, int capability, int regTech) {
3453 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 final long token = Binder.clearCallingIdentity();
3455 try {
3456 Phone phone = getPhone(subId);
3457 if (phone == null) return false;
3458 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003459 } catch (com.android.ims.ImsException e) {
3460 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3461 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 } finally {
3463 Binder.restoreCallingIdentity(token);
3464 }
3465 }
3466
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003467 /**
3468 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3469 * subscription.
3470 * @param subId The subscription to use to check the configuration.
3471 * @param callback The callback that will be used to send the result.
3472 * @param capability The MmTelFeature capability that will be used to send the result.
3473 * @param transportType The transport type of the MmTelFeature capability.
3474 */
3475 @Override
3476 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3477 int transportType) {
3478 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3479 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3480 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3481 "IMS not available on device.");
3482 }
3483 final long token = Binder.clearCallingIdentity();
3484 try {
3485 int slotId = getSlotIndex(subId);
3486 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3487 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3488 + subId + "'");
3489 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3490 }
3491 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3492 transportType, aBoolean -> {
3493 try {
3494 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3495 } catch (RemoteException e) {
3496 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3497 + "running. Ignore");
3498 }
3499 });
3500 } finally {
3501 Binder.restoreCallingIdentity(token);
3502 }
3503 }
3504
shilu366312e2019-12-17 09:28:10 -08003505 /**
3506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3507 * @param subId The subscription to use to check the configuration.
3508 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 @Override
3510 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003511 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3512 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003513
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3515 final long token = Binder.clearCallingIdentity();
3516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003517 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (ImsException e) {
3520 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 } finally {
3522 Binder.restoreCallingIdentity(token);
3523 }
3524 }
3525
3526 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003527 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003529 "setAdvancedCallingSettingEnabled");
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,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003535 } catch (ImsException e) {
3536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
3540 }
3541
shilu366312e2019-12-17 09:28:10 -08003542 /**
3543 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3544 * @param subId The subscription to use to check the configuration.
3545 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003547 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003548 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3549 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003553 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3554 } 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 setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003564 "setVtSettingEnabled");
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)).setVtSetting(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 isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003582 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3583 mApp, subId, "isVoWiFiSettingEnabled");
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)).isWfcEnabledByUser();
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 setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003599 "setVoWiFiSettingEnabled");
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, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003604 } catch (ImsException e) {
3605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 } finally {
3607 Binder.restoreCallingIdentity(identity);
3608 }
3609 }
3610
shilu366312e2019-12-17 09:28:10 -08003611 /**
3612 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3613 * @param subId The subscription to use to check the configuration.
3614 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 @Override
3616 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003617 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3618 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003624 } catch (ImsException e) {
3625 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
3629 }
3630
3631 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003632 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003634 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003638 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003640 } catch (ImsException e) {
3641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
3645 }
3646
3647 @Override
3648 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3650 "setVoWiFiNonPersistent");
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003655 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003656 } catch (ImsException e) {
3657 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
3661 }
3662
shilu366312e2019-12-17 09:28:10 -08003663 /**
3664 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3665 * @param subId The subscription to use to check the configuration.
3666 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003667 @Override
3668 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003669 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3670 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (ImsException e) {
3677 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
3681 }
3682
3683 @Override
3684 public void setVoWiFiModeSetting(int subId, int mode) {
3685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3686 "setVoWiFiModeSetting");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003692 } catch (ImsException e) {
3693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
3700 public int getVoWiFiRoamingModeSetting(int subId) {
3701 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003705 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003707 } catch (ImsException e) {
3708 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
3712 }
3713
3714 @Override
3715 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3717 "setVoWiFiRoamingModeSetting");
3718 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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
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
3730 @Override
3731 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3733 "setRttCapabilityEnabled");
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003737 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3738 } catch (ImsException e) {
3739 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
3743 }
3744
shilu366312e2019-12-17 09:28:10 -08003745 /**
3746 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3747 * @param subId The subscription to use to check the configuration.
3748 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 @Override
3750 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003751 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3752 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
3759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
3763 }
3764
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003765 @Override
3766 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3767 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003770 if (!isImsAvailableOnDevice()) {
3771 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3772 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003773 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003775 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003776 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003777 } catch (ImsException e) {
3778 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003779 } finally {
3780 Binder.restoreCallingIdentity(identity);
3781 }
3782 }
3783
3784 @Override
3785 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3786 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3787 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3790 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003791 try {
3792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003794 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003796 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3797 + "is inactive, ignoring unregister.");
3798 // If the subscription is no longer active, just return, since the callback will already
3799 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
3803 }
3804
allenwtsu99c623b2020-01-03 18:24:23 +08003805
3806 private void checkModifyPhoneStatePermission(int subId, String message) {
3807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3808 message);
3809 }
3810
3811 private boolean isImsProvisioningRequired(int subId, int capability,
3812 boolean isMmtelCapability) {
3813 Phone phone = getPhone(subId);
3814 if (phone == null) {
3815 loge("phone instance null for subid " + subId);
3816 return false;
3817 }
3818 if (isMmtelCapability) {
3819 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3820 return false;
3821 }
3822 } else {
3823 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3824 return false;
3825 }
3826 }
3827 return true;
3828 }
3829
3830 @Override
3831 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3832 boolean isProvisioned) {
3833 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3834
3835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3838 if (!isImsProvisioningRequired(subId, capability, false)) {
3839 return;
3840 }
3841
3842 // this capability requires provisioning, route to the correct API.
3843 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3844 switch (capability) {
3845 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3846 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3847 ims.setEabProvisioned(isProvisioned);
3848 break;
3849 default: {
3850 throw new IllegalArgumentException("Tried to set provisioning for "
3851 + "rcs capability '" + capability + "', which does not require "
3852 + "provisioning.");
3853 }
3854 }
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
3858
3859 }
3860
3861
3862 @Override
3863 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3864 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3868 if (!isImsProvisioningRequired(subId, capability, false)) {
3869 return true;
3870 }
3871
3872 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3873 switch (capability) {
3874 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3875 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3876 return ims.isEabProvisionedOnDevice();
3877
3878 default: {
3879 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3880 + "capability '" + capability + "', which does not require "
3881 + "provisioning.");
3882 }
3883 }
3884
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
3888 }
3889
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003890 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003891 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3892 boolean isProvisioned) {
3893 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3894 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3895 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3896 }
allenwtsu99c623b2020-01-03 18:24:23 +08003897 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003901 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003902 return;
3903 }
3904
3905 // this capability requires provisioning, route to the correct API.
3906 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3907 switch (capability) {
3908 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3909 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3910 ims.setVolteProvisioned(isProvisioned);
3911 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3912 ims.setWfcProvisioned(isProvisioned);
3913 }
3914 break;
3915 }
3916 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3917 // There is currently no difference in VT provisioning type.
3918 ims.setVtProvisioned(isProvisioned);
3919 break;
3920 }
3921 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3922 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3923 // change the capability of the feature instead if needed.
3924 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3925 == isProvisioned) {
3926 // No change in provisioning.
3927 return;
3928 }
3929 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3930 try {
3931 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003932 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003933 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3934 + ", Exception" + e.getMessage());
3935 }
3936 break;
3937 }
3938 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003939 throw new IllegalArgumentException("Tried to set provisioning for "
3940 + "MmTel capability '" + capability + "', which does not require "
3941 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003942 }
3943 }
3944
3945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
3948 }
3949
3950 @Override
3951 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3952 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3953 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3954 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3955 }
3956 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003960 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003961 return true;
3962 }
3963
3964 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3965 switch (capability) {
3966 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3967 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3968 return ims.isVolteProvisionedOnDevice();
3969 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3970 return ims.isWfcProvisionedOnDevice();
3971 }
3972 // This should never happen, since we are checking tech above to make sure it
3973 // is either LTE or IWLAN.
3974 throw new IllegalArgumentException("Invalid radio technology for voice "
3975 + "capability.");
3976 }
3977 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3978 // There is currently no difference in VT provisioning type.
3979 return ims.isVtProvisionedOnDevice();
3980 }
3981 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3982 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3983 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3984 }
3985 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003986 throw new IllegalArgumentException(
3987 "Tried to get provisioning for MmTel capability '" + capability
3988 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003989 }
3990 }
3991
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 }
3996
3997 @Override
3998 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3999 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4000 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4001 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4002 }
4003 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4004 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4005 return (provisionedBits & capability) > 0;
4006 }
4007
4008 @Override
4009 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4010 boolean isProvisioned) {
4011 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4012 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4013 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4014 }
4015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4016 "setProvisioningStatusForCapability");
4017 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4018 // If the current provisioning status for capability already matches isProvisioned,
4019 // do nothing.
4020 if (((provisionedBits & capability) > 0) == isProvisioned) {
4021 return;
4022 }
4023 if (isProvisioned) {
4024 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4025 } else {
4026 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4027 }
4028 }
4029
4030 /**
4031 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4032 * technology. The bitfield should mirror the bitfield defined by
4033 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4034 */
4035 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4036 String key = getMmTelProvisioningKey(subId, tech);
4037 // Default is no capabilities are provisioned.
4038 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4039 }
4040
4041 /**
4042 * Sets the MmTel capability provisioning bitfield (defined by
4043 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4044 * technology specified.
4045 *
4046 * Note: This is a synchronous command and should not be called on UI thread.
4047 */
4048 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4049 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4050 String key = getMmTelProvisioningKey(subId, tech);
4051 editor.putInt(key, newField);
4052 editor.commit();
4053 }
4054
4055 private static String getMmTelProvisioningKey(int subId, int tech) {
4056 // resulting key is provision_ims_mmtel_{subId}_{tech}
4057 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4058 }
4059
4060 /**
4061 * Query CarrierConfig to see if the specified capability requires provisioning for the
4062 * carrier associated with the subscription id.
4063 */
4064 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4065 int capability) {
4066 CarrierConfigManager configManager = new CarrierConfigManager(context);
4067 PersistableBundle c = configManager.getConfigForSubId(subId);
4068 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004069 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004070 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4071 false);
4072 boolean requireVoiceVtProvisioning = c.getBoolean(
4073 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4074
4075 // First check to make sure that the capability requires provisioning.
4076 switch (capability) {
4077 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4078 // intentional fallthrough
4079 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4080 if (requireVoiceVtProvisioning) {
4081 // Voice and Video requires provisioning
4082 return true;
4083 }
4084 break;
4085 }
4086 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4087 if (requireUtProvisioning) {
4088 // UT requires provisioning
4089 return true;
4090 }
4091 break;
4092 }
4093 }
4094 return false;
4095 }
4096
allenwtsu99c623b2020-01-03 18:24:23 +08004097 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4098 int capability) {
4099 CarrierConfigManager configManager = new CarrierConfigManager(context);
4100 PersistableBundle c = configManager.getConfigForSubId(subId);
4101
4102 boolean requireRcsProvisioning = c.getBoolean(
4103 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4104
4105 // First check to make sure that the capability requires provisioning.
4106 switch (capability) {
4107 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4108 // intentional fallthrough
4109 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4110 if (requireRcsProvisioning) {
4111 // OPTION or PRESENCE requires provisioning
4112 return true;
4113 }
4114 break;
4115 }
4116 }
4117 return false;
4118 }
4119
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004120 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004121 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004122 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4123 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4124 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004125 enforceReadPrivilegedPermission("getImsProvisioningInt");
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004129 int slotId = getSlotIndex(subId);
4130 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4131 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4132 + subId + "' for key:" + key);
4133 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4134 }
4135 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004137 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4138 + subId + "' for key:" + key);
4139 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
4143 }
4144
4145 @Override
4146 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4148 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4149 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004150 enforceReadPrivilegedPermission("getImsProvisioningString");
4151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004154 int slotId = getSlotIndex(subId);
4155 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4156 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4157 + subId + "' for key:" + key);
4158 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4159 }
4160 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004162 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4163 + subId + "' for key:" + key);
4164 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
4170 @Override
4171 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004172 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4173 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4174 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4176 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 int slotId = getSlotIndex(subId);
4181 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4182 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4183 + subId + "' for key:" + key);
4184 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4185 }
4186 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004188 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4189 + "' for key:" + key);
4190 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
4194 }
4195
4196 @Override
4197 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4199 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4200 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4202 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004206 int slotId = getSlotIndex(subId);
4207 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4208 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4209 + subId + "' for key:" + key);
4210 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4211 }
4212 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004213 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004214 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4215 + "' for key:" + key);
4216 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004217 } finally {
4218 Binder.restoreCallingIdentity(identity);
4219 }
4220 }
4221
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 int slotId = SubscriptionManager.getSlotIndex(subId);
4224 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4226 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 }
4228 return slotId;
4229 }
4230
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004231 private int getSlotIndex(int subId) {
4232 int slotId = SubscriptionManager.getSlotIndex(subId);
4233 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4234 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4235 }
4236 return slotId;
4237 }
4238
Wink Saville36469e72014-06-11 15:17:00 -07004239 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004240 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004241 */
4242 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004243 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4244 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004245 final int targetSdk = getTargetSdk(callingPackage);
4246 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004247 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004248 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004249 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004250 mApp, subId, callingPackage, callingFeatureId,
4251 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004252 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4253 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 final Phone phone = getPhone(subId);
4258 if (phone != null) {
4259 return phone.getServiceState().getDataNetworkType();
4260 } else {
4261 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4262 }
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004266 }
4267
4268 /**
4269 * Returns the data network type
4270 */
4271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4273 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4274 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004275 }
4276
4277 /**
4278 * Returns the data network type for a subId
4279 */
4280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004281 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4282 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004284 mApp, subId, callingPackage, callingFeatureId,
4285 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004286 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4287 }
4288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 final Phone phone = getPhone(subId);
4292 if (phone != null) {
4293 return phone.getServiceState().getDataNetworkType();
4294 } else {
4295 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4296 }
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004300 }
4301
4302 /**
Wink Saville36469e72014-06-11 15:17:00 -07004303 * Returns the Voice network type for a subId
4304 */
4305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004306 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4307 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004309 mApp, subId, callingPackage, callingFeatureId,
4310 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004311 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4312 }
4313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 final Phone phone = getPhone(subId);
4317 if (phone != null) {
4318 return phone.getServiceState().getVoiceNetworkType();
4319 } else {
4320 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4321 }
4322 } finally {
4323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004325 }
4326
4327 /**
4328 * @return true if a ICC card is present
4329 */
4330 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004331 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004332 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4333 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004334 }
4335
4336 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004337 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004338 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004339 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004340 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 final Phone phone = PhoneFactory.getPhone(slotIndex);
4344 if (phone != null) {
4345 return phone.getIccCard().hasIccCard();
4346 } else {
4347 return false;
4348 }
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004352 }
4353
4354 /**
4355 * Return if the current radio is LTE on CDMA. This
4356 * is a tri-state return value as for a period of time
4357 * the mode may be unknown.
4358 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004359 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004360 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004361 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004362 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004364 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4365 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4366 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004367 }
4368
Sanket Padawe356d7632015-06-22 14:03:32 -07004369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004370 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4371 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004372 try {
4373 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4374 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004375 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4376 }
4377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 final Phone phone = getPhone(subId);
4381 if (phone == null) {
4382 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4383 } else {
4384 return phone.getLteOnCdmaMode();
4385 }
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004388 }
Wink Saville36469e72014-06-11 15:17:00 -07004389 }
4390
Wink Saville36469e72014-06-11 15:17:00 -07004391 /**
4392 * {@hide}
4393 * Returns Default subId, 0 in the case of single standby.
4394 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004395 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004396 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004397 }
4398
Shishir Agrawala9f32182016-04-12 12:00:16 -07004399 private int getSlotForDefaultSubscription() {
4400 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4401 }
4402
Wink Savilleb564aae2014-10-23 10:18:09 -07004403 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004404 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004405 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004406
Pengquan Menge92a50d2018-09-21 15:54:48 -07004407 private boolean isActiveSubscription(int subId) {
4408 return mSubscriptionController.isActiveSubId(subId);
4409 }
4410
Ihab Awadf2177b72013-11-25 13:33:23 -08004411 /**
4412 * @see android.telephony.TelephonyManager.WifiCallingChoices
4413 */
4414 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415 final long identity = Binder.clearCallingIdentity();
4416 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004417 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4419 getWhenToMakeWifiCallsDefaultPreference());
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004423 }
4424
4425 /**
4426 * @see android.telephony.TelephonyManager.WifiCallingChoices
4427 */
4428 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004432 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004437 }
4438
Sailesh Nepald1e68152013-12-12 19:08:02 -08004439 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004440 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004441 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004442 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004443
Jordan Liu4c733742019-02-28 12:03:40 -08004444 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4445 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4446 if (phoneId == -1) {
4447 throw new IllegalArgumentException("Given slot index: " + slotIndex
4448 + " does not correspond to an active phone");
4449 }
4450 return PhoneFactory.getPhone(phoneId);
4451 }
4452
Shishir Agrawal566b7612013-10-28 14:41:00 -07004453 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004454 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4455 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4457 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004459 if (DBG) {
4460 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4461 }
4462 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4463 p2);
4464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004465
Jordan Liu4c733742019-02-28 12:03:40 -08004466
4467 @Override
4468 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4469 int slotIndex, String callingPackage, String aid, int p2) {
4470 enforceModifyPermission();
4471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4472 if (DBG) {
4473 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4474 }
4475 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4476 callingPackage, aid, p2);
4477 }
4478
4479 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4480 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 if (TextUtils.equals(ISDR_AID, aid)) {
4484 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004485 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4486 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 if (bestComponent == null
4488 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4489 loge("The calling package is not allowed to access ISD-R.");
4490 throw new SecurityException(
4491 "The calling package is not allowed to access ISD-R.");
4492 }
Derek Tan740e1672017-06-27 14:56:27 -07004493 }
Derek Tan740e1672017-06-27 14:56:27 -07004494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004496 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4497 null /* workSource */);
4498 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 return response;
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004503 }
4504
4505 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004506 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4508 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004509 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4510 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4511 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004512
Jordan Liu4c733742019-02-28 12:03:40 -08004513 @Override
4514 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4515 enforceModifyPermission();
4516 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4517 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4518 channel);
4519 }
4520
4521 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 final long identity = Binder.clearCallingIdentity();
4523 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524 if (channel < 0) {
4525 return false;
4526 }
Jordan Liu4c733742019-02-28 12:03:40 -08004527 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4528 null /* workSource */);
4529 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 return success;
4531 } finally {
4532 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534 }
4535
4536 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004537 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004538 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4540 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004541 if (DBG) {
4542 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4543 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4544 + p3 + " data=" + data);
4545 }
4546 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4547 command, p1, p2, p3, data);
4548 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004549
Jordan Liu4c733742019-02-28 12:03:40 -08004550 @Override
4551 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4552 int command, int p1, int p2, int p3, String data) {
4553 enforceModifyPermission();
4554 if (DBG) {
4555 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4556 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4557 + p3 + " data=" + data);
4558 }
4559 return iccTransmitApduLogicalChannelWithPermission(
4560 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4561 data);
4562 }
4563
4564 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4565 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 final long identity = Binder.clearCallingIdentity();
4567 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004568 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 return "";
4570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004573 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4574 null /* workSource */);
4575 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 // Append the returned status code to the end of the response payload.
4578 String s = Integer.toHexString(
4579 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4580 if (response.payload != null) {
4581 s = IccUtils.bytesToHexString(response.payload) + s;
4582 }
4583 return s;
4584 } finally {
4585 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004587 }
Jake Hambye994d462014-02-03 13:10:13 -08004588
Evan Charltonc66da362014-05-16 14:06:40 -07004589 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004590 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4591 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4593 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004595 if (DBG) {
4596 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4597 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4598 }
4599 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4600 cla, command, p1, p2, p3, data);
4601 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004602
Jordan Liu4c733742019-02-28 12:03:40 -08004603 @Override
4604 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4605 int command, int p1, int p2, int p3, String data) {
4606 enforceModifyPermission();
4607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4608 if (DBG) {
4609 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4610 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4611 + " data=" + data);
4612 }
4613
4614 return iccTransmitApduBasicChannelWithPermission(
4615 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4616 p2, p3, data);
4617 }
4618
4619 // open APDU basic channel assuming the caller has sufficient permissions
4620 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4621 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4625 && TextUtils.equals(ISDR_AID, data)) {
4626 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004627 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4628 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 if (bestComponent == null
4630 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4631 loge("The calling package is not allowed to select ISD-R.");
4632 throw new SecurityException(
4633 "The calling package is not allowed to select ISD-R.");
4634 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004635 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004638 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4639 null /* workSource */);
4640 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 // Append the returned status code to the end of the response payload.
4643 String s = Integer.toHexString(
4644 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4645 if (response.payload != null) {
4646 s = IccUtils.bytesToHexString(response.payload) + s;
4647 }
4648 return s;
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004651 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004652 }
4653
4654 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004655 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004656 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4658 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 if (DBG) {
4663 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4664 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4665 }
4666
4667 IccIoResult response =
4668 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4669 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4670 subId);
4671
4672 if (DBG) {
4673 log("Exchange SIM_IO [R]" + response);
4674 }
4675
4676 byte[] result = null;
4677 int length = 2;
4678 if (response.payload != null) {
4679 length = 2 + response.payload.length;
4680 result = new byte[length];
4681 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4682 } else {
4683 result = new byte[length];
4684 }
4685
4686 result[length - 1] = (byte) response.sw2;
4687 result[length - 2] = (byte) response.sw1;
4688 return result;
4689 } finally {
4690 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004691 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004692 }
4693
Nathan Haroldb3014052017-01-25 15:57:32 -08004694 /**
4695 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4696 * on a particular subscription
4697 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004698 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4699 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004701 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004702 return null;
4703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 if (appType != TelephonyManager.APPTYPE_USIM
4708 && appType != TelephonyManager.APPTYPE_SIM) {
4709 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4710 return null;
4711 }
4712 Object response = sendRequest(
4713 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4714 if (response instanceof String[]) {
4715 return (String[]) response;
4716 }
yincheng zhao2737e882019-09-06 17:06:54 -07004717 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004719 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 } finally {
4721 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004722 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004723 }
4724
yincheng zhao2737e882019-09-06 17:06:54 -07004725 /**
4726 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4727 * subscription.
4728 *
4729 * @param subId the id of the subscription.
4730 * @param appType the uicc app type, must be USIM or SIM.
4731 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4732 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004733 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004734 * @return number of fplmns that is successfully written to the SIM.
4735 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004736 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4737 String callingFeatureId) {
4738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4739 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004740 if (DBG) logv("no permissions for setForbiddenplmns");
4741 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4742 }
4743 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4744 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4745 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4746 }
4747 if (fplmns == null) {
4748 throw new IllegalArgumentException("Fplmn List provided is null");
4749 }
4750 for (String fplmn : fplmns) {
4751 if (!CellIdentity.isValidPlmn(fplmn)) {
4752 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4753 }
4754 }
4755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 Object response = sendRequest(
4758 CMD_SET_FORBIDDEN_PLMNS,
4759 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4760 subId);
4761 return (int) response;
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
4765 }
4766
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004767 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004768 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4770 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4775 if (response.payload == null) {
4776 return "";
4777 }
Evan Charltonc66da362014-05-16 14:06:40 -07004778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 // Append the returned status code to the end of the response payload.
4780 String s = Integer.toHexString(
4781 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4782 s = IccUtils.bytesToHexString(response.payload) + s;
4783 return s;
4784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
Evan Charltonc66da362014-05-16 14:06:40 -07004787 }
4788
Jake Hambye994d462014-02-03 13:10:13 -08004789 /**
4790 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4791 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4792 *
4793 * @param itemID the ID of the item to read
4794 * @return the NV item as a String, or null on error.
4795 */
4796 @Override
4797 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4800 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801
4802 final long identity = Binder.clearCallingIdentity();
4803 try {
4804 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004805 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4807 return value;
4808 } finally {
4809 Binder.restoreCallingIdentity(identity);
4810 }
Jake Hambye994d462014-02-03 13:10:13 -08004811 }
4812
4813 /**
4814 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4815 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4816 *
4817 * @param itemID the ID of the item to read
4818 * @param itemValue the value to write, as a String
4819 * @return true on success; false on any failure
4820 */
4821 @Override
4822 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004823 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4825 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826
4827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4830 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004831 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4833 return success;
4834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
Jake Hambye994d462014-02-03 13:10:13 -08004837 }
4838
4839 /**
4840 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4841 * Used for device configuration by some CDMA operators.
4842 *
4843 * @param preferredRoamingList byte array containing the new PRL
4844 * @return true on success; false on any failure
4845 */
4846 @Override
4847 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4849 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850
4851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4854 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4855 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4856 return success;
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
Jake Hambye994d462014-02-03 13:10:13 -08004860 }
4861
4862 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004863 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004864 * Used for device configuration by some CDMA operators.
4865 *
chen xu6dac5ab2018-10-26 17:39:23 -07004866 * @param slotIndex - device slot.
4867 *
Jake Hambye994d462014-02-03 13:10:13 -08004868 * @return true on success; false on any failure
4869 */
4870 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004871 public boolean resetModemConfig(int slotIndex) {
4872 Phone phone = PhoneFactory.getPhone(slotIndex);
4873 if (phone != null) {
4874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4875 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876
chen xu6dac5ab2018-10-26 17:39:23 -07004877 final long identity = Binder.clearCallingIdentity();
4878 try {
4879 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4880 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4881 return success;
4882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885 }
chen xu6dac5ab2018-10-26 17:39:23 -07004886 return false;
4887 }
4888
4889 /**
4890 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4891 *
4892 * @param slotIndex - device slot.
4893 *
4894 * @return true on success; false on any failure
4895 */
4896 @Override
4897 public boolean rebootModem(int slotIndex) {
4898 Phone phone = PhoneFactory.getPhone(slotIndex);
4899 if (phone != null) {
4900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4901 mApp, phone.getSubId(), "rebootModem");
4902
4903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4906 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4907 return success;
4908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
4911 }
4912 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004913 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004914
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004915 public String[] getPcscfAddress(String apnType, String callingPackage,
4916 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004917 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4919 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004920 return new String[0];
4921 }
4922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004925 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
Wink Saville36469e72014-06-11 15:17:00 -07004929 }
4930
Brad Ebinger51f743a2017-01-23 13:50:20 -08004931 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004932 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4933 * {@link #disableIms(int)}.
4934 * @param slotIndex device slot.
4935 */
4936 public void resetIms(int slotIndex) {
4937 enforceModifyPermission();
4938
4939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 if (mImsResolver == null) {
4942 // may happen if the does not support IMS.
4943 return;
4944 }
4945 mImsResolver.disableIms(slotIndex);
4946 mImsResolver.enableIms(slotIndex);
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
4950 }
4951
4952 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004953 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4954 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004955 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004956 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958
4959 final long identity = Binder.clearCallingIdentity();
4960 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004961 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004962 // may happen if the device does not support IMS.
4963 return;
4964 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004965 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004969 }
4970
4971 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004972 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4973 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004974 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004975 public void disableIms(int slotId) {
4976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977
4978 final long identity = Binder.clearCallingIdentity();
4979 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004980 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004981 // may happen if the device does not support IMS.
4982 return;
4983 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004984 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004988 }
4989
4990 /**
4991 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4992 * feature or {@link null} if the service is not available. If the feature is available, the
4993 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4994 */
4995 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004996 IImsServiceFeatureCallback callback) {
4997 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998
4999 final long identity = Binder.clearCallingIdentity();
5000 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005001 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005002 // may happen if the device does not support IMS.
5003 return null;
5004 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005005 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 } finally {
5007 Binder.restoreCallingIdentity(identity);
5008 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005009 }
5010
5011 /**
5012 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5013 * feature during emergency calling or {@link null} if the service is not available. If the
5014 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5015 * listener for feature updates.
5016 */
5017 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5018 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019
5020 final long identity = Binder.clearCallingIdentity();
5021 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005022 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005023 // may happen if the device does not support IMS.
5024 return null;
5025 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005026 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 } finally {
5028 Binder.restoreCallingIdentity(identity);
5029 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005030 }
5031
Brad Ebinger5f64b052017-12-14 14:26:15 -08005032 /**
5033 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005034 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005035 */
5036 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5037 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038
5039 final long identity = Binder.clearCallingIdentity();
5040 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005041 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005042 // may happen if the device does not support IMS.
5043 return null;
5044 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005045 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005049 }
5050
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005051 /**
5052 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005053 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005054 */
5055 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005060 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005061 // may happen if the device does not support IMS.
5062 return null;
5063 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005064 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005068 }
5069
Brad Ebinger884c07b2018-02-15 16:17:40 -08005070 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005071 * Sets the ImsService Package Name that Telephony will bind to.
5072 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005073 * @param slotIndex the slot ID that the ImsService should bind for.
5074 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005075 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005076 * @param featureTypes An integer array of feature types associated with a packageName.
5077 * @param packageName The name of the package that the current configuration will be replaced
5078 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005079 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005081 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5082 int[] featureTypes, String packageName) {
5083 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5086 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005087 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005091 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005092 // may happen if the device does not support IMS.
5093 return false;
5094 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005095 Map<Integer, String> featureConfig = new HashMap<>();
5096 for (int featureType : featureTypes) {
5097 featureConfig.put(featureType, packageName);
5098 }
5099 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5100 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 } finally {
5102 Binder.restoreCallingIdentity(identity);
5103 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005104 }
5105
5106 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005107 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005108 *
5109 * @param slotId The slot that the ImsService is associated with.
5110 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5111 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005112 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005113 * @return the package name of the ImsService configuration.
5114 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005115 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5116 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005117 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005118 TelephonyPermissions
5119 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5120 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5121 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 final long identity = Binder.clearCallingIdentity();
5124 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005125 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005126 // may happen if the device does not support IMS.
5127 return "";
5128 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005129 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005130 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5131 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005135 }
5136
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005137 /**
5138 * Get the MmTelFeature state associated with the requested subscription id.
5139 * @param subId The subscription that the MmTelFeature is associated with.
5140 * @param callback A callback with an integer containing the
5141 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5142 */
5143 @Override
5144 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5145 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5146 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5147 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5148 "IMS not available on device.");
5149 }
5150 final long token = Binder.clearCallingIdentity();
5151 try {
5152 int slotId = getSlotIndex(subId);
5153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5154 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5155 + subId + "'");
5156 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5157 }
5158 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5159 try {
5160 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5161 } catch (RemoteException e) {
5162 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5163 + "Ignore");
5164 }
5165 });
5166 } finally {
5167 Binder.restoreCallingIdentity(token);
5168 }
5169 }
5170
Wink Saville36469e72014-06-11 15:17:00 -07005171 public void setImsRegistrationState(boolean registered) {
5172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173
5174 final long identity = Binder.clearCallingIdentity();
5175 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005176 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
Wink Saville36469e72014-06-11 15:17:00 -07005180 }
5181
5182 /**
Stuart Scott54788802015-03-30 13:18:01 -07005183 * Set the network selection mode to automatic.
5184 *
5185 */
5186 @Override
5187 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5189 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
shilufc958392020-01-20 11:36:01 -08005193 if (!isActiveSubscription(subId)) {
5194 return;
5195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5197 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Stuart Scott54788802015-03-30 13:18:01 -07005201 }
5202
Pengquan Mengea84e042018-09-20 14:57:26 -07005203 /**
5204 * Ask the radio to connect to the input network and change selection mode to manual.
5205 *
5206 * @param subId the id of the subscription.
5207 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5208 * the operator to attach to.
5209 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5210 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5211 * normal network selection next time.
5212 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005213 */
5214 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005215 public boolean setNetworkSelectionModeManual(
5216 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5218 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005219
5220 if (!isActiveSubscription(subId)) {
5221 return false;
5222 }
5223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005226 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005228 if (DBG) {
5229 log("setNetworkSelectionModeManual: subId: " + subId
5230 + " operator: " + operatorInfo);
5231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005236 }
shilu84f6e8b2019-12-19 13:58:01 -08005237 /**
5238 * Get the manual network selection
5239 *
5240 * @param subId the id of the subscription.
5241 *
5242 * @return the previously saved user selected PLMN
5243 */
5244 @Override
5245 public String getManualNetworkSelectionPlmn(int subId) {
5246 TelephonyPermissions
5247 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5248 mApp, subId, "getManualNetworkSelectionPlmn");
5249
5250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 if (!isActiveSubscription(subId)) {
5253 return "";
5254 }
5255
5256 final Phone phone = getPhone(subId);
5257 if (phone == null) {
5258 return "";
5259 }
5260 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5261 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5262 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
5266 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005267
5268 /**
5269 * Scans for available networks.
5270 */
5271 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005272 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5273 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5275 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005276 LocationAccessPolicy.LocationPermissionResult locationResult =
5277 LocationAccessPolicy.checkLocationPermission(mApp,
5278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5279 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005280 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005281 .setCallingPid(Binder.getCallingPid())
5282 .setCallingUid(Binder.getCallingUid())
5283 .setMethod("getCellNetworkScanResults")
5284 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5285 .build());
5286 switch (locationResult) {
5287 case DENIED_HARD:
5288 throw new SecurityException("Not allowed to access scan results -- location");
5289 case DENIED_SOFT:
5290 return null;
5291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292
Pengquan Menga1bb6272018-09-06 09:59:22 -07005293 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 try {
5295 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005296 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005301 }
5302
5303 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005304 * Get the call forwarding info, given the call forwarding reason.
5305 */
5306 @Override
5307 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5308 enforceReadPrivilegedPermission("getCallForwarding");
5309 long identity = Binder.clearCallingIdentity();
5310 try {
5311 if (DBG) {
5312 log("getCallForwarding: subId " + subId
5313 + " callForwardingReason" + callForwardingReason);
5314 }
5315 return (CallForwardingInfo) sendRequest(
5316 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
5320 }
5321
5322 /**
5323 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5324 * reason, the number to forward, and the timeout before the forwarding is attempted.
5325 */
5326 @Override
5327 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5328 enforceModifyPermission();
5329 long identity = Binder.clearCallingIdentity();
5330 try {
5331 if (DBG) {
5332 log("setCallForwarding: subId " + subId
5333 + " callForwardingInfo" + callForwardingInfo);
5334 }
5335 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
5339 }
5340
5341 /**
5342 * Get the call forwarding info, given the call forwarding reason.
5343 */
5344 @Override
5345 public int getCallWaitingStatus(int subId) {
5346 enforceReadPrivilegedPermission("getCallForwarding");
5347 long identity = Binder.clearCallingIdentity();
5348 try {
5349 if (DBG) log("getCallWaitingStatus: subId " + subId);
5350 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
5356 /**
5357 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5358 * reason, the number to forward, and the timeout before the forwarding is attempted.
5359 */
5360 @Override
5361 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5362 enforceModifyPermission();
5363 long identity = Binder.clearCallingIdentity();
5364 try {
5365 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5366 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
5369 }
5370 }
5371
5372 /**
yinxub1bed742017-04-17 11:45:04 -07005373 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005374 *
yinxub1bed742017-04-17 11:45:04 -07005375 * @param subId id of the subscription
5376 * @param request contains the radio access networks with bands/channels to scan
5377 * @param messenger callback messenger for scan results or errors
5378 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005379 * @return the id of the requested scan which can be used to stop the scan.
5380 */
5381 @Override
5382 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005383 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5385 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005386 LocationAccessPolicy.LocationPermissionResult locationResult =
5387 LocationAccessPolicy.checkLocationPermission(mApp,
5388 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5389 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005390 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005391 .setCallingPid(Binder.getCallingPid())
5392 .setCallingUid(Binder.getCallingUid())
5393 .setMethod("requestNetworkScan")
5394 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5395 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005396 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005397 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005398 if (e != null) {
5399 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5400 throw e;
5401 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005402 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005403 return TelephonyScanManager.INVALID_SCAN_ID;
5404 }
5405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 }
Hall Liu912dfd32019-04-25 14:02:26 -07005407 int callingUid = Binder.getCallingUid();
5408 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005409 final long identity = Binder.clearCallingIdentity();
5410 try {
5411 return mNetworkScanRequestTracker.startNetworkScan(
5412 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005413 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
yinxu504e1392017-04-12 16:03:22 -07005417 }
5418
Hall Liub2ac8ef2019-02-28 15:56:23 -08005419 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005420 NetworkScanRequest request, int subId) {
5421 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5422 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5423 boolean hasNetworkScanPermission =
5424 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5425 == PERMISSION_GRANTED;
5426
5427 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5428 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5429 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005430 }
5431
5432 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5433 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005434 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5435 return new SecurityException("Specific channels must not be"
5436 + " scanned without location access.");
5437 }
5438 }
5439 }
5440
Hall Liub2ac8ef2019-02-28 15:56:23 -08005441 return null;
5442 }
5443
yinxu504e1392017-04-12 16:03:22 -07005444 /**
5445 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005446 *
5447 * @param subId id of the subscription
5448 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005449 */
5450 @Override
5451 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5453 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454
Hall Liu912dfd32019-04-25 14:02:26 -07005455 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 final long identity = Binder.clearCallingIdentity();
5457 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005458 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
yinxu504e1392017-04-12 16:03:22 -07005462 }
5463
5464 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005465 * Get the calculated preferred network type.
5466 * Used for debugging incorrect network type.
5467 *
5468 * @return the preferred network type, defined in RILConstants.java.
5469 */
5470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005471 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005472 final Phone defaultPhone = getDefaultPhone();
5473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005474 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005475 return RILConstants.PREFERRED_NETWORK_MODE;
5476 }
5477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005481 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
5484 }
Junda Liu84d15a22014-07-02 11:21:04 -07005485 }
5486
5487 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005488 * Get the preferred network type.
5489 * Used for device configuration by some CDMA operators.
5490 *
5491 * @return the preferred network type, defined in RILConstants.java.
5492 */
5493 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005494 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005495 TelephonyPermissions
5496 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5497 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
5501 if (DBG) log("getPreferredNetworkType");
5502 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5503 int networkType = (result != null ? result[0] : -1);
5504 if (DBG) log("getPreferredNetworkType: " + networkType);
5505 return networkType;
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005509 }
5510
5511 /**
5512 * Set the preferred network type.
5513 * Used for device configuration by some CDMA operators.
5514 *
5515 * @param networkType the preferred network type, defined in RILConstants.java.
5516 * @return true on success; false on any failure.
5517 */
5518 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005519 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005525 Settings.Global.putInt(mApp.getContentResolver(),
5526 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5527 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005530 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005531 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005532
5533 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005534 * Get the allowed network types that store in the telephony provider.
5535 *
5536 * @param subId the id of the subscription.
5537 * @return allowedNetworkTypes the allowed network types.
5538 */
5539 @Override
5540 public long getAllowedNetworkTypes(int subId) {
5541 TelephonyPermissions
5542 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5543 mApp, subId, "getAllowedNetworkTypes");
5544
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 return SubscriptionManager.getLongSubscriptionProperty(
5548 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
5552 }
5553
5554 /**
5555 * Set the allowed network types.
5556 *
5557 * @param subId the id of the subscription.
5558 * @param allowedNetworkTypes the allowed network types.
5559 * @return true on success; false on any failure.
5560 */
5561 @Override
5562 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, subId, "setAllowedNetworkTypes");
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 SubscriptionManager.setSubscriptionProperty(subId,
5568 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5569 String.valueOf(allowedNetworkTypes));
5570 return setPreferredNetworkTypesInternal(subId);
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
5574 }
5575
5576 private boolean setPreferredNetworkTypesInternal(int subId) {
5577 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5578 Settings.Global.getInt(mApp.getContentResolver(),
5579 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5580 RILConstants.PREFERRED_NETWORK_MODE));
5581 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5582 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5583 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5584 (int) (networkTypeBitMask & allowedNetworkTypes));
5585
5586 if (DBG) {
5587 log("setPreferredNetworkTypesInternal: subId " + subId
5588 + " networkTypes " + networkTypeBitMask
5589 + " allowedNetworkTypes " + allowedNetworkTypes
5590 + " networkMode " + networkMode);
5591 }
5592
5593 Boolean success = (Boolean) sendRequest(
5594 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5595 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5596 return success;
5597 }
5598
5599 /**
Miaoa84611c2019-03-15 09:21:10 +08005600 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005601 *
Miaoa84611c2019-03-15 09:21:10 +08005602 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005603 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005604 * @hide
5605 */
5606 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005607 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005610 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 try {
Miaoa84611c2019-03-15 09:21:10 +08005612 if (phone != null) {
5613 return phone.hasMatchedTetherApnSetting();
5614 } else {
5615 return false;
5616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 } finally {
5618 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005619 }
Junda Liu475951f2014-11-07 16:45:03 -08005620 }
5621
5622 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005623 * Set mobile data enabled
5624 * Used by the user through settings etc to turn on/off mobile data
5625 *
5626 * @param enable {@code true} turn turn data on, else {@code false}
5627 */
5628 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005629 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 int phoneId = mSubscriptionController.getPhoneId(subId);
5636 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5637 Phone phone = PhoneFactory.getPhone(phoneId);
5638 if (phone != null) {
5639 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005640 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005642 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 }
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005646 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005647 }
5648
5649 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005650 * Enable or disable always reporting signal strength changes from radio.
5651 *
5652 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5653 */
5654 @Override
5655 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5656 enforceModifyPermission();
5657 enforceSystemCaller();
5658
5659 final long identity = Binder.clearCallingIdentity();
5660 final Phone phone = getPhone(subId);
5661 try {
5662 if (phone != null) {
5663 if (DBG) {
5664 log("setAlwaysReportSignalStrength: subId=" + subId
5665 + " isEnable=" + isEnable);
5666 }
5667 phone.setAlwaysReportSignalStrength(isEnable);
5668 } else {
5669 loge("setAlwaysReportSignalStrength: no phone found for subId="
5670 + subId);
5671 }
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 }
5676
5677 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005678 * Get the user enabled state of Mobile Data.
5679 *
5680 * TODO: remove and use isUserDataEnabled.
5681 * This can't be removed now because some vendor codes
5682 * calls through ITelephony directly while they should
5683 * use TelephonyManager.
5684 *
5685 * @return true on enabled
5686 */
5687 @Override
5688 public boolean getDataEnabled(int subId) {
5689 return isUserDataEnabled(subId);
5690 }
5691
5692 /**
5693 * Get whether mobile data is enabled per user setting.
5694 *
5695 * There are other factors deciding whether mobile data is actually enabled, but they are
5696 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005697 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005698 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005699 *
5700 * @return {@code true} if data is enabled else {@code false}
5701 */
5702 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005703 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005704 try {
5705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5706 null);
5707 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5709 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 int phoneId = mSubscriptionController.getPhoneId(subId);
5715 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5716 Phone phone = PhoneFactory.getPhone(phoneId);
5717 if (phone != null) {
5718 boolean retVal = phone.isUserDataEnabled();
5719 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5720 return retVal;
5721 } else {
5722 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5723 return false;
5724 }
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005727 }
5728 }
5729
5730 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005731 * Checks if the device is capable of mobile data by considering whether whether the
5732 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5733 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005734 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005735 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005736 */
5737 @Override
5738 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005739 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 int phoneId = mSubscriptionController.getPhoneId(subId);
5744 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5745 Phone phone = PhoneFactory.getPhone(phoneId);
5746 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005747 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5749 return retVal;
5750 } else {
5751 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5752 return false;
5753 }
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005756 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005757 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005758
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005759 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5760 Phone phone) {
5761 //load access rules from carrier configs, and check those as well: b/139133814
5762 SubscriptionController subController = SubscriptionController.getInstance();
5763 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5764 || subController == null) return privilegeFromSim;
5765
5766 int uid = Binder.getCallingUid();
5767 PackageManager pkgMgr = phone.getContext().getPackageManager();
5768 String[] packages = pkgMgr.getPackagesForUid(uid);
5769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5773 SubscriptionManager subManager = (SubscriptionManager)
5774 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5775 for (String pkg : packages) {
5776 if (subManager.canManageSubscription(subInfo, pkg)) {
5777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5778 }
5779 }
5780 return privilegeFromSim;
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
5784 }
5785
5786 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5787 String pkgName) {
5788 //load access rules from carrier configs, and check those as well: b/139133814
5789 SubscriptionController subController = SubscriptionController.getInstance();
5790 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5791 || subController == null) return privilegeFromSim;
5792
5793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5796 SubscriptionManager subManager = (SubscriptionManager)
5797 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5798 return subManager.canManageSubscription(subInfo, pkgName)
5799 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
5802 }
5803 }
5804
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005805 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005806 public int getCarrierPrivilegeStatus(int subId) {
5807 final Phone phone = getPhone(subId);
5808 if (phone == null) {
5809 loge("getCarrierPrivilegeStatus: Invalid subId");
5810 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5811 }
5812 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005813 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005814 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5816 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005817
5818 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5819 card.getCarrierPrivilegeStatusForCurrentTransaction(
5820 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005821 }
Junda Liu29340342014-07-10 15:23:27 -07005822
5823 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005824 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005825 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005826 final Phone phone = getPhone(subId);
5827 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005828 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005829 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5830 }
5831 UiccProfile profile =
5832 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5833 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005834 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005835 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5836 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005837 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005838 profile.getCarrierPrivilegeStatusForUid(
5839 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005840 }
5841
5842 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005843 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5844 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005846 }
5847
5848 int phoneId = SubscriptionManager.getPhoneId(subId);
5849 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005850 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005851 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005852 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5853 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005854 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5855 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5856 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005857 }
5858
5859 @Override
5860 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005861 if (TextUtils.isEmpty(pkgName))
5862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005863 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5864 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5865 UiccCard card = UiccController.getInstance().getUiccCard(i);
5866 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005867 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005868 continue;
5869 }
5870
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005871 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5872 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5873 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005874 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5875 break;
5876 }
5877 }
5878
5879 return result;
Junda Liu29340342014-07-10 15:23:27 -07005880 }
Derek Tan89e89d42014-07-08 17:00:10 -07005881
5882 @Override
Junda Liue64de782015-04-16 17:19:16 -07005883 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5884 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5885 loge("phoneId " + phoneId + " is not valid.");
5886 return null;
5887 }
5888 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005889 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005890 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005891 return null ;
5892 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005893 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005894 }
5895
Amith Yamasani6e118872016-02-19 12:53:51 -08005896 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005897 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005898 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005899 List<String> privilegedPackages = new ArrayList<>();
5900 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005901 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5902 // has UICC in that slot.
5903 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005904 if (card.hasCarrierPrivilegeRules()) {
5905 if (packages == null) {
5906 // Only check packages in user 0 for now
5907 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005908 PackageManager.MATCH_DISABLED_COMPONENTS
5909 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005910 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005911 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005912 }
5913 for (int p = packages.size() - 1; p >= 0; p--) {
5914 PackageInfo pkgInfo = packages.get(p);
5915 if (pkgInfo != null && pkgInfo.packageName != null
5916 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005917 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005918 privilegedPackages.add(pkgInfo.packageName);
5919 }
5920 }
5921 }
5922 }
5923 return privilegedPackages;
5924 }
5925
chen xuf7e9fe82019-05-09 19:31:02 -07005926 @Override
5927 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005928 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5929
5930 final long identity = Binder.clearCallingIdentity();
5931
chen xuf7e9fe82019-05-09 19:31:02 -07005932 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005933 try {
5934 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5935 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5936 }
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005939 }
5940 return privilegedPackages;
5941 }
5942
Wink Savilleb564aae2014-10-23 10:18:09 -07005943 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005944 final Phone phone = getPhone(subId);
5945 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005946 if (card == null) {
5947 loge("getIccId: No UICC");
5948 return null;
5949 }
5950 String iccId = card.getIccId();
5951 if (TextUtils.isEmpty(iccId)) {
5952 loge("getIccId: ICC ID is null or empty.");
5953 return null;
5954 }
5955 return iccId;
5956 }
5957
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005958 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005959 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5960 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005961 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005962 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 final String iccId = getIccId(subId);
5967 final Phone phone = getPhone(subId);
5968 if (phone == null) {
5969 return false;
5970 }
5971 final String subscriberId = phone.getSubscriberId();
5972
5973 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005974 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 + subscriberId + " to " + number);
5976 }
5977
5978 if (TextUtils.isEmpty(iccId)) {
5979 return false;
5980 }
5981
5982 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5983
5984 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5985 if (alphaTag == null) {
5986 editor.remove(alphaTagPrefKey);
5987 } else {
5988 editor.putString(alphaTagPrefKey, alphaTag);
5989 }
5990
5991 // Record both the line number and IMSI for this ICCID, since we need to
5992 // track all merged IMSIs based on line number
5993 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5994 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5995 if (number == null) {
5996 editor.remove(numberPrefKey);
5997 editor.remove(subscriberPrefKey);
5998 } else {
5999 editor.putString(numberPrefKey, number);
6000 editor.putString(subscriberPrefKey, subscriberId);
6001 }
6002
6003 editor.commit();
6004 return true;
6005 } finally {
6006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006007 }
Derek Tan7226c842014-07-02 17:42:23 -07006008 }
6009
6010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006011 public String getLine1NumberForDisplay(int subId, String callingPackage,
6012 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006013 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006015 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006016 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006017 return null;
6018 }
Derek Tan97ebb422014-09-05 16:55:38 -07006019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 final long identity = Binder.clearCallingIdentity();
6021 try {
6022 String iccId = getIccId(subId);
6023 if (iccId != null) {
6024 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6025 if (DBG_MERGE) {
6026 log("getLine1NumberForDisplay returning "
6027 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6028 }
6029 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6032 return null;
6033 } finally {
6034 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006035 }
Derek Tan7226c842014-07-02 17:42:23 -07006036 }
6037
6038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006039 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6040 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006042 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006043 return null;
6044 }
Derek Tan97ebb422014-09-05 16:55:38 -07006045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 String iccId = getIccId(subId);
6049 if (iccId != null) {
6050 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6051 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6052 }
6053 return null;
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006056 }
Derek Tan7226c842014-07-02 17:42:23 -07006057 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006058
6059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006060 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6061 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006062 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6063 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006065 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006066 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006067 return null;
6068 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006069
Jordan Liub49b04b2019-05-06 14:45:15 -07006070 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6071 // the process, where TelephonyManager was instantiated.
6072 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006073 final long identity = Binder.clearCallingIdentity();
6074 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006075 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 final TelephonyManager tele = TelephonyManager.from(context);
6077 final SubscriptionManager sub = SubscriptionManager.from(context);
6078
6079 // Figure out what subscribers are currently active
6080 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081
Jordan Liub49b04b2019-05-06 14:45:15 -07006082 // Only consider subs which match the current subId
6083 // This logic can be simplified. See b/131189269 for progress.
6084 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006085 activeSubscriberIds.add(tele.getSubscriberId(subId));
6086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087
6088 // First pass, find a number override for an active subscriber
6089 String mergeNumber = null;
6090 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6091 for (String key : prefs.keySet()) {
6092 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6093 final String subscriberId = (String) prefs.get(key);
6094 if (activeSubscriberIds.contains(subscriberId)) {
6095 final String iccId = key.substring(
6096 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6097 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6098 mergeNumber = (String) prefs.get(numberKey);
6099 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006100 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 + " for active subscriber " + subscriberId);
6102 }
6103 if (!TextUtils.isEmpty(mergeNumber)) {
6104 break;
6105 }
6106 }
6107 }
6108 }
6109
6110 // Shortcut when no active merged subscribers
6111 if (TextUtils.isEmpty(mergeNumber)) {
6112 return null;
6113 }
6114
6115 // Second pass, find all subscribers under that line override
6116 final ArraySet<String> result = new ArraySet<>();
6117 for (String key : prefs.keySet()) {
6118 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6119 final String number = (String) prefs.get(key);
6120 if (mergeNumber.equals(number)) {
6121 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6122 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6123 final String subscriberId = (String) prefs.get(subscriberKey);
6124 if (!TextUtils.isEmpty(subscriberId)) {
6125 result.add(subscriberId);
6126 }
6127 }
6128 }
6129 }
6130
6131 final String[] resultArray = result.toArray(new String[result.size()]);
6132 Arrays.sort(resultArray);
6133 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006134 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6136 }
6137 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006138 } finally {
6139 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006140 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006141 }
6142
6143 @Override
zoey chen38003472019-12-13 17:16:31 +08006144 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6145 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006146
6147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 final TelephonyManager telephonyManager = mApp.getSystemService(
6150 TelephonyManager.class);
6151 String subscriberId = telephonyManager.getSubscriberId(subId);
6152 if (subscriberId == null) {
6153 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006154 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006155 + subId);
6156 }
6157 return null;
6158 }
6159
6160 final SubscriptionInfo info = SubscriptionController.getInstance()
6161 .getSubscriptionInfo(subId);
6162 final ParcelUuid groupUuid = info.getGroupUuid();
6163 // If it doesn't belong to any group, return just subscriberId of itself.
6164 if (groupUuid == null) {
6165 return new String[]{subscriberId};
6166 }
6167
6168 // Get all subscriberIds from the group.
6169 final List<String> mergedSubscriberIds = new ArrayList<>();
6170 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006171 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006172 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006173 for (SubscriptionInfo subInfo : groupInfos) {
6174 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6175 if (subscriberId != null) {
6176 mergedSubscriberIds.add(subscriberId);
6177 }
6178 }
6179
6180 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
6183
6184 }
6185 }
6186
6187 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006188 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006190 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191
6192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 final Phone phone = getPhone(subId);
6195 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006199 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006200
6201 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006202 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006203 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6204 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006205 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6206 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207
6208 final long identity = Binder.clearCallingIdentity();
6209 try {
6210 final Phone phone = getPhone(subId);
6211 if (phone == null) {
6212 return false;
6213 }
6214 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6215 cdmaNonRoamingList);
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006218 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006219 }
6220
6221 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006222 @Deprecated
6223 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6224 enforceModifyPermission();
6225
6226 int returnValue = 0;
6227 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006228 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006229 if(result.exception == null) {
6230 if (result.result != null) {
6231 byte[] responseData = (byte[])(result.result);
6232 if(responseData.length > oemResp.length) {
6233 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6234 responseData.length + "bytes. Buffer Size is " +
6235 oemResp.length + "bytes.");
6236 }
6237 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6238 returnValue = responseData.length;
6239 }
6240 } else {
6241 CommandException ex = (CommandException) result.exception;
6242 returnValue = ex.getCommandError().ordinal();
6243 if(returnValue > 0) returnValue *= -1;
6244 }
6245 } catch (RuntimeException e) {
6246 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6247 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6248 if(returnValue > 0) returnValue *= -1;
6249 }
6250
6251 return returnValue;
6252 }
6253
6254 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006255 public void setRadioCapability(RadioAccessFamily[] rafs) {
6256 try {
6257 ProxyController.getInstance().setRadioCapability(rafs);
6258 } catch (RuntimeException e) {
6259 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6260 }
6261 }
6262
6263 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006264 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006265 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006266 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006267 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006268 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
chen xub97461a2018-10-26 14:17:57 -07006272 TelephonyPermissions
6273 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6274 mApp, phone.getSubId(), "getRadioAccessFamily");
6275 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 } finally {
6277 Binder.restoreCallingIdentity(identity);
6278 }
chen xub97461a2018-10-26 14:17:57 -07006279 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006280 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006281
6282 @Override
6283 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006284 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006285 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
6287 final long identity = Binder.clearCallingIdentity();
6288 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006289 ImsManager.getInstance(defaultPhone.getContext(),
6290 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006294 }
6295
6296 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006297 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006298 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6300 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006301 return false;
6302 }
Svet Ganovb320e182015-04-16 12:30:10 -07006303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 final long identity = Binder.clearCallingIdentity();
6305 try {
6306 // Check the user preference and the system-level IMS setting. Even if the user has
6307 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6308 // In the long run, we may instead need to check if there exists a connection service
6309 // which can support video calling.
6310 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006311 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 return imsManager.isVtEnabledByPlatform()
6313 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6314 && imsManager.isVtEnabledByUser();
6315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006318 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006319
Andrew Leea1239f22015-03-02 17:44:07 -08006320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006321 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6322 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006324 mApp, subId, callingPackage, callingFeatureId,
6325 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 return false;
6327 }
6328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 CarrierConfigManager configManager =
6332 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006333 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Andrew Leea1239f22015-03-02 17:44:07 -08006338 }
6339
6340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006341 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006343 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 return false;
6345 }
6346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 CarrierConfigManager configManager =
6350 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006351 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
Andrew Leea1239f22015-03-02 17:44:07 -08006356 }
6357
Andrew Lee9431b832015-03-09 18:46:45 -07006358 @Override
6359 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006360 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006361 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006362 }
6363
6364 @Override
6365 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366 final long identity = Binder.clearCallingIdentity();
6367 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006368 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Andrew Lee9431b832015-03-09 18:46:45 -07006372 }
6373
Hall Liuf6668912018-10-31 17:05:23 -07006374 /**
6375 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6376 * support for the feature and device firmware support.
6377 *
6378 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6379 */
6380 @Override
6381 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006383 final Phone phone = getPhone(subscriptionId);
6384 if (phone == null) {
6385 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6386 return false;
6387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006389 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6391 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006392 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 return isCarrierSupported && isDeviceSupported;
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Hall Liu98187582018-01-22 19:15:32 -08006397 }
6398
Hall Liuf6668912018-10-31 17:05:23 -07006399 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006400 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6401 * RTT setting, will return true if the device and carrier both support RTT.
6402 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006403 */
6404 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 final long identity = Binder.clearCallingIdentity();
6406 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006407 boolean isRttSupported = isRttSupported(subscriptionId);
6408 boolean isUserRttSettingOn = Settings.Secure.getInt(
6409 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6410 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6411 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6412 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006416 }
6417
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006418 @Deprecated
6419 @Override
6420 public String getDeviceId(String callingPackage) {
6421 return getDeviceIdWithFeature(callingPackage, null);
6422 }
6423
Sanket Padawe7310cc72015-01-14 09:53:20 -08006424 /**
6425 * Returns the unique device ID of phone, for example, the IMEI for
6426 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6427 *
6428 * <p>Requires Permission:
6429 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6430 */
6431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006432 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006433 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006434 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006435 return null;
6436 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006437 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006438 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006439 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006440 return null;
6441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442
6443 final long identity = Binder.clearCallingIdentity();
6444 try {
6445 return phone.getDeviceId();
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006449 }
6450
Ping Sunc67b7c22016-03-02 19:16:45 +08006451 /**
6452 * {@hide}
6453 * Returns the IMS Registration Status on a particular subid
6454 *
6455 * @param subId
6456 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006457 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006458 Phone phone = getPhone(subId);
6459 if (phone != null) {
6460 return phone.isImsRegistered();
6461 } else {
6462 return false;
6463 }
6464 }
6465
Santos Cordon7a1885b2015-02-03 11:15:19 -08006466 @Override
6467 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006474 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006475
Tyler Gunnf70ed162019-04-03 15:28:53 -07006476 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006477 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006478 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006480 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006481 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6482 }
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006492 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 Phone phone = getPhone(subscriptionId);
6496 if (phone == null) {
6497 return null;
6498 }
6499 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
6503 }
6504
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006505 /**
6506 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006507 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006508 public boolean isWifiCallingAvailable(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.isWifiCallingEnabled();
6514 } else {
6515 return false;
6516 }
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006519 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006520 }
6521
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006522 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006523 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006524 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006525 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 Phone phone = getPhone(subId);
6529 if (phone != null) {
6530 return phone.isVideoEnabled();
6531 } else {
6532 return false;
6533 }
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006536 }
6537 }
6538
6539 /**
6540 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6541 * defined in {@link ImsRegistrationImplBase}.
6542 */
6543 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 Phone phone = getPhone(subId);
6547 if (phone != null) {
6548 return phone.getImsRegistrationTech();
6549 } else {
6550 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6551 }
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006554 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006555 }
6556
Stuart Scott8eef64f2015-04-08 15:13:54 -07006557 @Override
6558 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006559 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006560 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6561 return;
6562 }
6563
Svet Ganovcc087f82015-05-12 20:35:54 -07006564 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006565
Svet Ganovcc087f82015-05-12 20:35:54 -07006566 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006567 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6568 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006569 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006570 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006571 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006572 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6573 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006574 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006575 // There has been issues when Sms raw table somehow stores orphan
6576 // fragments. They lead to garbled message when new fragments come
6577 // in and combined with those stale ones. In case this happens again,
6578 // user can reset all network settings which will clean up this table.
6579 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006580 // Clean up IMS settings as well here.
6581 int slotId = getSlotIndex(subId);
6582 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6583 ImsManager.getInstance(mApp, slotId).factoryReset();
6584 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006585
6586 // Erase modem config if erase modem on network setting is enabled.
6587 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6588 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6589 if (configValue != null && Boolean.parseBoolean(configValue)) {
6590 sendEraseModemConfig(getDefaultPhone());
6591 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006592 } finally {
6593 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006594 }
6595 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006596
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006597 private void cleanUpSmsRawTable(Context context) {
6598 ContentResolver resolver = context.getContentResolver();
6599 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6600 resolver.delete(uri, null, null);
6601 }
6602
Narayan Kamath1c496c22015-04-16 14:40:19 +01006603 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006604 public String getSimLocaleForSubscriber(int subId) {
6605 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6606 final Phone phone = getPhone(subId);
6607 if (phone == null) {
6608 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006609 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 final long identity = Binder.clearCallingIdentity();
6612 try {
chen xu5d3637b2019-01-21 23:31:38 -08006613 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006614 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006615 if (info == null) {
6616 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6617 return null;
6618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 // Try and fetch the locale from the carrier properties or from the SIM language
6620 // preferences (EF-PL and EF-LI)...
6621 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006623 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6624 if (localeFromDefaultSim != null) {
6625 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6626 if (DBG) log("Using locale from subId: " + subId + " locale: "
6627 + localeFromDefaultSim);
6628 return localeFromDefaultSim.toLanguageTag();
6629 } else {
6630 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 }
6632 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 // The SIM language preferences only store a language (e.g. fr = French), not an
6635 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6636 // the SIM and carrier preferences does not include a country we add the country
6637 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006638 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006640 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641 return mccLocale.toLanguageTag();
6642 }
6643
6644 if (DBG) log("No locale found - returning null");
6645 return null;
6646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006649 }
6650
6651 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006652 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006653 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006654 }
6655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 /**
6657 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6658 */
6659 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006660 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006661 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006662 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006663
Chenjie Yu1ba97252018-01-11 18:16:20 -08006664 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006665 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006666
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006667 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006668 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6669 * representing the state of the modem.
6670 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006671 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6672 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006673 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006674 */
6675 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006676 public void requestModemActivityInfo(ResultReceiver result) {
6677 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006678 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
Shuo Qian1d931ee2020-02-20 17:12:10 -08006682 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683 } finally {
6684 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006685 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006686 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006687
Siddharth Rayb8114062018-06-17 15:02:38 -07006688 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6689 // less than total activity duration.
6690 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6691 if (info == null) {
6692 return false;
6693 }
6694 int activityDurationMs =
6695 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6696 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006697 int[] txTimeMs = info.getTransmitTimeMillis();
6698 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6699 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006700 }
6701 return (info.isValid()
6702 && (info.getSleepTimeMillis() <= activityDurationMs)
6703 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006704 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006705 && (totalTxTimeMs <= activityDurationMs));
6706 }
6707
Jack Yu85bd38a2015-11-09 11:34:32 -08006708 /**
6709 * {@hide}
6710 * Returns the service state information on specified subscription.
6711 */
6712 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006713 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6714 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006716 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006717 return null;
6718 }
6719
Hall Liuf19c44f2018-11-27 14:38:17 -08006720 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6721 LocationAccessPolicy.checkLocationPermission(mApp,
6722 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6723 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006724 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006725 .setCallingPid(Binder.getCallingPid())
6726 .setCallingUid(Binder.getCallingUid())
6727 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006728 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006729 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6730 .build());
6731
6732 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6733 LocationAccessPolicy.checkLocationPermission(mApp,
6734 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6735 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006736 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006737 .setCallingPid(Binder.getCallingPid())
6738 .setCallingUid(Binder.getCallingUid())
6739 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006740 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006741 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6742 .build());
6743 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6744 boolean hasFinePermission =
6745 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6746 boolean hasCoarsePermission =
6747 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 final Phone phone = getPhone(subId);
6752 if (phone == null) {
6753 return null;
6754 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006755
Hall Liuf19c44f2018-11-27 14:38:17 -08006756 ServiceState ss = phone.getServiceState();
6757
6758 // Scrub out the location info in ServiceState depending on what level of access
6759 // the caller has.
6760 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006761 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6762 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006766 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006767
6768 /**
6769 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6770 *
6771 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6772 * voicemail ringtone.
6773 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6774 * PhoneAccount.
6775 */
6776 @Override
6777 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 final long identity = Binder.clearCallingIdentity();
6779 try {
6780 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6781 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006782 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6786 } finally {
6787 Binder.restoreCallingIdentity(identity);
6788 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006789 }
6790
6791 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006792 * Sets the per-account voicemail ringtone.
6793 *
6794 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6795 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6796 *
6797 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6798 * voicemail ringtone.
6799 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6800 * PhoneAccount.
6801 */
6802 @Override
6803 public void setVoicemailRingtoneUri(String callingPackage,
6804 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006805 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006807 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6808 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6810 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6811 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
6816 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6817 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006818 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 }
6820 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006823 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006824 }
6825
6826 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006827 * Returns whether vibration is set for voicemail notification in Phone settings.
6828 *
6829 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6830 * voicemail vibration setting.
6831 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6832 */
6833 @Override
6834 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 final long identity = Binder.clearCallingIdentity();
6836 try {
6837 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6838 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006839 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006846 }
6847
Youhan Wange64578a2016-05-02 15:32:42 -07006848 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006849 * Sets the per-account voicemail vibration.
6850 *
6851 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6852 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6853 *
6854 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6855 * voicemail vibration setting.
6856 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6857 * specific PhoneAccount.
6858 */
6859 @Override
6860 public void setVoicemailVibrationEnabled(String callingPackage,
6861 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006862 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006863 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006864 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6865 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6867 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6868 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006869 }
6870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 final long identity = Binder.clearCallingIdentity();
6872 try {
6873 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6874 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006875 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 }
6877 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6878 } finally {
6879 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006880 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006881 }
6882
6883 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006884 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6885 *
6886 * @throws SecurityException if the caller does not have the required permission
6887 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006888 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006889 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006890 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006891 }
6892
6893 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006894 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6895 * permission.
6896 *
6897 * @throws SecurityException if the caller does not have the required permission
6898 */
6899 private void enforceSendSmsPermission() {
6900 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6901 }
6902
6903 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006904 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006905 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006906 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006907 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006908 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006912 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 if (componentName == null) {
6914 throw new SecurityException(
6915 "Caller not current active visual voicemail package[null]");
6916 }
6917 String vvmPackage = componentName.getPackageName();
6918 if (!callingPackage.equals(vvmPackage)) {
6919 throw new SecurityException("Caller not current active visual voicemail package["
6920 + vvmPackage + "]");
6921 }
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006924 }
6925 }
6926
6927 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006928 * Return the application ID for the app type.
6929 *
6930 * @param subId the subscription ID that this request applies to.
6931 * @param appType the uicc app type.
6932 * @return Application ID for specificied app type, or null if no uicc.
6933 */
6934 @Override
6935 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006936 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006937 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938
6939 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006940 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941 if (phone == null) {
6942 return null;
6943 }
6944 String aid = null;
6945 try {
6946 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6947 .getApplicationByType(appType).getAid();
6948 } catch (Exception e) {
6949 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6950 }
6951 return aid;
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006954 }
Youhan Wange64578a2016-05-02 15:32:42 -07006955 }
6956
Youhan Wang4001d252016-05-11 10:29:41 -07006957 /**
6958 * Return the Electronic Serial Number.
6959 *
6960 * @param subId the subscription ID that this request applies to.
6961 * @return ESN or null if error.
6962 */
6963 @Override
6964 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006965 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006966 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967
6968 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006969 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 if (phone == null) {
6971 return null;
6972 }
6973 String esn = null;
6974 try {
6975 esn = phone.getEsn();
6976 } catch (Exception e) {
6977 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6978 }
6979 return esn;
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006982 }
Youhan Wang4001d252016-05-11 10:29:41 -07006983 }
6984
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006985 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006986 * Return the Preferred Roaming List Version.
6987 *
6988 * @param subId the subscription ID that this request applies to.
6989 * @return PRLVersion or null if error.
6990 */
6991 @Override
6992 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006993 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006994 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995
6996 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006997 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 if (phone == null) {
6999 return null;
7000 }
7001 String cdmaPrlVersion = null;
7002 try {
7003 cdmaPrlVersion = phone.getCdmaPrlVersion();
7004 } catch (Exception e) {
7005 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7006 }
7007 return cdmaPrlVersion;
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007010 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007011 }
7012
7013 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007014 * Get snapshot of Telephony histograms
7015 * @return List of Telephony histograms
7016 * @hide
7017 */
7018 @Override
7019 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7021 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 return RIL.getTelephonyRILTimingHistograms();
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007029 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007030
7031 /**
7032 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007033 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7034 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007035 * Require system privileges. In the future we may add this to carrier APIs.
7036 *
Michele Berionne482f8202018-11-27 18:57:59 -08007037 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007038 */
7039 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007040 @TelephonyManager.SetCarrierRestrictionResult
7041 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007042 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007044
Michele Berionne482f8202018-11-27 18:57:59 -08007045 if (carrierRestrictionRules == null) {
7046 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007047 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 final long identity = Binder.clearCallingIdentity();
7050 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007051 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007052 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007056 }
7057
7058 /**
7059 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007060 * Get the allowed carrier list and the excluded carrier list, including the priority between
7061 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007062 * Require system privileges. In the future we may add this to carrier APIs.
7063 *
Michele Berionne482f8202018-11-27 18:57:59 -08007064 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007065 */
7066 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007067 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007068 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007069 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070
7071 final long identity = Binder.clearCallingIdentity();
7072 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007073 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7074 if (response instanceof CarrierRestrictionRules) {
7075 return (CarrierRestrictionRules) response;
7076 }
7077 // Response is an Exception of some kind,
7078 // which is signalled to the user as a NULL retval
7079 return null;
7080 } catch (Exception e) {
7081 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7082 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 } finally {
7084 Binder.restoreCallingIdentity(identity);
7085 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007086 }
7087
fionaxu59545b42016-05-25 15:53:37 -07007088 /**
7089 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7090 * @param subId the subscription ID that this action applies to.
7091 * @param enabled control enable or disable metered apns.
7092 * {@hide}
7093 */
7094 @Override
7095 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7096 enforceModifyPermission();
7097 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098
7099 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007100 if (phone == null) {
7101 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7102 return;
7103 }
7104 try {
7105 phone.carrierActionSetMeteredApnsEnabled(enabled);
7106 } catch (Exception e) {
7107 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 } finally {
7109 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007110 }
7111 }
7112
7113 /**
7114 * Action set from carrier signalling broadcast receivers to enable/disable radio
7115 * @param subId the subscription ID that this action applies to.
7116 * @param enabled control enable or disable radio.
7117 * {@hide}
7118 */
7119 @Override
7120 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7121 enforceModifyPermission();
7122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123
7124 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007125 if (phone == null) {
7126 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7127 return;
7128 }
7129 try {
7130 phone.carrierActionSetRadioEnabled(enabled);
7131 } catch (Exception e) {
7132 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 } finally {
7134 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007135 }
7136 }
7137
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007138 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007139 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7140 * network status based on which carrier apps could apply actions accordingly,
7141 * enable/disable default url handler for example.
7142 *
7143 * @param subId the subscription ID that this action applies to.
7144 * @param report control start/stop reporting the default network status.
7145 * {@hide}
7146 */
7147 @Override
7148 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7149 enforceModifyPermission();
7150 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151
7152 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007153 if (phone == null) {
7154 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7155 return;
7156 }
7157 try {
7158 phone.carrierActionReportDefaultNetworkStatus(report);
7159 } catch (Exception e) {
7160 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 } finally {
7162 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007163 }
7164 }
7165
7166 /**
fionaxud9622282017-07-17 17:51:30 -07007167 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7168 * @param subId the subscription ID that this action applies to.
7169 * {@hide}
7170 */
7171 @Override
7172 public void carrierActionResetAll(int subId) {
7173 enforceModifyPermission();
7174 final Phone phone = getPhone(subId);
7175 if (phone == null) {
7176 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7177 return;
7178 }
7179 try {
7180 phone.carrierActionResetAll();
7181 } catch (Exception e) {
7182 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7183 }
7184 }
7185
7186 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007187 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7188 * bug report is being generated.
7189 */
7190 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007191 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007192 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7193 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007194 writer.println("Permission Denial: can't dump Phone from pid="
7195 + Binder.getCallingPid()
7196 + ", uid=" + Binder.getCallingUid()
7197 + "without permission "
7198 + android.Manifest.permission.DUMP);
7199 return;
7200 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007201 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007202 }
Jack Yueb89b242016-06-22 13:27:47 -07007203
Brad Ebingerdac2f002018-04-03 15:17:52 -07007204 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007205 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7206 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7207 @NonNull String[] args) {
7208 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7209 this, in.getFileDescriptor(), out.getFileDescriptor(),
7210 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007211 }
7212
Jack Yueb89b242016-06-22 13:27:47 -07007213 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007214 * Policy control of data connection. Usually used when data limit is passed.
7215 * @param enabled True if enabling the data, otherwise disabling.
7216 * @param subId Subscription index
7217 * {@hide}
7218 */
7219 @Override
7220 public void setPolicyDataEnabled(boolean enabled, int subId) {
7221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222
7223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 Phone phone = getPhone(subId);
7226 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007227 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 }
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007231 }
7232 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007233
7234 /**
7235 * Get Client request stats
7236 * @return List of Client Request Stats
7237 * @hide
7238 */
7239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007240 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7241 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007243 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007244 return null;
7245 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007246 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 if (phone != null) {
7251 return phone.getClientRequestStats();
7252 }
7253
7254 return null;
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
7257 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007258 }
7259
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007260 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007261 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007262 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007263 }
Jack Yueb4124c2017-02-16 15:32:43 -08007264
7265 /**
Grace Chen70990072017-03-24 17:21:30 -07007266 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007267 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007268 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007269 * @param state State of SIM (power down, power up, pass through)
7270 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7271 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7272 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007273 *
7274 **/
7275 @Override
Grace Chen70990072017-03-24 17:21:30 -07007276 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007277 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007278 Phone phone = PhoneFactory.getPhone(slotIndex);
7279
vagdeviaf9a5b92018-08-15 16:01:53 -07007280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007285 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 }
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007289 }
7290 }
Shuo Qiandd210312017-04-12 22:11:33 +00007291
Tyler Gunn65d45c22017-06-05 11:22:26 -07007292 private boolean isUssdApiAllowed(int subId) {
7293 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007294 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007295 if (configManager == null) {
7296 return false;
7297 }
7298 PersistableBundle pb = configManager.getConfigForSubId(subId);
7299 if (pb == null) {
7300 return false;
7301 }
7302 return pb.getBoolean(
7303 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7304 }
7305
Shuo Qiandd210312017-04-12 22:11:33 +00007306 /**
7307 * Check if phone is in emergency callback mode
7308 * @return true if phone is in emergency callback mode
7309 * @param subId sub id
7310 */
goneil9c5f4872017-12-05 14:07:56 -08007311 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007312 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007313 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 if (phone != null) {
7319 return phone.isInEcm();
7320 } else {
7321 return false;
7322 }
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007325 }
7326 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007327
7328 /**
7329 * Get the current signal strength information for the given subscription.
7330 * Because this information is not updated when the device is in a low power state
7331 * it should not be relied-upon to be current.
7332 * @param subId Subscription index
7333 * @return the most recent cached signal strength info from the modem
7334 */
7335 @Override
7336 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
7339 Phone p = getPhone(subId);
7340 if (p == null) {
7341 return null;
7342 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 return p.getSignalStrength();
7345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007348 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007349
Pengquan Meng77b7f132018-08-22 14:49:57 -07007350 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007351 * Get the current modem radio state for the given slot.
7352 * @param slotIndex slot index.
7353 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007354 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007355 * @return the current radio power state from the modem
7356 */
7357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007358 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007359 Phone phone = PhoneFactory.getPhone(slotIndex);
7360 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7362 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007363 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7364 }
7365
7366 final long identity = Binder.clearCallingIdentity();
7367 try {
7368 return phone.getRadioPowerState();
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
7371 }
7372 }
7373 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7374 }
7375
7376 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007377 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7378 *
7379 * <p>Requires one of the following permissions:
7380 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7381 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7382 * privileges.
7383 *
7384 * @param subId subscription id
7385 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7386 * {@code false}.
7387 */
7388 @Override
7389 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007390 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7391 null /* message */);
7392
Pengquan Menga1bb6272018-09-06 09:59:22 -07007393 boolean isEnabled = false;
7394 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007395 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007396 Phone phone = getPhone(subId);
7397 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007398 } catch (Exception e) {
7399 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7400 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007401 } finally {
7402 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007403 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007404 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007405 }
7406
7407
7408 /**
7409 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7410 *
7411 * <p> Requires permission:
7412 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7413 * privileges.
7414 *
7415 * @param subId subscription id
7416 * @param isEnabled {@code true} means enable, {@code false} means disable.
7417 */
7418 @Override
7419 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7421 mApp, subId, "setDataRoamingEnabled");
7422
Pengquan Menga1bb6272018-09-06 09:59:22 -07007423 final long identity = Binder.clearCallingIdentity();
7424 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007425 Phone phone = getPhone(subId);
7426 if (phone != null) {
7427 phone.setDataRoamingEnabled(isEnabled);
7428 }
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007431 }
7432 }
7433
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007434 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007435 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007436 TelephonyPermissions
7437 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007438 mApp, subId, "isManualNetworkSelectionAllowed");
7439
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007440 boolean isAllowed = true;
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007443 Phone phone = getPhone(subId);
7444 if (phone != null) {
7445 isAllowed = phone.isCspPlmnEnabled();
7446 }
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
7450 return isAllowed;
7451 }
7452
7453 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007454 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu102b2772020-03-04 13:59:23 -08007455 try {
7456 PackageManager pm = mApp.getPackageManager();
7457 if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) {
7458 throw new SecurityException("Calling package " + callingPackage + " does not match "
7459 + "calling UID");
7460 }
7461 } catch (PackageManager.NameNotFoundException e) {
7462 throw new SecurityException("Invalid calling package. e=" + e);
7463 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007464 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007465 try {
7466 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007467 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007468 } catch (SecurityException e) {
7469 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7470 // has carrier privileges on an active UICC
7471 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7472 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007473 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007474 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007475 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007476
7477 final long identity = Binder.clearCallingIdentity();
7478 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007479 UiccController uiccController = UiccController.getInstance();
7480 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007481 if (hasReadPermission) {
7482 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007483 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007484
7485 // Remove private info if the caller doesn't have access
7486 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7487 for (UiccCardInfo cardInfo : cardInfos) {
7488 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7489 // is available
7490 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7491 if (card == null || card.getUiccProfile() == null) {
7492 // assume no access if the card or profile is unavailable
7493 filteredInfos.add(cardInfo.getUnprivileged());
7494 continue;
7495 }
7496 UiccProfile profile = card.getUiccProfile();
7497 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7498 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7499 filteredInfos.add(cardInfo);
7500 } else {
7501 filteredInfos.add(cardInfo.getUnprivileged());
7502 }
7503 }
7504 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007505 } finally {
7506 Binder.restoreCallingIdentity(identity);
7507 }
7508 }
7509
7510 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007511 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007512 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7517 if (slots == null) {
7518 Rlog.i(LOG_TAG, "slots is null.");
7519 return null;
7520 }
7521
7522 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7523 for (int i = 0; i < slots.length; i++) {
7524 UiccSlot slot = slots[i];
7525 if (slot == null) {
7526 continue;
7527 }
7528
Jordan Liu7be7e652019-05-06 18:55:02 +00007529 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 UiccCard card = slot.getUiccCard();
7531 if (card != null) {
7532 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007533 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007534 cardId = slot.getEid();
7535 if (TextUtils.isEmpty(cardId)) {
7536 cardId = slot.getIccId();
7537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 }
7539
Jordan Liu857451f2019-05-09 16:35:35 -07007540 if (cardId != null) {
7541 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7542 // if cardId is an EID, it's all digits so this is fine
7543 cardId = IccUtils.stripTrailingFs(cardId);
7544 }
7545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 int cardState = 0;
7547 switch (slot.getCardState()) {
7548 case CARDSTATE_ABSENT:
7549 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7550 break;
7551 case CARDSTATE_PRESENT:
7552 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7553 break;
7554 case CARDSTATE_ERROR:
7555 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7556 break;
7557 case CARDSTATE_RESTRICTED:
7558 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7559 break;
7560 default:
7561 break;
7562
7563 }
7564
7565 infos[i] = new UiccSlotInfo(
7566 slot.isActive(),
7567 slot.isEuicc(),
7568 cardId,
7569 cardState,
7570 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007571 slot.isExtendedApduSupported(),
7572 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 }
7574 return infos;
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007577 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007578 }
7579
7580 @Override
7581 public boolean switchSlots(int[] physicalSlots) {
7582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007590 }
Jack Yu4c988042018-02-27 15:30:01 -08007591
7592 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007593 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 return UiccController.getInstance().getCardIdForDefaultEuicc();
7597 } finally {
7598 Binder.restoreCallingIdentity(identity);
7599 }
7600 }
7601
Pengquan Meng85728fb2018-03-12 16:31:21 -07007602 /**
goneil47ffb6e2018-04-06 15:40:58 -07007603 * A test API to reload the UICC profile.
7604 *
7605 * <p>Requires that the calling app has permission
7606 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7607 * @hide
7608 */
7609 @Override
7610 public void refreshUiccProfile(int subId) {
7611 enforceModifyPermission();
7612
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = getPhone(subId);
7616 if (phone == null) {
7617 return;
7618 }
7619 UiccCard uiccCard = phone.getUiccCard();
7620 if (uiccCard == null) {
7621 return;
7622 }
7623 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7624 if (uiccProfile == null) {
7625 return;
7626 }
7627 uiccProfile.refresh();
7628 } finally {
7629 Binder.restoreCallingIdentity(identity);
7630 }
7631 }
7632
7633 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007634 * Returns false if the mobile data is disabled by default, otherwise return true.
7635 */
7636 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007637 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007638 }
7639
7640 /**
7641 * Returns true if the data roaming is enabled by default, i.e the system property
7642 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7643 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7644 */
7645 private boolean getDefaultDataRoamingEnabled(int subId) {
7646 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007647 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007648 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007649 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7650 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7651 return isDataRoamingEnabled;
7652 }
7653
7654 /**
7655 * Returns the default network type for the given {@code subId}, if the default network type is
7656 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7657 */
7658 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007659 List<Integer> list = TelephonyProperties.default_network();
7660 int phoneId = mSubscriptionController.getPhoneId(subId);
7661 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7662 return list.get(phoneId);
7663 }
7664 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007665 }
fionaxua13278b2018-03-21 00:08:13 -07007666
7667 @Override
7668 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007669 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671
7672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 final Phone phone = getPhone(subId);
7675 if (phone == null) {
7676 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7677 return;
7678 }
chen xueaba88a2019-03-15 13:15:10 -07007679 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7680 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681 } finally {
7682 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007683 }
fionaxua13278b2018-03-21 00:08:13 -07007684 }
7685
7686 @Override
7687 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007688 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689
7690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 final Phone phone = getPhone(subId);
7693 if (phone == null) {
7694 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7695 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7696 }
7697 return phone.getCarrierIdListVersion();
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007700 }
fionaxua13278b2018-03-21 00:08:13 -07007701 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007702
7703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7705 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007707 mApp, subId, callingPackage, callingFeatureId,
7708 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007709 return -1;
7710 }
7711
7712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
7717 }
7718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007719
7720 @Override
7721 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007722 TelephonyPermissions
7723 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007724 mApp, subId, "getCdmaRoamingMode");
7725
7726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
7732 }
7733
7734 @Override
7735 public boolean setCdmaRoamingMode(int subId, int mode) {
7736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7737 mApp, subId, "setCdmaRoamingMode");
7738
7739 final long identity = Binder.clearCallingIdentity();
7740 try {
7741 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
7745 }
7746
7747 @Override
7748 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7750 mApp, subId, "setCdmaSubscriptionMode");
7751
7752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7755 } finally {
7756 Binder.restoreCallingIdentity(identity);
7757 }
7758 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007759
sqianc5eccab2018-10-19 18:46:41 -07007760 @Override
sqian8c685422019-02-22 15:55:18 -08007761 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007762 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007764 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7765 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007766 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7767 }
7768 final long identity = Binder.clearCallingIdentity();
7769 try {
sqian854d44b2018-12-12 16:48:18 -08007770 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7771 for (Phone phone: PhoneFactory.getPhones()) {
7772 if (phone.getEmergencyNumberTracker() != null
7773 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7774 emergencyNumberListInternal.put(
7775 phone.getSubId(),
7776 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7777 }
sqian11b7a0e2018-12-05 18:48:28 -08007778 }
sqian854d44b2018-12-12 16:48:18 -08007779 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
sqianc5eccab2018-10-19 18:46:41 -07007783 }
7784
7785 @Override
sqian8c685422019-02-22 15:55:18 -08007786 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007787 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007788 if (!exactMatch) {
7789 TelephonyPermissions
7790 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007791 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007792 }
7793 final long identity = Binder.clearCallingIdentity();
7794 try {
sqian854d44b2018-12-12 16:48:18 -08007795 for (Phone phone: PhoneFactory.getPhones()) {
7796 if (phone.getEmergencyNumberTracker() != null
7797 && phone.getEmergencyNumberTracker() != null) {
7798 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7799 number, exactMatch)) {
7800 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007801 }
7802 }
sqian11b7a0e2018-12-05 18:48:28 -08007803 }
7804 return false;
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
7808 }
7809
sqianf4ca7ed2019-01-15 18:32:07 -08007810 /**
7811 * Update emergency number list for test mode.
7812 */
7813 @Override
7814 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7816 "updateEmergencyNumberListTestMode");
7817
7818 final long identity = Binder.clearCallingIdentity();
7819 try {
7820 for (Phone phone: PhoneFactory.getPhones()) {
7821 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7822 if (tracker != null) {
7823 tracker.executeEmergencyNumberTestModeCommand(action, num);
7824 }
7825 }
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
7829 }
7830
7831 /**
7832 * Get the full emergency number list for test mode.
7833 */
7834 @Override
7835 public List<String> getEmergencyNumberListTestMode() {
7836 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7837 "getEmergencyNumberListTestMode");
7838
7839 final long identity = Binder.clearCallingIdentity();
7840 try {
7841 Set<String> emergencyNumbers = new HashSet<>();
7842 for (Phone phone: PhoneFactory.getPhones()) {
7843 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7844 if (tracker != null) {
7845 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7846 emergencyNumbers.add(num.getNumber());
7847 }
7848 }
7849 }
7850 return new ArrayList<>(emergencyNumbers);
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
7854 }
7855
chen xud6b45bd2018-10-30 22:27:10 -07007856 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007857 public int getEmergencyNumberDbVersion(int subId) {
7858 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7859
7860 final long identity = Binder.clearCallingIdentity();
7861 try {
7862 final Phone phone = getPhone(subId);
7863 if (phone == null) {
7864 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7865 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7866 }
7867 return phone.getEmergencyNumberDbVersion();
7868 } finally {
7869 Binder.restoreCallingIdentity(identity);
7870 }
7871 }
7872
7873 @Override
7874 public void notifyOtaEmergencyNumberDbInstalled() {
7875 enforceModifyPermission();
7876
7877 final long identity = Binder.clearCallingIdentity();
7878 try {
7879 for (Phone phone: PhoneFactory.getPhones()) {
7880 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7881 if (tracker != null) {
7882 tracker.updateOtaEmergencyNumberDatabase();
7883 }
7884 }
7885 } finally {
7886 Binder.restoreCallingIdentity(identity);
7887 }
7888 }
7889
7890 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007891 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007892 enforceActiveEmergencySessionPermission();
7893
7894 final long identity = Binder.clearCallingIdentity();
7895 try {
7896 for (Phone phone: PhoneFactory.getPhones()) {
7897 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7898 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007899 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7900 }
7901 }
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
7904 }
7905 }
7906
7907 @Override
7908 public void resetOtaEmergencyNumberDbFilePath() {
7909 enforceActiveEmergencySessionPermission();
7910
7911 final long identity = Binder.clearCallingIdentity();
7912 try {
7913 for (Phone phone: PhoneFactory.getPhones()) {
7914 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7915 if (tracker != null) {
7916 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007917 }
7918 }
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
7921 }
7922 }
7923
7924 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007925 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7926 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7927 Phone phone = getPhone(subId);
7928 if (phone == null) {
7929 return null;
7930 }
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 UiccProfile profile = UiccController.getInstance()
7934 .getUiccProfileForPhone(phone.getPhoneId());
7935 if (profile != null) {
7936 return profile.getCertsFromCarrierPrivilegeAccessRules();
7937 }
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
7941 return null;
7942 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007943
7944 /**
7945 * Enable or disable a modem stack.
7946 */
7947 @Override
7948 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7949 enforceModifyPermission();
7950
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 Phone phone = PhoneFactory.getPhone(slotIndex);
7954 if (phone == null) {
7955 return false;
7956 } else {
7957 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7958 }
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
7962 }
Michelecea4cf22018-12-21 15:00:11 -08007963
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007964 /**
7965 * Whether a modem stack is enabled or not.
7966 */
7967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007968 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7969 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007970 Phone phone = PhoneFactory.getPhone(slotIndex);
7971 if (phone == null) return false;
7972
7973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007974 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7975 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007976 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7977 }
7978
7979 final long identity = Binder.clearCallingIdentity();
7980 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007981 try {
7982 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7983 } catch (NoSuchElementException ex) {
7984 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7985 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007986 } finally {
7987 Binder.restoreCallingIdentity(identity);
7988 }
7989 }
7990
Michelecea4cf22018-12-21 15:00:11 -08007991 @Override
Michele0ea7d782019-03-19 14:58:42 -07007992 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007993 enforceModifyPermission();
7994
7995 final long identity = Binder.clearCallingIdentity();
7996 try {
7997 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007998 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007999 .commit();
8000 } finally {
8001 Binder.restoreCallingIdentity(identity);
8002 }
8003 }
8004
8005 @Override
Michele0ea7d782019-03-19 14:58:42 -07008006 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008007 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008009 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8010 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008011 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008012 }
Michelecea4cf22018-12-21 15:00:11 -08008013
8014 final long identity = Binder.clearCallingIdentity();
8015 try {
Michele0ea7d782019-03-19 14:58:42 -07008016 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
8020 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008021
Michele0ea7d782019-03-19 14:58:42 -07008022 @TelephonyManager.IsMultiSimSupportedResult
8023 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008024 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8025 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8026 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008027 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8028 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008029 }
8030 // Check if the hardware supports multisim functionality. If usage of multisim is not
8031 // supported by the modem, indicate that it is restricted.
8032 PhoneCapability staticCapability =
8033 mPhoneConfigurationManager.getStaticPhoneCapability();
8034 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008035 loge("isMultiSimSupportedInternal: no static configuration available");
8036 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008037 }
Sarah Chin7caee492020-02-18 20:49:02 +00008038 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008039 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8040 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008041 }
8042 // Check if support of multiple SIMs is restricted by carrier
8043 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008044 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008045 }
8046
Michele0ea7d782019-03-19 14:58:42 -07008047 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008048 }
8049
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008050 /**
8051 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008052 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8053 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8054 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008055 * @param numOfSims number of active sims we want to switch to
8056 */
8057 @Override
8058 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008059 if (numOfSims == 1) {
8060 enforceModifyPermission();
8061 } else {
8062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8063 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8064 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008065 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008066
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008067 try {
Michele30b57b22019-03-01 12:01:14 -08008068 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008069 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008070 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8071 return;
8072 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008073 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
8076 }
8077 }
8078
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008079 @Override
8080 public boolean isApplicationOnUicc(int subId, int appType) {
8081 enforceReadPrivilegedPermission("isApplicationOnUicc");
8082 Phone phone = getPhone(subId);
8083 if (phone == null) {
8084 return false;
8085 }
8086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 UiccCard uiccCard = phone.getUiccCard();
8089 if (uiccCard == null) {
8090 return false;
8091 }
8092 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8093 if (uiccProfile == null) {
8094 return false;
8095 }
8096 if (TelephonyManager.APPTYPE_SIM <= appType
8097 && appType <= TelephonyManager.APPTYPE_ISIM) {
8098 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8099 }
8100 return false;
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
8104 }
8105
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008106 /**
chen xub4baa772019-04-03 10:23:41 -07008107 * Get whether making changes to modem configurations will trigger reboot.
8108 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008109 */
8110 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008111 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8112 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008114 mApp, subId, callingPackage, callingFeatureId,
8115 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008116 return false;
8117 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
8125
Nathan Harold29f5f052019-02-15 13:41:57 -08008126 private void updateModemStateMetrics() {
8127 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8128 // TODO: check the state for each modem if the api is ready.
8129 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8130 }
8131
Pengquan Meng3889a572019-01-23 11:16:29 -08008132 @Override
8133 public int[] getSlotsMapping() {
8134 enforceReadPrivilegedPermission("getSlotsMapping");
8135
8136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8139 // All logical slots should have a mapping to a physical slot.
8140 int[] logicalSlotsMapping = new int[phoneCount];
8141 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8142 for (int i = 0; i < slotInfos.length; i++) {
8143 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8144 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8145 }
8146 }
8147 return logicalSlotsMapping;
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008152
8153 /**
8154 * Get the IRadio HAL Version
8155 */
8156 @Override
8157 public int getRadioHalVersion() {
8158 Phone phone = getDefaultPhone();
8159 if (phone == null) return -1;
8160 HalVersion hv = phone.getHalVersion();
8161 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8162 return hv.major * 100 + hv.minor;
8163 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008164
8165 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008166 * Get the current calling package name.
8167 * @return the current calling package name
8168 */
8169 @Override
8170 public String getCurrentPackageName() {
8171 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8172 }
8173
8174 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008175 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8176 * corresponding network requests on a subId.
8177 *
8178 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008179 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008180 * 2) APN is un-metered for this subscription, or
8181 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008182 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008183 *
8184 * @return whether data is allowed for a apn type.
8185 *
8186 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008187 */
8188 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008189 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008190 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8191 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008192
8193 // Now that all security checks passes, perform the operation as ourselves.
8194 final long identity = Binder.clearCallingIdentity();
8195 try {
8196 Phone phone = getPhone(subId);
8197 if (phone == null) return false;
8198
Jack Yu41407ee2019-05-13 16:54:09 -07008199 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008200 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
8204 }
8205
8206 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008207 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008208 enforceReadPrivilegedPermission("isApnMetered");
8209
8210 // Now that all security checks passes, perform the operation as ourselves.
8211 final long identity = Binder.clearCallingIdentity();
8212 try {
8213 Phone phone = getPhone(subId);
8214 if (phone == null) return true; // By default return true.
8215
Jack Yu41407ee2019-05-13 16:54:09 -07008216 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
8220 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008221
8222 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008223 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8224 int subscriptionId, IBooleanConsumer resultCallback) {
8225 enforceModifyPermission();
8226 long token = Binder.clearCallingIdentity();
8227 try {
8228 Phone phone = getPhone(subscriptionId);
8229 if (phone == null) {
8230 try {
8231 if (resultCallback != null) {
8232 resultCallback.accept(false);
8233 }
8234 } catch (RemoteException e) {
8235 // ignore
8236 }
8237 return;
8238 }
8239 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8240 Pair.create(specifiers, (x) -> {
8241 try {
8242 if (resultCallback != null) {
8243 resultCallback.accept(x);
8244 }
8245 } catch (RemoteException e) {
8246 // ignore
8247 }
8248 });
8249 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8250 } finally {
8251 Binder.restoreCallingIdentity(token);
8252 }
8253 }
8254
8255 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008256 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008257 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008258 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8259 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8260 if (iccRecords == null) {
8261 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8262 return false;
8263 }
8264 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8265 }
8266
8267 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008268 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8269 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008270 if (callingPackage == null) {
8271 callingPackage = getCurrentPackageName();
8272 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008273 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8274 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008275 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8276 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008277 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8278 }
8279 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8280 Intent intent = new Intent();
8281 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8282 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8283 // Bring up choose default SMS subscription dialog right now
8284 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8285 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8286 mApp.startActivity(intent);
8287 }
chen xud5ca2d52019-05-28 15:20:57 -07008288
8289 @Override
8290 public String getMmsUAProfUrl(int subId) {
8291 //TODO investigate if this API should require proper permission check in R b/133791609
8292 final long identity = Binder.clearCallingIdentity();
8293 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008294 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8295 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
8299 }
8300
8301 @Override
8302 public String getMmsUserAgent(int subId) {
8303 //TODO investigate if this API should require proper permission check in R b/133791609
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008306 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8307 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
Jack Yub07d4972019-05-28 16:12:25 -07008312
8313 @Override
8314 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8315 enforceModifyPermission();
8316
8317 // Now that all security checks passes, perform the operation as ourselves.
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
8320 Phone phone = getPhone(subId);
8321 if (phone == null) return false;
8322
8323 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
8329 @Override
8330 public boolean isDataAllowedInVoiceCall(int subId) {
8331 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8332
8333 // Now that all security checks passes, perform the operation as ourselves.
8334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = getPhone(subId);
8337 if (phone == null) return false;
8338
8339 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008344
changbettyd5c246e2019-12-24 15:40:37 +08008345 @Override
8346 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8347 enforceModifyPermission();
8348
8349 // Now that all security checks passes, perform the operation as ourselves.
8350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 Phone phone = getPhone(subId);
8353 if (phone == null) return false;
8354
8355 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
8359 }
8360
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008361 /**
8362 * Updates whether conference event pacakge handling is enabled.
8363 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8364 * otherwise.
8365 */
8366 @Override
8367 public void setCepEnabled(boolean isCepEnabled) {
8368 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8369
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8373 for (Phone phone : PhoneFactory.getPhones()) {
8374 Phone defaultPhone = phone.getImsPhone();
8375 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8376 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8377 ImsPhoneCallTracker imsPhoneCallTracker =
8378 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8379 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8380 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8381 + imsPhone.getMsisdn());
8382 }
8383 }
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
allenwtsu46dcc572020-01-08 18:24:03 +08008388
8389 /**
8390 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8391 *
8392 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8393 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8394 * before being read.
8395 */
8396 @Override
8397 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8398 isCompressed) {
8399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8400 mApp, subId, "notifyRcsAutoConfigurationReceived");
8401 try {
8402 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8403 if (configBinder == null) {
8404 Rlog.e(LOG_TAG, "null result for getImsConfig");
8405 } else {
8406 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8407 }
8408 } catch (RemoteException e) {
8409 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8410 }
8411 }
zoey chene02881a2019-12-30 16:11:23 +08008412
8413 @Override
8414 public boolean isIccLockEnabled(int subId) {
8415 enforceReadPrivilegedPermission("isIccLockEnabled");
8416
8417 // Now that all security checks passes, perform the operation as ourselves.
8418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 Phone phone = getPhone(subId);
8421 if (phone != null && phone.getIccCard() != null) {
8422 return phone.getIccCard().getIccLockEnabled();
8423 } else {
8424 return false;
8425 }
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
8428 }
8429 }
8430
8431 /**
8432 * Set the ICC pin lock enabled or disabled.
8433 *
8434 * @return an integer representing the status of IccLock enabled or disabled in the following
8435 * three cases:
8436 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8437 * successfully.
8438 * - Positive number and zero for remaining password attempts.
8439 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8440 *
8441 */
8442 @Override
8443 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8444 enforceModifyPermission();
8445
8446 Phone phone = getPhone(subId);
8447 if (phone == null) {
8448 return 0;
8449 }
8450 // Now that all security checks passes, perform the operation as ourselves.
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8454 new Pair<Boolean, String>(enabled, password), phone, null);
8455 return attemptsRemaining;
8456
8457 } catch (Exception e) {
8458 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
8461 }
8462 return 0;
8463 }
8464
8465 /**
8466 * Change the ICC password used in ICC pin lock.
8467 *
8468 * @return an integer representing the status of IccLock changed in the following three cases:
8469 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8470 * - Positive number and zero for remaining password attempts.
8471 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8472 *
8473 */
8474 @Override
8475 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8476 enforceModifyPermission();
8477
8478 Phone phone = getPhone(subId);
8479 if (phone == null) {
8480 return 0;
8481 }
8482 // Now that all security checks passes, perform the operation as ourselves.
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
8485 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8486 new Pair<String, String>(oldPassword, newPassword), phone, null);
8487 return attemptsRemaining;
8488
8489 } catch (Exception e) {
8490 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 return 0;
8495 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008496
8497 /**
8498 * Request for receiving user activity notification
8499 */
8500 @Override
8501 public void requestUserActivityNotification() {
8502 if (!mNotifyUserActivity.get()
8503 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8504 mNotifyUserActivity.set(true);
8505 }
8506 }
8507
8508 /**
8509 * Called when userActivity is signalled in the power manager.
8510 * This is safe to call from any thread, with any window manager locks held or not.
8511 */
8512 @Override
8513 public void userActivity() {
8514 // ***************************************
8515 // * Inherited from PhoneWindowManager *
8516 // ***************************************
8517 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8518 // WITH ITS LOCKS HELD.
8519 //
8520 // This code must be VERY careful about the locks
8521 // it acquires.
8522 // In fact, the current code acquires way too many,
8523 // and probably has lurking deadlocks.
8524
8525 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8526 throw new SecurityException("Only the OS may call notifyUserActivity()");
8527 }
8528
8529 if (mNotifyUserActivity.getAndSet(false)) {
8530 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8531 USER_ACTIVITY_NOTIFICATION_DELAY);
8532 }
8533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008534}