blob: b045c0f2044a6956b76878539679c73cc0f0ff00 [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;
Shuo Qian4a594052020-01-23 11:59:30 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800193import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800282 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800283 private static final int CMD_GET_CALL_FORWARDING = 83;
284 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
285 private static final int CMD_SET_CALL_FORWARDING = 85;
286 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
287 private static final int CMD_GET_CALL_WAITING = 87;
288 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
289 private static final int CMD_SET_CALL_WAITING = 89;
290 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800292 // Parameters of select command.
293 private static final int SELECT_COMMAND = 0xA4;
294 private static final int SELECT_P1 = 0x04;
295 private static final int SELECT_P2 = 0;
296 private static final int SELECT_P3 = 0x10;
297
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 /** The singleton instance. */
299 private static PhoneInterfaceManager sInstance;
300
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800303 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700304 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private AppOpsManager mAppOps;
306 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800307 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700309 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 /** User Activity */
312 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
314
Derek Tan97ebb422014-09-05 16:55:38 -0700315 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
316 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800317 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800318 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700319
Michelecea4cf22018-12-21 15:00:11 -0800320 // String to store multi SIM allowed
321 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
322
Derek Tan740e1672017-06-27 14:56:27 -0700323 // The AID of ISD-R.
324 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
325
yinxub1bed742017-04-17 11:45:04 -0700326 private NetworkScanRequestTracker mNetworkScanRequestTracker;
327
David Kelly5e06a7f2018-03-12 14:10:59 +0000328 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
329 private static final int MANUFACTURER_CODE_LENGTH = 8;
330
Derek Tan89e89d42014-07-08 17:00:10 -0700331 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700332 * Experiment flag to enable erase modem config on reset network, default value is false
333 */
334 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
335 "reset_network_erase_modem_config_enabled";
336
337 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700338 * A request object to use for transmitting data to an ICC.
339 */
340 private static final class IccAPDUArgument {
341 public int channel, cla, command, p1, p2, p3;
342 public String data;
343
344 public IccAPDUArgument(int channel, int cla, int command,
345 int p1, int p2, int p3, String data) {
346 this.channel = channel;
347 this.cla = cla;
348 this.command = command;
349 this.p1 = p1;
350 this.p2 = p2;
351 this.p3 = p3;
352 this.data = data;
353 }
354 }
355
356 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700357 * A request object to use for transmitting data to an ICC.
358 */
359 private static final class ManualNetworkSelectionArgument {
360 public OperatorInfo operatorInfo;
361 public boolean persistSelection;
362
363 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
364 this.operatorInfo = operatorInfo;
365 this.persistSelection = persistSelection;
366 }
367 }
368
369 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
371 * request after sending. The main thread will notify the request when it is complete.
372 */
373 private static final class MainThreadRequest {
374 /** The argument to use for the request */
375 public Object argument;
376 /** The result of the request that is run on the main thread */
377 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800378 // The subscriber id that this request applies to. Defaults to
379 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
380 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Nathan Harold92bed182018-10-12 18:16:49 -0700382 // In cases where subId is unavailable, the caller needs to specify the phone.
383 public Phone phone;
384
vagdeviaf9a5b92018-08-15 16:01:53 -0700385 public WorkSource workSource;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 public MainThreadRequest(Object argument) {
388 this.argument = argument;
389 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800390
Nathan Harold92bed182018-10-12 18:16:49 -0700391 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
392 this.argument = argument;
393 if (phone != null) {
394 this.phone = phone;
395 }
396 this.workSource = workSource;
397 }
398
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800401 if (subId != null) {
402 this.subId = subId;
403 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700404 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 }
407
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800408 private static final class IncomingThirdPartyCallArgs {
409 public final ComponentName component;
410 public final String callId;
411 public final String callerDisplayName;
412
413 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
414 String callerDisplayName) {
415 this.component = component;
416 this.callId = callId;
417 this.callerDisplayName = callerDisplayName;
418 }
419 }
420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /**
422 * A handler that processes messages on the main thread in the phone process. Since many
423 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
424 * inbound binder threads to the main thread in the phone process. The Binder thread
425 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
426 * on, which will be notified when the operation completes and will contain the result of the
427 * request.
428 *
429 * <p>If a MainThreadRequest object is provided in the msg.obj field,
430 * note that request.result must be set to something non-null for the calling thread to
431 * unblock.
432 */
433 private final class MainThreadHandler extends Handler {
434 @Override
435 public void handleMessage(Message msg) {
436 MainThreadRequest request;
437 Message onCompleted;
438 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800441 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
443 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 case CMD_HANDLE_USSD_REQUEST: {
445 request = (MainThreadRequest) msg.obj;
446 final Phone phone = getPhoneFromRequest(request);
447 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
448 String ussdRequest = ussdObject.first;
449 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 if (!isUssdApiAllowed(request.subId)) {
452 // Carrier does not support use of this API, return failure.
453 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
454 UssdResponse response = new UssdResponse(ussdRequest, null);
455 Bundle returnData = new Bundle();
456 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
457 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 request.result = true;
460 notifyRequester(request);
461 return;
462 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700463
Pengquan Menga1bb6272018-09-06 09:59:22 -0700464 try {
465 request.result = phone != null
466 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
467 } catch (CallStateException cse) {
468 request.result = false;
469 }
470 // Wake up the requesting thread
471 notifyRequester(request);
472 break;
pkanwar32d516d2016-10-14 19:37:38 -0700473 }
474
Yorke Lee716f67e2015-06-17 15:39:16 -0700475 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 final Phone phone = getPhoneFromRequest(request);
478 request.result = phone != null ?
479 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
480 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduLogicalChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
496 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 iccArgument.channel, iccArgument.cla, iccArgument.command,
499 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 break;
503
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 if (ar.result == null) {
512 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800513 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800515 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 } else {
517 loge("iccTransmitApduLogicalChannel: Unknown exception");
518 }
519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 break;
522
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
524 request = (MainThreadRequest) msg.obj;
525 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 if (uiccCard == null) {
528 loge("iccTransmitApduBasicChannel: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 } else {
532 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
533 request);
534 uiccCard.iccTransmitApduBasicChannel(
535 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
536 iccArgument.p3, iccArgument.data, onCompleted);
537 }
538 break;
539
540 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduBasicChannel: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("iccTransmitApduBasicChannel: CommandException: " +
551 ar.exception);
552 } else {
553 loge("iccTransmitApduBasicChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
559 case CMD_EXCHANGE_SIM_IO:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccExchangeSimIO: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
569 request);
570 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
571 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
572 iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_EXCHANGE_SIM_IO_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6f, 0, (byte[])null);
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 case CMD_SEND_ENVELOPE:
588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("sendEnvelopeWithStatus: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
596 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
597 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800598 break;
599
600 case EVENT_SEND_ENVELOPE_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700603 if (ar.exception == null && ar.result != null) {
604 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800605 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
607 if (ar.result == null) {
608 loge("sendEnvelopeWithStatus: Empty response");
609 } else if (ar.exception instanceof CommandException) {
610 loge("sendEnvelopeWithStatus: CommandException: " +
611 ar.exception);
612 } else {
613 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
614 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 break;
618
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 case CMD_OPEN_CHANNEL:
620 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 if (uiccCard == null) {
624 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800625 request.result = new IccOpenLogicalChannelResponse(-1,
626 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800630 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
631 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_OPEN_CHANNEL_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 int[] result = (int[]) ar.result;
641 int channelId = result[0];
642 byte[] selectResponse = null;
643 if (result.length > 1) {
644 selectResponse = new byte[result.length - 1];
645 for (int i = 1; i < result.length; ++i) {
646 selectResponse[i - 1] = (byte) result[i];
647 }
648 }
649 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700650 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 if (ar.result == null) {
653 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 if (ar.exception != null) {
656 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
657 }
658
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700660 if (ar.exception instanceof CommandException) {
661 CommandException.Error error =
662 ((CommandException) (ar.exception)).getCommandError();
663 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700664 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700665 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 }
668 }
669 openChannelResp = new IccOpenLogicalChannelResponse(
670 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700672 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case CMD_CLOSE_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800678 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 if (uiccCard == null) {
680 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900681 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 } else {
684 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
685 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
689 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800690 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
691 break;
692
693 case CMD_NV_READ_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800706 request.result = "";
707 if (ar.result == null) {
708 loge("nvReadItem: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("nvReadItem: CommandException: " +
711 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800713 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
Jake Hambye994d462014-02-03 13:10:13 -0800719 case CMD_NV_WRITE_ITEM:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
722 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700724 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
727 case EVENT_NV_WRITE_ITEM_DONE:
728 handleNullReturnEvent(msg, "nvWriteItem");
729 break;
730
731 case CMD_NV_WRITE_CDMA_PRL:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_WRITE_CDMA_PRL_DONE:
738 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
739 break;
740
chen xu6dac5ab2018-10-26 17:39:23 -0700741 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800742 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700743 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
chen xu6dac5ab2018-10-26 17:39:23 -0700747 case EVENT_RESET_MODEM_CONFIG_DONE:
748 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800749 break;
750
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 case CMD_GET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result; // Integer
762 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800763 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800764 if (ar.result == null) {
765 loge("getPreferredNetworkType: Empty response");
766 } else if (ar.exception instanceof CommandException) {
767 loge("getPreferredNetworkType: CommandException: " +
768 ar.exception);
769 } else {
770 loge("getPreferredNetworkType: Unknown exception");
771 }
772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800774 break;
775
776 case CMD_SET_PREFERRED_NETWORK_TYPE:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
779 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700780 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800781 break;
782
783 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
784 handleNullReturnEvent(msg, "setPreferredNetworkType");
785 break;
786
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
788 request = (MainThreadRequest)msg.obj;
789 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000791 break;
792
793 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
794 ar = (AsyncResult)msg.obj;
795 request = (MainThreadRequest)ar.userObj;
796 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000798 break;
799
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800 case CMD_SET_VOICEMAIL_NUMBER:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
803 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800804 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
805 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800806 break;
807
808 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
809 handleNullReturnEvent(msg, "setVoicemailNumber");
810 break;
811
Stuart Scott54788802015-03-30 13:18:01 -0700812 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
815 request);
816 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
821 break;
822
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 case CMD_PERFORM_NETWORK_SCAN:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
826 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
827 break;
828
Shuo Qian4a594052020-01-23 11:59:30 -0800829 case CMD_GET_CALL_FORWARDING:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
832 int callForwardingReason = (Integer) request.argument;
833 getPhoneFromRequest(request).getCallForwardingOption(
834 callForwardingReason, onCompleted);
835 break;
836
837 case EVENT_GET_CALL_FORWARDING_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 CallForwardingInfo callForwardingInfo = null;
841 if (ar.exception == null && ar.result != null) {
842 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
843 for (CallForwardInfo callForwardInfo : callForwardInfos) {
844 // Service Class is a bit mask per 3gpp 27.007. Search for
845 // any service for voice call.
846 if ((callForwardInfo.serviceClass
847 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
848 callForwardingInfo = new CallForwardingInfo(
849 callForwardInfo.serviceClass, callForwardInfo.reason,
850 callForwardInfo.number,
851 callForwardInfo.timeSeconds);
852 break;
853 }
854 }
855 // Didn't find a call forward info for voice call.
856 if (callForwardingInfo == null) {
857 callForwardingInfo = new CallForwardingInfo(
858 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
859 0 /* reason */, null /* number */, 0 /* timeout */);
860 }
861 } else {
862 if (ar.result == null) {
863 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
864 }
865 if (ar.exception != null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
867 }
868 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
869 if (ar.exception instanceof CommandException) {
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
873 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
874 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
876 }
877 }
878 callForwardingInfo = new CallForwardingInfo(
879 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
880 }
881 request.result = callForwardingInfo;
882 notifyRequester(request);
883 break;
884
885 case CMD_SET_CALL_FORWARDING:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
888 CallForwardingInfo callForwardingInfoToSet =
889 (CallForwardingInfo) request.argument;
890 getPhoneFromRequest(request).setCallForwardingOption(
891 callForwardingInfoToSet.getStatus(),
892 callForwardingInfoToSet.getReason(),
893 callForwardingInfoToSet.getNumber(),
894 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
895 break;
896
897 case EVENT_SET_CALL_FORWARDING_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null) {
901 request.result = true;
902 } else {
903 request.result = false;
904 loge("setCallForwarding exception: " + ar.exception);
905 }
906 notifyRequester(request);
907 break;
908
909 case CMD_GET_CALL_WAITING:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
912 getPhoneFromRequest(request).getCallWaiting(onCompleted);
913 break;
914
915 case EVENT_GET_CALL_WAITING_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
919 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800920 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800921 // Service Class is a bit mask per 3gpp 27.007.
922 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 if (callForwardResults.length > 1
924 && ((callForwardResults[1]
925 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
926 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800927 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
928 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
929 } else {
930 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
931 }
932 } else {
933 if (ar.result == null) {
934 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
935 }
936 if (ar.exception != null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
938 }
939 if (ar.exception instanceof CommandException) {
940 CommandException.Error error =
941 ((CommandException) (ar.exception)).getCommandError();
942 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
943 callForwardingStatus =
944 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
945 }
946 }
947 }
948 request.result = callForwardingStatus;
949 notifyRequester(request);
950 break;
951
952 case CMD_SET_CALL_WAITING:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
955 boolean isEnable = (Boolean) request.argument;
956 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
957 break;
958
959 case EVENT_SET_CALL_WAITING_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null) {
963 request.result = true;
964 } else {
965 request.result = false;
966 loge("setCallWaiting exception: " + ar.exception);
967 }
968 notifyRequester(request);
969 break;
970
Shishir Agrawal302c8692015-06-19 13:49:39 -0700971 case EVENT_PERFORM_NETWORK_SCAN_DONE:
972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
974 CellNetworkScanResult cellScanResult;
975 if (ar.exception == null && ar.result != null) {
976 cellScanResult = new CellNetworkScanResult(
977 CellNetworkScanResult.STATUS_SUCCESS,
978 (List<OperatorInfo>) ar.result);
979 } else {
980 if (ar.result == null) {
981 loge("getCellNetworkScanResults: Empty response");
982 }
983 if (ar.exception != null) {
984 loge("getCellNetworkScanResults: Exception: " + ar.exception);
985 }
986 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
991 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
992 } else if (error == CommandException.Error.GENERIC_FAILURE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
994 }
995 }
996 cellScanResult = new CellNetworkScanResult(errorCode, null);
997 }
998 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 break;
1001
1002 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1003 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001004 ManualNetworkSelectionArgument selArg =
1005 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001006 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1007 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001008 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1009 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001010 break;
1011
1012 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result = true;
1017 } else {
1018 request.result = false;
1019 loge("setNetworkSelectionModeManual " + ar.exception);
1020 }
1021 notifyRequester(request);
1022 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001023 break;
1024
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001025 case CMD_GET_MODEM_ACTIVITY_INFO:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001028 if (defaultPhone != null) {
1029 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian1d931ee2020-02-20 17:12:10 -08001030 } else {
1031 ResultReceiver result = (ResultReceiver) request.argument;
1032 Bundle bundle = new Bundle();
1033 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1034 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1035 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001036 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001037 break;
1038
1039 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
Shuo Qian1d931ee2020-02-20 17:12:10 -08001042 ResultReceiver result = (ResultReceiver) request.argument;
1043
1044 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001045 if (ar.exception == null && ar.result != null) {
Shuo Qian1d931ee2020-02-20 17:12:10 -08001046 // Update the last modem activity info and the result of the request.
1047 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1048 if (isModemActivityInfoValid(info)) {
1049 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1050 int[] txTimeMs = info.getTransmitTimeMillis();
1051 int[] lastModemTxTimeMs = mLastModemActivityInfo
1052 .getTransmitTimeMillis();
1053 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1054 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1055 }
1056 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1057 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1058 + mLastModemActivityInfo.getSleepTimeMillis());
1059 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1060 + mLastModemActivityInfo.getIdleTimeMillis());
1061 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1062 mLastModemActivityInfo.setReceiveTimeMillis(
1063 info.getReceiveTimeMillis()
1064 + mLastModemActivityInfo.getReceiveTimeMillis());
1065 }
1066 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1067 mLastModemActivityInfo.getSleepTimeMillis(),
1068 mLastModemActivityInfo.getIdleTimeMillis(),
1069 mLastModemActivityInfo.getTransmitTimeMillis(),
1070 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001071 } else {
1072 if (ar.result == null) {
1073 loge("queryModemActivityInfo: Empty response");
1074 } else if (ar.exception instanceof CommandException) {
1075 loge("queryModemActivityInfo: CommandException: " +
1076 ar.exception);
1077 } else {
1078 loge("queryModemActivityInfo: Unknown exception");
1079 }
1080 }
Shuo Qian1d931ee2020-02-20 17:12:10 -08001081 Bundle bundle = new Bundle();
1082 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1083 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001084 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001085 break;
1086
Meng Wang1a7c35a2016-05-05 20:56:15 -07001087 case CMD_SET_ALLOWED_CARRIERS:
1088 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001089 CarrierRestrictionRules argument =
1090 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001091 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001092 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001093 break;
1094
1095 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null && ar.result != null) {
1099 request.result = ar.result;
1100 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001101 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1102 if (ar.exception instanceof CommandException) {
1103 loge("setAllowedCarriers: CommandException: " + ar.exception);
1104 CommandException.Error error =
1105 ((CommandException) (ar.exception)).getCommandError();
1106 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1107 request.result =
1108 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1109 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001110 } else {
1111 loge("setAllowedCarriers: Unknown exception");
1112 }
1113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001115 break;
1116
1117 case CMD_GET_ALLOWED_CARRIERS:
1118 request = (MainThreadRequest) msg.obj;
1119 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001120 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001121 break;
1122
1123 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 if (ar.exception == null && ar.result != null) {
1127 request.result = ar.result;
1128 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001129 request.result = new IllegalStateException(
1130 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001131 if (ar.result == null) {
1132 loge("getAllowedCarriers: Empty response");
1133 } else if (ar.exception instanceof CommandException) {
1134 loge("getAllowedCarriers: CommandException: " +
1135 ar.exception);
1136 } else {
1137 loge("getAllowedCarriers: Unknown exception");
1138 }
1139 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001141 break;
1142
Nathan Haroldb3014052017-01-25 15:57:32 -08001143 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 if (ar.exception == null && ar.result != null) {
1147 request.result = ar.result;
1148 } else {
1149 request.result = new IllegalArgumentException(
1150 "Failed to retrieve Forbidden Plmns");
1151 if (ar.result == null) {
1152 loge("getForbiddenPlmns: Empty response");
1153 } else {
1154 loge("getForbiddenPlmns: Unknown exception");
1155 }
1156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001158 break;
1159
1160 case CMD_GET_FORBIDDEN_PLMNS:
1161 request = (MainThreadRequest) msg.obj;
1162 uiccCard = getUiccCardFromRequest(request);
1163 if (uiccCard == null) {
1164 loge("getForbiddenPlmns() UiccCard is null");
1165 request.result = new IllegalArgumentException(
1166 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001168 break;
1169 }
1170 Integer appType = (Integer) request.argument;
1171 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1172 if (uiccApp == null) {
1173 loge("getForbiddenPlmns() no app with specified type -- "
1174 + appType);
1175 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001177 break;
1178 } else {
1179 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1180 + " specified type -- " + appType);
1181 }
1182 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1183 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1184 onCompleted);
1185 break;
1186
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001187 case CMD_SWITCH_SLOTS:
1188 request = (MainThreadRequest) msg.obj;
1189 int[] physicalSlots = (int[]) request.argument;
1190 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1191 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1192 break;
1193
1194 case EVENT_SWITCH_SLOTS_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001198 notifyRequester(request);
1199 break;
1200 case CMD_GET_NETWORK_SELECTION_MODE:
1201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1203 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1204 break;
1205
1206 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
1209 if (ar.exception != null) {
1210 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1211 } else {
1212 int mode = ((int[]) ar.result)[0];
1213 if (mode == 0) {
1214 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1215 } else {
1216 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1217 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001218 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001219 notifyRequester(request);
1220 break;
1221 case CMD_GET_CDMA_ROAMING_MODE:
1222 request = (MainThreadRequest) msg.obj;
1223 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1224 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1225 break;
1226 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1227 ar = (AsyncResult) msg.obj;
1228 request = (MainThreadRequest) ar.userObj;
1229 if (ar.exception != null) {
1230 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1231 } else {
1232 request.result = ((int[]) ar.result)[0];
1233 }
1234 notifyRequester(request);
1235 break;
1236 case CMD_SET_CDMA_ROAMING_MODE:
1237 request = (MainThreadRequest) msg.obj;
1238 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1239 int mode = (int) request.argument;
1240 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1241 break;
1242 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1243 ar = (AsyncResult) msg.obj;
1244 request = (MainThreadRequest) ar.userObj;
1245 request.result = ar.exception == null;
1246 notifyRequester(request);
1247 break;
1248 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1251 int subscriptionMode = (int) request.argument;
1252 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1253 break;
1254 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1255 ar = (AsyncResult) msg.obj;
1256 request = (MainThreadRequest) ar.userObj;
1257 request.result = ar.exception == null;
1258 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001259 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 case CMD_GET_ALL_CELL_INFO:
1261 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001262 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001263 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 case EVENT_GET_ALL_CELL_INFO_DONE:
1266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001268 // If a timeout occurs, the response will be null
1269 request.result = (ar.exception == null && ar.result != null)
1270 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 synchronized (request) {
1272 request.notifyAll();
1273 }
1274 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001275 case CMD_REQUEST_CELL_INFO_UPDATE:
1276 request = (MainThreadRequest) msg.obj;
1277 request.phone.requestCellInfoUpdate(request.workSource,
1278 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1279 break;
1280 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
1283 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1284 try {
1285 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001287 cb.onError(
1288 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1289 ar.exception.getClass().getName(),
1290 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001293 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 } else {
1295 // use the result as returned
1296 cb.onCellInfo((List<CellInfo>) ar.result);
1297 }
1298 } catch (RemoteException re) {
1299 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1300 }
1301 break;
1302 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001303 request = (MainThreadRequest) msg.obj;
1304 WorkSource ws = (WorkSource) request.argument;
1305 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001306 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001307 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001308 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null) {
1312 request.result = ar.result;
1313 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001314 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001315 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001316 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001317 }
1318
1319 synchronized (request) {
1320 request.notifyAll();
1321 }
1322 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001323 case CMD_MODEM_REBOOT:
1324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001327 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001328 case EVENT_CMD_MODEM_REBOOT_DONE:
1329 handleNullReturnEvent(msg, "rebootModem");
1330 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001331 case CMD_REQUEST_ENABLE_MODEM:
1332 request = (MainThreadRequest) msg.obj;
1333 boolean enable = (boolean) request.argument;
1334 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001335 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001336 PhoneConfigurationManager.getInstance()
1337 .enablePhone(request.phone, enable, onCompleted);
1338 break;
1339 case EVENT_ENABLE_MODEM_DONE:
1340 ar = (AsyncResult) msg.obj;
1341 request = (MainThreadRequest) ar.userObj;
1342 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001343 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001344 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001345 if ((boolean) request.result) {
1346 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1347 updateModemStateMetrics();
1348 } else {
1349 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1350 + ar.exception);
1351 }
1352 notifyRequester(request);
1353 break;
1354 case CMD_GET_MODEM_STATUS:
1355 request = (MainThreadRequest) msg.obj;
1356 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1357 PhoneConfigurationManager.getInstance()
1358 .getPhoneStatusFromModem(request.phone, onCompleted);
1359 break;
1360 case EVENT_GET_MODEM_STATUS_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 int id = request.phone.getPhoneId();
1364 if (ar.exception == null && ar.result != null) {
1365 request.result = ar.result;
1366 //update the cache as modem status has changed
1367 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1368 (boolean) request.result);
1369 } else {
1370 // Return true if modem status cannot be retrieved. For most cases,
1371 // modem status is on. And for older version modems, GET_MODEM_STATUS
1372 // and disable modem are not supported. Modem is always on.
1373 // TODO: this should be fixed in R to support a third
1374 // status UNKNOWN b/131631629
1375 request.result = true;
1376 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1377 + ar.exception);
1378 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001379 notifyRequester(request);
1380 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001381 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1382 request = (MainThreadRequest) msg.obj;
1383 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1384 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1385 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1386 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1387 break;
1388 }
1389 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
1392 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1393 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1394 args.second.accept(ar.exception == null);
1395 notifyRequester(request);
1396 break;
1397 }
yincheng zhao2737e882019-09-06 17:06:54 -07001398 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null && ar.result != null) {
1402 request.result = ar.result;
1403 } else {
1404 request.result = -1;
1405 loge("Failed to set Forbidden Plmns");
1406 if (ar.result == null) {
1407 loge("setForbidenPlmns: Empty response");
1408 } else if (ar.exception != null) {
1409 loge("setForbiddenPlmns: Exception: " + ar.exception);
1410 request.result = -1;
1411 } else {
1412 loge("setForbiddenPlmns: Unknown exception");
1413 }
1414 }
1415 notifyRequester(request);
1416 break;
1417 case CMD_SET_FORBIDDEN_PLMNS:
1418 request = (MainThreadRequest) msg.obj;
1419 uiccCard = getUiccCardFromRequest(request);
1420 if (uiccCard == null) {
1421 loge("setForbiddenPlmns: UiccCard is null");
1422 request.result = -1;
1423 notifyRequester(request);
1424 break;
1425 }
1426 Pair<Integer, List<String>> setFplmnsArgs =
1427 (Pair<Integer, List<String>>) request.argument;
1428 appType = setFplmnsArgs.first;
1429 List<String> fplmns = setFplmnsArgs.second;
1430 uiccApp = uiccCard.getApplicationByType(appType);
1431 if (uiccApp == null) {
1432 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1433 request.result = -1;
1434 loge("Failed to get UICC App");
1435 notifyRequester(request);
1436 } else {
1437 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1438 ((SIMRecords) uiccApp.getIccRecords())
1439 .setForbiddenPlmns(onCompleted, fplmns);
1440 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001441 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001442 case CMD_ERASE_MODEM_CONFIG:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1445 defaultPhone.eraseModemConfig(onCompleted);
1446 break;
1447 case EVENT_ERASE_MODEM_CONFIG_DONE:
1448 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001449 break;
zoey chene02881a2019-12-30 16:11:23 +08001450
1451 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1454 Pair<String, String> changed = (Pair<String, String>) request.argument;
1455 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1456 changed.first, changed.second, onCompleted);
1457 break;
1458 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
1461 if (ar.exception == null) {
1462 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1463 } else {
1464 request.result = msg.arg1;
1465 }
1466 notifyRequester(request);
1467 break;
1468
1469 case CMD_SET_ICC_LOCK_ENABLED:
1470 request = (MainThreadRequest) msg.obj;
1471 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1472 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1473 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1474 enabled.first, enabled.second, onCompleted);
1475 break;
1476 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 if (ar.exception == null) {
1480 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1481 } else {
1482 request.result = msg.arg1;
1483 }
1484 notifyRequester(request);
1485 break;
1486
Peter Wangdafb9ac2020-01-15 14:13:38 -08001487 case MSG_NOTIFY_USER_ACTIVITY:
1488 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001489 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001490 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1491 getDefaultPhone().getContext().sendBroadcastAsUser(
1492 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1493 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 default:
1495 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1496 break;
1497 }
1498 }
Jake Hambye994d462014-02-03 13:10:13 -08001499
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 private void notifyRequester(MainThreadRequest request) {
1501 synchronized (request) {
1502 request.notifyAll();
1503 }
1504 }
1505
Jake Hambye994d462014-02-03 13:10:13 -08001506 private void handleNullReturnEvent(Message msg, String command) {
1507 AsyncResult ar = (AsyncResult) msg.obj;
1508 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null) {
1510 request.result = true;
1511 } else {
1512 request.result = false;
1513 if (ar.exception instanceof CommandException) {
1514 loge(command + ": CommandException: " + ar.exception);
1515 } else {
1516 loge(command + ": Unknown exception");
1517 }
1518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
1522
1523 /**
1524 * Posts the specified command to be executed on the main thread,
1525 * waits for the request to complete, and returns the result.
1526 * @see #sendRequestAsync
1527 */
1528 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001529 return sendRequest(
1530 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001531 }
1532
1533 /**
1534 * Posts the specified command to be executed on the main thread,
1535 * waits for the request to complete, and returns the result.
1536 * @see #sendRequestAsync
1537 */
1538 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1539 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001540 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
1543 /**
1544 * Posts the specified command to be executed on the main thread,
1545 * waits for the request to complete, and returns the result.
1546 * @see #sendRequestAsync
1547 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001548 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001549 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001550 }
1551
1552 /**
1553 * Posts the specified command to be executed on the main thread,
1554 * waits for the request to complete, and returns the result.
1555 * @see #sendRequestAsync
1556 */
Nathan Harold92bed182018-10-12 18:16:49 -07001557 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1558 return sendRequest(command, argument, subId, null, workSource);
1559 }
1560
1561 /**
1562 * Posts the specified command to be executed on the main thread,
1563 * waits for the request to complete, and returns the result.
1564 * @see #sendRequestAsync
1565 */
1566 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1567 return sendRequest(
1568 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1569 }
1570
1571 /**
1572 * Posts the specified command to be executed on the main thread,
1573 * waits for the request to complete, and returns the result.
1574 * @see #sendRequestAsync
1575 */
1576 private Object sendRequest(
1577 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1579 throw new RuntimeException("This method will deadlock if called from the main thread.");
1580 }
1581
Nathan Harold92bed182018-10-12 18:16:49 -07001582 MainThreadRequest request = null;
1583 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1584 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1585 } else if (phone != null) {
1586 request = new MainThreadRequest(argument, phone, workSource);
1587 } else {
1588 request = new MainThreadRequest(argument, subId, workSource);
1589 }
1590
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 Message msg = mMainThreadHandler.obtainMessage(command, request);
1592 msg.sendToTarget();
1593
1594 // Wait for the request to complete
1595 synchronized (request) {
1596 while (request.result == null) {
1597 try {
1598 request.wait();
1599 } catch (InterruptedException e) {
1600 // Do nothing, go back and wait until the request is complete
1601 }
1602 }
1603 }
1604 return request.result;
1605 }
1606
1607 /**
1608 * Asynchronous ("fire and forget") version of sendRequest():
1609 * Posts the specified command to be executed on the main thread, and
1610 * returns immediately.
1611 * @see #sendRequest
1612 */
1613 private void sendRequestAsync(int command) {
1614 mMainThreadHandler.sendEmptyMessage(command);
1615 }
1616
1617 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001618 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001619 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001620 */
1621 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001622 sendRequestAsync(command, argument, null, null);
1623 }
1624
1625 /**
1626 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1627 * @see {@link #sendRequest(int,Object)}
1628 */
1629 private void sendRequestAsync(
1630 int command, Object argument, Phone phone, WorkSource workSource) {
1631 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001632 Message msg = mMainThreadHandler.obtainMessage(command, request);
1633 msg.sendToTarget();
1634 }
1635
1636 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 * Initialize the singleton PhoneInterfaceManager instance.
1638 * This is only done once, at startup, from PhoneApp.onCreate().
1639 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001640 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 synchronized (PhoneInterfaceManager.class) {
1642 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001643 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 } else {
1645 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1646 }
1647 return sInstance;
1648 }
1649 }
1650
1651 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001652 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001655 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001656 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1658 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001659 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001660 mTelephonySharedPreferences =
1661 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001662 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001663 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001664 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 publish();
1667 }
1668
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001669 private Phone getDefaultPhone() {
1670 Phone thePhone = getPhone(getDefaultSubscription());
1671 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1672 }
1673
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 private void publish() {
1675 if (DBG) log("publish: " + this);
1676
Peter Wangc035ce42020-01-08 21:00:22 -08001677 TelephonyFrameworkInitializer
1678 .getTelephonyServiceManager()
1679 .getTelephonyServiceRegisterer()
1680 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Stuart Scott584921c2015-01-15 17:10:34 -08001683 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001684 if (request.phone != null) {
1685 return request.phone;
1686 } else {
1687 return getPhoneFromSubId(request.subId);
1688 }
1689 }
1690
1691 private Phone getPhoneFromSubId(int subId) {
1692 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1693 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001694 }
1695
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001696 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1697 Phone phone = getPhoneFromRequest(request);
1698 return phone == null ? null :
1699 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1700 }
1701
Wink Saville36469e72014-06-11 15:17:00 -07001702 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001704 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706
Naina Nallurid63128d2019-09-17 14:10:30 -07001707 private void sendEraseModemConfig(Phone phone) {
1708 if (phone != null) {
1709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1710 mApp, phone.getSubId(), "eraseModemConfig");
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1714 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
1717 }
1718 }
1719 }
1720
Peter Wang44b186e2020-01-13 23:33:09 -08001721 private boolean isImsAvailableOnDevice() {
1722 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1723 if (pm == null) {
1724 // For some reason package manger is not available.. This will fail internally anyway,
1725 // so do not throw error and allow.
1726 return true;
1727 }
1728 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1729 }
1730
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001732 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001733 }
1734
Wink Savilleb564aae2014-10-23 10:18:09 -07001735 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 if (DBG) log("dial: " + number);
1737 // No permission check needed here: This is just a wrapper around the
1738 // ACTION_DIAL intent, which is available to any app since it puts up
1739 // the UI before it does anything.
1740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001741 final long identity = Binder.clearCallingIdentity();
1742 try {
1743 String url = createTelUrl(number);
1744 if (url == null) {
1745 return;
1746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001748 // PENDING: should we just silently fail if phone is offhook or ringing?
1749 PhoneConstants.State state = mCM.getState(subId);
1750 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1751 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1752 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1753 mApp.startActivity(intent);
1754 }
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758 }
1759
1760 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001761 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 if (DBG) log("call: " + number);
1766
1767 // This is just a wrapper around the ACTION_CALL intent, but we still
1768 // need to do a permission check since we're calling startActivity()
1769 // from the context of the phone app.
1770 enforceCallPermission();
1771
Jordan Liu1617b712019-07-10 15:06:26 -07001772 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 != AppOpsManager.MODE_ALLOWED) {
1774 return;
1775 }
1776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 String url = createTelUrl(number);
1780 if (url == null) {
1781 return;
1782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 boolean isValid = false;
1785 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1786 if (slist != null) {
1787 for (SubscriptionInfo subInfoRecord : slist) {
1788 if (subInfoRecord.getSubscriptionId() == subId) {
1789 isValid = true;
1790 break;
1791 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001792 }
Wink Saville08874612014-08-31 19:19:58 -07001793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794 if (!isValid) {
1795 return;
1796 }
Wink Saville08874612014-08-31 19:19:58 -07001797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1799 intent.putExtra(SUBSCRIPTION_KEY, subId);
1800 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1801 mApp.startActivity(intent);
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
1804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001808 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001809 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1810 }
1811
Wink Savilleb564aae2014-10-23 10:18:09 -07001812 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001813 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001814 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1815 }
1816
Wink Savilleb564aae2014-10-23 10:18:09 -07001817 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1823 checkSimPin.start();
1824 return checkSimPin.unlockSim(null, pin);
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Wink Savilleb564aae2014-10-23 10:18:09 -07001830 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1836 checkSimPuk.start();
1837 return checkSimPuk.unlockSim(puk, pin);
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
1840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
1842
1843 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001844 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 * a synchronous one.
1846 */
1847 private static class UnlockSim extends Thread {
1848
1849 private final IccCard mSimCard;
1850
1851 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001852 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1853 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854
1855 // For replies from SimCard interface
1856 private Handler mHandler;
1857
1858 // For async handler to identify request type
1859 private static final int SUPPLY_PIN_COMPLETE = 100;
1860
1861 public UnlockSim(IccCard simCard) {
1862 mSimCard = simCard;
1863 }
1864
1865 @Override
1866 public void run() {
1867 Looper.prepare();
1868 synchronized (UnlockSim.this) {
1869 mHandler = new Handler() {
1870 @Override
1871 public void handleMessage(Message msg) {
1872 AsyncResult ar = (AsyncResult) msg.obj;
1873 switch (msg.what) {
1874 case SUPPLY_PIN_COMPLETE:
1875 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1876 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001877 mRetryCount = msg.arg1;
1878 if (ar.exception != null) {
1879 if (ar.exception instanceof CommandException &&
1880 ((CommandException)(ar.exception)).getCommandError()
1881 == CommandException.Error.PASSWORD_INCORRECT) {
1882 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1883 } else {
1884 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1885 }
1886 } else {
1887 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 mDone = true;
1890 UnlockSim.this.notifyAll();
1891 }
1892 break;
1893 }
1894 }
1895 };
1896 UnlockSim.this.notifyAll();
1897 }
1898 Looper.loop();
1899 }
1900
1901 /*
1902 * Use PIN or PUK to unlock SIM card
1903 *
1904 * If PUK is null, unlock SIM card with PIN
1905 *
1906 * If PUK is not null, unlock SIM card with PUK and set PIN code
1907 */
Wink Saville9de0f752013-10-22 19:04:03 -07001908 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909
1910 while (mHandler == null) {
1911 try {
1912 wait();
1913 } catch (InterruptedException e) {
1914 Thread.currentThread().interrupt();
1915 }
1916 }
1917 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1918
1919 if (puk == null) {
1920 mSimCard.supplyPin(pin, callback);
1921 } else {
1922 mSimCard.supplyPuk(puk, pin, callback);
1923 }
1924
1925 while (!mDone) {
1926 try {
1927 Log.d(LOG_TAG, "wait for done");
1928 wait();
1929 } catch (InterruptedException e) {
1930 // Restore the interrupted status
1931 Thread.currentThread().interrupt();
1932 }
1933 }
1934 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001935 int[] resultArray = new int[2];
1936 resultArray[0] = mResult;
1937 resultArray[1] = mRetryCount;
1938 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 }
1940 }
1941
1942 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001943 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944
1945 }
1946
Wink Savilleb564aae2014-10-23 10:18:09 -07001947 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 // No permission check needed here: this call is harmless, and it's
1949 // needed for the ServiceState.requestStateUpdate() call (which is
1950 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001951 final long identity = Binder.clearCallingIdentity();
1952 try {
1953 final Phone phone = getPhone(subId);
1954 if (phone != null) {
1955 phone.updateServiceLocation();
1956 }
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001962 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 @Override
1964 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001965 return isRadioOnWithFeature(callingPackage, null);
1966 }
1967
1968
1969 @Override
1970 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1971 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1972 callingFeatureId);
1973 }
1974
1975 @Deprecated
1976 @Override
1977 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1978 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001979 }
1980
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001982 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1983 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001985 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001986 return false;
1987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988
1989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 return isRadioOnForSubscriber(subId);
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
1994 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001995 }
1996
1997 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 final Phone phone = getPhone(subId);
2001 if (phone != null) {
2002 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2003 } else {
2004 return false;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002012 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
Wink Saville36469e72014-06-11 15:17:00 -07002014
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 final Phone phone = getPhone(subId);
2021 if (phone != null) {
2022 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2023 }
2024 } finally {
2025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002026 }
Wink Saville36469e72014-06-11 15:17:00 -07002027 }
2028
2029 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002030 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002031 }
2032
Wink Savilleb564aae2014-10-23 10:18:09 -07002033 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035
2036 final long identity = Binder.clearCallingIdentity();
2037 try {
2038 final Phone phone = getPhone(subId);
2039 if (phone == null) {
2040 return false;
2041 }
2042 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2043 toggleRadioOnOffForSubscriber(subId);
2044 }
2045 return true;
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
Wink Saville36469e72014-06-11 15:17:00 -07002050
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002051 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002052 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 /*
2054 * If any of the Radios are available, it will need to be
2055 * shutdown. So return true if any Radio is available.
2056 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2060 Phone phone = PhoneFactory.getPhone(i);
2061 if (phone != null && phone.isRadioAvailable()) return true;
2062 }
2063 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2064 return false;
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002067 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002068 }
2069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002071 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 enforceModifyPermission();
2073
2074 final long identity = Binder.clearCallingIdentity();
2075 try {
2076 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2077 logv("Shutting down Phone " + i);
2078 shutdownRadioUsingPhoneId(i);
2079 }
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002082 }
2083 }
2084
2085 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002086 Phone phone = PhoneFactory.getPhone(phoneId);
2087 if (phone != null && phone.isRadioAvailable()) {
2088 phone.shutdownRadio();
2089 }
2090 }
2091
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2098 if (defaultPhone != null) {
2099 defaultPhone.setRadioPower(turnOn);
2100 return true;
2101 } else {
2102 loge("There's no default phone.");
2103 return false;
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002107 }
Wink Saville36469e72014-06-11 15:17:00 -07002108 }
2109
Wink Savilleb564aae2014-10-23 10:18:09 -07002110 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 final Phone phone = getPhone(subId);
2116 if (phone != null) {
2117 phone.setRadioPower(turnOn);
2118 return true;
2119 } else {
2120 return false;
2121 }
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 }
2126
Wink Saville36469e72014-06-11 15:17:00 -07002127 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 public boolean enableDataConnectivity() {
2130 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 int subId = mSubscriptionController.getDefaultDataSubId();
2135 final Phone phone = getPhone(subId);
2136 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002137 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002138 return true;
2139 } else {
2140 return false;
2141 }
2142 } finally {
2143 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 }
2146
Wink Saville36469e72014-06-11 15:17:00 -07002147 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 public boolean disableDataConnectivity() {
2150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002151
2152 final long identity = Binder.clearCallingIdentity();
2153 try {
2154 int subId = mSubscriptionController.getDefaultDataSubId();
2155 final Phone phone = getPhone(subId);
2156 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002157 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 return true;
2159 } else {
2160 return false;
2161 }
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002168 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 final long identity = Binder.clearCallingIdentity();
2170 try {
2171 final Phone phone = getPhone(subId);
2172 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002173 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 } else {
2175 return false;
2176 }
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
2181
2182 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002183 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
pkanwarae03a6b2016-11-06 20:37:09 -08002186 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 enforceCallPermission();
2188
2189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2192 return;
2193 }
2194 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2195 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
2198 }
pkanwar32d516d2016-10-14 19:37:38 -07002199 };
2200
Wink Savilleb564aae2014-10-23 10:18:09 -07002201 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002203
2204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2207 return false;
2208 }
2209 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 }
2214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002216 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002217 }
2218
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002219 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 Phone phone = PhoneFactory.getPhone(slotIndex);
2223 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2224 PhoneConstantConversions.convertCallState(phone.getState());
2225 } finally {
2226 Binder.restoreCallingIdentity(identity);
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002231 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002232 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2233 }
2234
2235 @Override
2236 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237 final long identity = Binder.clearCallingIdentity();
2238 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002239 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 if (phone != null) {
2241 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2242 } else {
2243 return PhoneConstantConversions.convertDataState(
2244 PhoneConstants.DataState.DISCONNECTED);
2245 }
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
Sanket Padawe356d7632015-06-22 14:03:32 -07002251 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002252 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002253 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2254 }
2255
2256 @Override
2257 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002260 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 if (phone != null) {
2262 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2263 } else {
2264 return TelephonyManager.DATA_ACTIVITY_NONE;
2265 }
2266 } finally {
2267 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 }
2270
2271 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002272 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002274 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002275
2276 LocationAccessPolicy.LocationPermissionResult locationResult =
2277 LocationAccessPolicy.checkLocationPermission(mApp,
2278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2279 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002280 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002281 .setCallingPid(Binder.getCallingPid())
2282 .setCallingUid(Binder.getCallingUid())
2283 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002284 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2286 .build());
2287 switch (locationResult) {
2288 case DENIED_HARD:
2289 throw new SecurityException("Not allowed to access cell location");
2290 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002291 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2292 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002299 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002300 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
Svetoslav64fad262015-04-14 14:35:21 -07002304 }
2305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002307 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002308 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2309 // registered cell info, so return a NULL country instead.
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002312 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2313 // Get default phone in this case.
2314 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2315 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002316 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002318 if (phone == null) return "";
2319 ServiceStateTracker sst = phone.getServiceStateTracker();
2320 if (sst == null) return "";
2321 LocaleTracker lt = sst.getLocaleTracker();
2322 if (lt == null) return "";
2323 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2324 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2325 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002326 } finally {
2327 Binder.restoreCallingIdentity(identity);
2328 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002329 }
2330
2331 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002333 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002337 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 mApp.enforceCallingOrSelfPermission(
2339 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 final Phone phone = getPhone(subId);
2344 if (phone != null) {
2345 phone.enableLocationUpdates();
2346 }
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
2351
2352 @Override
2353 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002354 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002355 }
2356
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 mApp.enforceCallingOrSelfPermission(
2360 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
2365 if (phone != null) {
2366 phone.disableLocationUpdates();
2367 }
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
Nathan Harold31d7ff32018-10-15 20:20:30 -07002373 /**
2374 * Returns the target SDK version number for a given package name.
2375 *
Nathan Haroldec184742019-07-10 17:04:16 -07002376 * This call MUST be invoked before clearing the calling UID.
2377 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002378 * @return target SDK if the package is found or INT_MAX.
2379 */
2380 private int getTargetSdk(String packageName) {
2381 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002382 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002383 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002384 if (ai != null) return ai.targetSdkVersion;
2385 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002386 loge("Failed to get package info for pkg="
2387 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002388 }
2389 return Integer.MAX_VALUE;
2390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 @Override
2393 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002394 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2395 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002396 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002397 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2398 throw new SecurityException(
2399 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2400 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002401
Jordan Liu1617b712019-07-10 15:06:26 -07002402 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2404 return null;
2405 }
Svetoslav64fad262015-04-14 14:35:21 -07002406
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002407 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002409 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002410 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411
Nathan Haroldf180aac2018-06-01 18:43:55 -07002412 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2413 for (CellInfo ci : info) {
2414 if (ci instanceof CellInfoGsm) {
2415 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2416 } else if (ci instanceof CellInfoWcdma) {
2417 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002420 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002423 private List<CellInfo> getCachedCellInfo() {
2424 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2425 for (Phone phone : PhoneFactory.getPhones()) {
2426 List<CellInfo> info = phone.getAllCellInfo();
2427 if (info != null) cellInfos.addAll(info);
2428 }
2429 return cellInfos;
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431
2432 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002433 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002434 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002435 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002436
2437 LocationAccessPolicy.LocationPermissionResult locationResult =
2438 LocationAccessPolicy.checkLocationPermission(mApp,
2439 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2440 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002441 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002442 .setCallingPid(Binder.getCallingPid())
2443 .setCallingUid(Binder.getCallingUid())
2444 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002445 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002446 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2447 .build());
2448 switch (locationResult) {
2449 case DENIED_HARD:
2450 throw new SecurityException("Not allowed to access cell info");
2451 case DENIED_SOFT:
2452 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002455 final int targetSdk = getTargetSdk(callingPackage);
2456 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2457 return getCachedCellInfo();
2458 }
2459
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002460 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002461 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2465 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002466 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002467 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 if (info != null) cellInfos.addAll(info);
2469 }
2470 return cellInfos;
2471 } finally {
2472 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 }
2474 }
2475
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002476 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002477 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2478 String callingFeatureId) {
2479 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2480 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002481 }
2482
2483 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002484 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2485 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002486 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002487 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002488 }
2489
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002490 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2491 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002492 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002493 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002494
2495 LocationAccessPolicy.LocationPermissionResult locationResult =
2496 LocationAccessPolicy.checkLocationPermission(mApp,
2497 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2498 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002499 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002500 .setCallingPid(Binder.getCallingPid())
2501 .setCallingUid(Binder.getCallingUid())
2502 .setMethod("requestCellInfoUpdate")
2503 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2504 .build());
2505 switch (locationResult) {
2506 case DENIED_HARD:
2507 throw new SecurityException("Not allowed to access cell info");
2508 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002509 try {
2510 cb.onCellInfo(new ArrayList<CellInfo>());
2511 } catch (RemoteException re) {
2512 // Drop without consequences
2513 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002514 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002515 }
2516
Nathan Harolda939a962019-05-09 10:13:47 -07002517
2518 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002519 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2520
2521 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2522 }
2523
2524 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002526 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002531 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 } finally {
2533 Binder.restoreCallingIdentity(identity);
2534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 }
2536
Shishir Agrawala9f32182016-04-12 12:00:16 -07002537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002538 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002539 Phone phone = PhoneFactory.getPhone(slotIndex);
2540 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002541 return null;
2542 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002543 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002544 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002545 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002546 return null;
2547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 return phone.getImei();
2552 } finally {
2553 Binder.restoreCallingIdentity(identity);
2554 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002555 }
2556
2557 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002558 public String getTypeAllocationCodeForSlot(int slotIndex) {
2559 Phone phone = PhoneFactory.getPhone(slotIndex);
2560 String tac = null;
2561 if (phone != null) {
2562 String imei = phone.getImei();
2563 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2564 }
2565 return tac;
2566 }
2567
2568 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002569 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002570 Phone phone = PhoneFactory.getPhone(slotIndex);
2571 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002572 return null;
2573 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002574
Jeff Davidson913390f2018-02-23 17:11:49 -08002575 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002576 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002577 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002578 return null;
2579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 return phone.getMeid();
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
2586 }
Jack Yu2af8d712017-03-15 17:14:14 -07002587 }
2588
2589 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002590 public String getManufacturerCodeForSlot(int slotIndex) {
2591 Phone phone = PhoneFactory.getPhone(slotIndex);
2592 String manufacturerCode = null;
2593 if (phone != null) {
2594 String meid = phone.getMeid();
2595 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2596 }
2597 return manufacturerCode;
2598 }
2599
2600 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002601 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2602 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 Phone phone = PhoneFactory.getPhone(slotIndex);
2604 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002605 return null;
2606 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002607 int subId = phone.getSubId();
2608 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 mApp, subId, callingPackage, callingFeatureId,
2610 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002611 return null;
2612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 return phone.getDeviceSvn();
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002620 }
2621
fionaxu43304da2017-11-27 22:51:16 -08002622 @Override
2623 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(subId);
2627 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
2630 }
fionaxu43304da2017-11-27 22:51:16 -08002631 }
2632
2633 @Override
2634 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 final Phone phone = getPhone(subId);
2638 return phone == null ? null : phone.getCarrierName();
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
fionaxu43304da2017-11-27 22:51:16 -08002642 }
2643
calvinpanffe225e2018-11-01 19:43:06 +08002644 @Override
chen xu0026ca62019-03-06 15:28:50 -08002645 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 final Phone phone = getPhone(subId);
2649 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002650 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
2654 }
2655
2656 @Override
chen xu0026ca62019-03-06 15:28:50 -08002657 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002661 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
2665 }
2666
chen xu651eec72018-11-11 19:03:44 -08002667 @Override
chen xu864e11c2018-12-06 22:10:03 -08002668 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2669 if (!isSubscriptionMccMnc) {
2670 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2671 }
chen xu651eec72018-11-11 19:03:44 -08002672 final Phone phone = PhoneFactory.getPhone(slotIndex);
2673 if (phone == null) {
2674 return TelephonyManager.UNKNOWN_CARRIER_ID;
2675 }
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
2681 }
2682 }
2683
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 //
2685 // Internal helper methods.
2686 //
2687
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002688 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2690 *
2691 * @throws SecurityException if the caller does not have the required permission
2692 */
2693 private void enforceModifyPermission() {
2694 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2695 }
2696
Shuo Qiancd19c462020-01-16 20:51:11 -08002697 /**
2698 * Make sure the caller is system.
2699 *
2700 * @throws SecurityException if the caller is not system.
2701 */
2702 private void enforceSystemCaller() {
2703 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2704 throw new SecurityException("Caller must be system");
2705 }
2706 }
2707
Shuo Qian3b6ee772019-11-13 17:43:31 -08002708 private void enforceActiveEmergencySessionPermission() {
2709 mApp.enforceCallingOrSelfPermission(
2710 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2711 }
2712
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 /**
2714 * Make sure the caller has the CALL_PHONE permission.
2715 *
2716 * @throws SecurityException if the caller does not have the required permission
2717 */
2718 private void enforceCallPermission() {
2719 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2720 }
2721
paulhu5a773602019-08-23 19:17:33 +08002722 private void enforceSettingsPermission() {
2723 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002724 }
2725
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 private String createTelUrl(String number) {
2727 if (TextUtils.isEmpty(number)) {
2728 return null;
2729 }
2730
Jake Hambye994d462014-02-03 13:10:13 -08002731 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 }
2733
Ihab Awadf9e92732013-12-05 18:02:52 -08002734 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2736 }
2737
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 private static void logv(String msg) {
2739 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2740 }
2741
Ihab Awadf9e92732013-12-05 18:02:52 -08002742 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2744 }
2745
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002746 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002748 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002749 }
2750
Sanket Padawe356d7632015-06-22 14:03:32 -07002751 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002752 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 final Phone phone = PhoneFactory.getPhone(slotIndex);
2756 if (phone == null) {
2757 return PhoneConstants.PHONE_TYPE_NONE;
2758 } else {
2759 return phone.getPhoneType();
2760 }
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
2765
2766 /**
2767 * Returns the CDMA ERI icon index to display
2768 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002769 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2771 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2772 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002776 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2777 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002779 mApp, subId, callingPackage, callingFeatureId,
2780 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002781 return -1;
2782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783
2784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 final Phone phone = getPhone(subId);
2787 if (phone != null) {
2788 return phone.getCdmaEriIconIndex();
2789 } else {
2790 return -1;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
2797 /**
2798 * Returns the CDMA ERI icon mode,
2799 * 0 - ON
2800 * 1 - FLASHING
2801 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2804 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2805 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002806 }
2807
Sanket Padawe356d7632015-06-22 14:03:32 -07002808 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002809 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2810 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002812 mApp, subId, callingPackage, callingFeatureId,
2813 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002814 return -1;
2815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone != null) {
2821 return phone.getCdmaEriIconMode();
2822 } else {
2823 return -1;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 /**
2831 * Returns the CDMA ERI text,
2832 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002833 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2835 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2836 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002840 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2841 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002843 mApp, subId, callingPackage, callingFeatureId,
2844 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002845 return null;
2846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 if (phone != null) {
2852 return phone.getCdmaEriText();
2853 } else {
2854 return null;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
2861 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002862 * Returns the CDMA MDN.
2863 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002865 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2867 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868
2869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 return phone.getLine1Number();
2874 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 return null;
2877 }
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002880 }
2881 }
2882
2883 /**
2884 * Returns the CDMA MIN.
2885 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002887 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2889 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2895 return phone.getCdmaMin();
2896 } else {
2897 return null;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002901 }
2902 }
2903
Hall Liud892bec2018-11-30 14:51:45 -08002904 @Override
2905 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2906 INumberVerificationCallback callback, String callingPackage) {
2907 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2908 != PERMISSION_GRANTED) {
2909 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2910 }
2911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2912
2913 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2914 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2915 throw new SecurityException("Calling package must be configured in the device config");
2916 }
2917
2918 if (range == null) {
2919 throw new NullPointerException("Range must be non-null");
2920 }
2921
2922 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002923 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002924
2925 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2926 }
2927
Junda Liuca05d5d2014-08-14 22:36:34 -07002928 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 * Returns true if CDMA provisioning needs to run.
2930 */
2931 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002934 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 }
2939
2940 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002941 * Sets the voice mail number of a given subId.
2942 */
2943 @Override
2944 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2946 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2951 new Pair<String, String>(alphaTag, number), new Integer(subId));
2952 return success;
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002956 }
2957
Ta-wei Yen87c49842016-05-13 21:19:52 -07002958 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002959 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2960 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002961 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2962 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002963 if (!TextUtils.equals(callingPackage, systemDialer)) {
2964 throw new SecurityException("caller must be system dialer");
2965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2970 if (phoneAccountHandle == null) {
2971 return null;
2972 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 } finally {
2975 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002976 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002977 }
2978
2979 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002980 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2981 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002984 mApp, subId, callingPackage, callingFeatureId,
2985 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002986 return null;
2987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002989 final long identity = Binder.clearCallingIdentity();
2990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002995 }
2996
2997 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002998 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2999 VisualVoicemailSmsFilterSettings settings) {
3000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003005 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003009 }
3010
3011 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003012 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003018 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003022 }
3023
3024 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003025 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3026 String callingPackage, int subId) {
3027 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003032 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003036 }
3037
3038 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003039 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003049 }
3050
3051 @Override
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003052 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3053 String callingAttributionTag, int subId, String number, int port, String text,
3054 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003056 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003057 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003058 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003059 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3060 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003061 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003062
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003063 /**
fionaxu0152e512016-11-14 13:36:14 -08003064 * Sets the voice activation state of a given subId.
3065 */
3066 @Override
3067 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3069 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 final Phone phone = getPhone(subId);
3074 if (phone != null) {
3075 phone.setVoiceActivationState(activationState);
3076 } else {
3077 loge("setVoiceActivationState fails with invalid subId: " + subId);
3078 }
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003081 }
3082 }
3083
3084 /**
3085 * Sets the data activation state of a given subId.
3086 */
3087 @Override
3088 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3090 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 final Phone phone = getPhone(subId);
3095 if (phone != null) {
3096 phone.setDataActivationState(activationState);
3097 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003098 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 }
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003102 }
3103 }
3104
3105 /**
3106 * Returns the voice activation state of a given subId.
3107 */
3108 @Override
3109 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003110 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111
fionaxu0152e512016-11-14 13:36:14 -08003112 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 if (phone != null) {
3116 return phone.getVoiceActivationState();
3117 } else {
3118 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003122 }
3123 }
3124
3125 /**
3126 * Returns the data activation state of a given subId.
3127 */
3128 @Override
3129 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131
fionaxu0152e512016-11-14 13:36:14 -08003132 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 if (phone != null) {
3136 return phone.getDataActivationState();
3137 } else {
3138 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003142 }
3143 }
3144
3145 /**
Wink Saville36469e72014-06-11 15:17:00 -07003146 * Returns the unread count of voicemails for a subId
3147 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003148 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003149 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3150 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003152 mApp, subId, callingPackage, callingFeatureId,
3153 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003154 return 0;
3155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 final Phone phone = getPhone(subId);
3159 if (phone != null) {
3160 return phone.getVoiceMessageCount();
3161 } else {
3162 return 0;
3163 }
3164 } finally {
3165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 }
3168
3169 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003170 * returns true, if the device is in a state where both voice and data
3171 * are supported simultaneously. This can change based on location or network condition.
3172 */
3173 @Override
3174 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 final Phone phone = getPhone(subId);
3178 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
3181 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003182 }
3183
3184 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003185 * Send the dialer code if called from the current default dialer or the caller has
3186 * carrier privilege.
3187 * @param inputCode The dialer code to send
3188 */
3189 @Override
3190 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003192 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003193 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3194 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003195 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003196 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199
3200 final long identity = Binder.clearCallingIdentity();
3201 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003202 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
fionaxu235cc5e2017-03-06 22:25:57 -08003206 }
3207
Pengquan Menga1bb6272018-09-06 09:59:22 -07003208 @Override
3209 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003210 TelephonyPermissions
3211 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3212 mApp, subId, "getNetworkSelectionMode");
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 if (!isActiveSubscription(subId)) {
3216 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3217 }
3218 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003222 }
3223
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003225 public boolean isInEmergencySmsMode() {
3226 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 for (Phone phone : PhoneFactory.getPhones()) {
3230 if (phone.isInEmergencySmsMode()) {
3231 return true;
3232 }
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
3237 return false;
3238 }
3239
shilu366312e2019-12-17 09:28:10 -08003240 /**
3241 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3242 * @param subId The subscription to use to check the configuration.
3243 * @param c The callback that will be used to send the result.
3244 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003245 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003246 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3247 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003248 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3249 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003250
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003251 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3252 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3253 "IMS not available on device.");
3254 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 final long token = Binder.clearCallingIdentity();
3256 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003258 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003260 } catch (ImsException e) {
3261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 } finally {
3263 Binder.restoreCallingIdentity(token);
3264 }
3265 }
3266
shilu366312e2019-12-17 09:28:10 -08003267 /**
3268 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3269 * @param subId The subscription to use to check the configuration.
3270 * @param c The callback that will be used to send the result.
3271 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003273 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003274 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3275 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003276 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3277 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3278 }
Meng Wangafbc5852019-09-19 17:37:13 -07003279 final long token = Binder.clearCallingIdentity();
3280 try {
3281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3282 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3283 .removeRegistrationCallbackForSubscription(c, subId);
3284 } catch (ImsException e) {
3285 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3286 + "is inactive, ignoring unregister.");
3287 // If the subscription is no longer active, just return, since the callback
3288 // will already have been removed internally.
3289 } finally {
3290 Binder.restoreCallingIdentity(token);
3291 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 }
3293
Brad Ebingera34a6c22019-10-22 17:36:18 -07003294 /**
3295 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3296 */
3297 @Override
3298 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3299 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3300 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3301 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3302 "IMS not available on device.");
3303 }
3304 final long token = Binder.clearCallingIdentity();
3305 try {
3306 Phone phone = getPhone(subId);
3307 if (phone == null) {
3308 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3309 + subId + "'");
3310 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3311 }
3312 phone.getImsRegistrationState(regState -> {
3313 try {
3314 consumer.accept((regState == null)
3315 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3316 } catch (RemoteException e) {
3317 // Ignore if the remote process is no longer available to call back.
3318 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3319 }
3320 });
3321 } finally {
3322 Binder.restoreCallingIdentity(token);
3323 }
3324 }
3325
3326 /**
3327 * Get the transport type for the IMS service registration state.
3328 */
3329 @Override
3330 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003331 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3332 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003333 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3335 "IMS not available on device.");
3336 }
3337 final long token = Binder.clearCallingIdentity();
3338 try {
3339 Phone phone = getPhone(subId);
3340 if (phone == null) {
3341 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3342 + subId + "'");
3343 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3344 }
3345 phone.getImsRegistrationTech(regTech -> {
3346 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3347 int regTechConverted = (regTech == null)
3348 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3349 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3350 regTechConverted);
3351 try {
3352 consumer.accept(regTechConverted);
3353 } catch (RemoteException e) {
3354 // Ignore if the remote process is no longer available to call back.
3355 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3356 }
3357 });
3358 } finally {
3359 Binder.restoreCallingIdentity(token);
3360 }
3361 }
3362
shilu366312e2019-12-17 09:28:10 -08003363 /**
3364 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3365 * @param subId The subscription to use to check the configuration.
3366 * @param c The callback that will be used to send the result.
3367 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003369 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3370 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003371 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3372 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003373 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3374 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3375 "IMS not available on device.");
3376 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3378 final long token = Binder.clearCallingIdentity();
3379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
3383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 } finally {
3385 Binder.restoreCallingIdentity(token);
3386 }
3387 }
3388
shilu366312e2019-12-17 09:28:10 -08003389 /**
3390 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3391 * @param subId The subscription to use to check the configuration.
3392 * @param c The callback that will be used to send the result.
3393 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003395 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003396 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3397 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003398 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3399 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3400 }
Meng Wangafbc5852019-09-19 17:37:13 -07003401
3402 final long token = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3405 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003406 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003407 } catch (ImsException e) {
3408 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3409 + "is inactive, ignoring unregister.");
3410 // If the subscription is no longer active, just return, since the callback
3411 // will already have been removed internally.
3412 } finally {
3413 Binder.restoreCallingIdentity(token);
3414 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 }
3416
3417 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003418 public boolean isCapable(int subId, int capability, int regTech) {
3419 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3421 final long token = Binder.clearCallingIdentity();
3422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3427 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003428 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003429 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3430 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 } finally {
3432 Binder.restoreCallingIdentity(token);
3433 }
3434 }
3435
3436 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003437 public boolean isAvailable(int subId, int capability, int regTech) {
3438 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 final long token = Binder.clearCallingIdentity();
3440 try {
3441 Phone phone = getPhone(subId);
3442 if (phone == null) return false;
3443 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003444 } catch (com.android.ims.ImsException e) {
3445 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3446 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 } finally {
3448 Binder.restoreCallingIdentity(token);
3449 }
3450 }
3451
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003452 /**
3453 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3454 * subscription.
3455 * @param subId The subscription to use to check the configuration.
3456 * @param callback The callback that will be used to send the result.
3457 * @param capability The MmTelFeature capability that will be used to send the result.
3458 * @param transportType The transport type of the MmTelFeature capability.
3459 */
3460 @Override
3461 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3462 int transportType) {
3463 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3464 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3465 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3466 "IMS not available on device.");
3467 }
3468 final long token = Binder.clearCallingIdentity();
3469 try {
3470 int slotId = getSlotIndex(subId);
3471 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3472 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3473 + subId + "'");
3474 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3475 }
3476 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3477 transportType, aBoolean -> {
3478 try {
3479 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3480 } catch (RemoteException e) {
3481 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3482 + "running. Ignore");
3483 }
3484 });
3485 } finally {
3486 Binder.restoreCallingIdentity(token);
3487 }
3488 }
3489
shilu366312e2019-12-17 09:28:10 -08003490 /**
3491 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3492 * @param subId The subscription to use to check the configuration.
3493 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 @Override
3495 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003496 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3497 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003498
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3500 final long token = Binder.clearCallingIdentity();
3501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003504 } catch (ImsException e) {
3505 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 } finally {
3507 Binder.restoreCallingIdentity(token);
3508 }
3509 }
3510
3511 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003512 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003514 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (ImsException e) {
3521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
3525 }
3526
shilu366312e2019-12-17 09:28:10 -08003527 /**
3528 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3529 * @param subId The subscription to use to check the configuration.
3530 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003532 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003533 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3534 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003538 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3539 } catch (ImsException e) {
3540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
3544 }
3545
3546 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003547 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003549 "setVtSettingEnabled");
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.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003553 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003554 } catch (ImsException e) {
3555 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
3559 }
3560
shilu366312e2019-12-17 09:28:10 -08003561 /**
3562 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3563 * @param subId The subscription to use to check the configuration.
3564 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 @Override
3566 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003567 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3568 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003574 } catch (ImsException e) {
3575 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
3581 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003582 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003584 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08003596 /**
3597 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3598 * @param subId The subscription to use to check the configuration.
3599 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 @Override
3601 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003602 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3603 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003609 } catch (ImsException e) {
3610 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
3614 }
3615
3616 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003617 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003619 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003625 } catch (ImsException e) {
3626 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631
3632 @Override
3633 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3635 "setVoWiFiNonPersistent");
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003640 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003641 } catch (ImsException e) {
3642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
3646 }
3647
shilu366312e2019-12-17 09:28:10 -08003648 /**
3649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3650 * @param subId The subscription to use to check the configuration.
3651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 @Override
3653 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003654 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3655 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003659 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003661 } catch (ImsException e) {
3662 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
3666 }
3667
3668 @Override
3669 public void setVoWiFiModeSetting(int subId, int mode) {
3670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3671 "setVoWiFiModeSetting");
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003675 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003677 } catch (ImsException e) {
3678 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 }
3683
3684 @Override
3685 public int getVoWiFiRoamingModeSetting(int subId) {
3686 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 getSlotIndexOrException(subId)).getWfcMode(true /*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 void setVoWiFiRoamingModeSetting(int subId, int mode) {
3701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3702 "setVoWiFiRoamingModeSetting");
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3718 "setRttCapabilityEnabled");
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3723 } 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
shilu366312e2019-12-17 09:28:10 -08003730 /**
3731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3732 * @param subId The subscription to use to check the configuration.
3733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 @Override
3735 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003736 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3737 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003743 } catch (ImsException e) {
3744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
3748 }
3749
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003750 @Override
3751 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3752 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003755 if (!isImsAvailableOnDevice()) {
3756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3757 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003758 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003761 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
3763 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
3767 }
3768
3769 @Override
3770 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3771 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3772 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3775 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003778 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003779 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003781 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3782 + "is inactive, ignoring unregister.");
3783 // If the subscription is no longer active, just return, since the callback will already
3784 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
3788 }
3789
allenwtsu99c623b2020-01-03 18:24:23 +08003790
3791 private void checkModifyPhoneStatePermission(int subId, String message) {
3792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3793 message);
3794 }
3795
3796 private boolean isImsProvisioningRequired(int subId, int capability,
3797 boolean isMmtelCapability) {
3798 Phone phone = getPhone(subId);
3799 if (phone == null) {
3800 loge("phone instance null for subid " + subId);
3801 return false;
3802 }
3803 if (isMmtelCapability) {
3804 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3805 return false;
3806 }
3807 } else {
3808 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3809 return false;
3810 }
3811 }
3812 return true;
3813 }
3814
3815 @Override
3816 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3817 boolean isProvisioned) {
3818 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3823 if (!isImsProvisioningRequired(subId, capability, false)) {
3824 return;
3825 }
3826
3827 // this capability requires provisioning, route to the correct API.
3828 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3829 switch (capability) {
3830 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3831 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3832 ims.setEabProvisioned(isProvisioned);
3833 break;
3834 default: {
3835 throw new IllegalArgumentException("Tried to set provisioning for "
3836 + "rcs capability '" + capability + "', which does not require "
3837 + "provisioning.");
3838 }
3839 }
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843
3844 }
3845
3846
3847 @Override
3848 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3849 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3853 if (!isImsProvisioningRequired(subId, capability, false)) {
3854 return true;
3855 }
3856
3857 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3858 switch (capability) {
3859 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3860 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3861 return ims.isEabProvisionedOnDevice();
3862
3863 default: {
3864 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3865 + "capability '" + capability + "', which does not require "
3866 + "provisioning.");
3867 }
3868 }
3869
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
3873 }
3874
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003875 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003876 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3877 boolean isProvisioned) {
3878 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3879 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3880 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3881 }
allenwtsu99c623b2020-01-03 18:24:23 +08003882 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003886 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003887 return;
3888 }
3889
3890 // this capability requires provisioning, route to the correct API.
3891 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3892 switch (capability) {
3893 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3894 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3895 ims.setVolteProvisioned(isProvisioned);
3896 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3897 ims.setWfcProvisioned(isProvisioned);
3898 }
3899 break;
3900 }
3901 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3902 // There is currently no difference in VT provisioning type.
3903 ims.setVtProvisioned(isProvisioned);
3904 break;
3905 }
3906 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3907 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3908 // change the capability of the feature instead if needed.
3909 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3910 == isProvisioned) {
3911 // No change in provisioning.
3912 return;
3913 }
3914 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3915 try {
3916 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003917 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003918 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3919 + ", Exception" + e.getMessage());
3920 }
3921 break;
3922 }
3923 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003924 throw new IllegalArgumentException("Tried to set provisioning for "
3925 + "MmTel capability '" + capability + "', which does not require "
3926 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003927 }
3928 }
3929
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
3933 }
3934
3935 @Override
3936 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3937 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3938 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3939 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3940 }
3941 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003945 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003946 return true;
3947 }
3948
3949 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3950 switch (capability) {
3951 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3952 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3953 return ims.isVolteProvisionedOnDevice();
3954 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3955 return ims.isWfcProvisionedOnDevice();
3956 }
3957 // This should never happen, since we are checking tech above to make sure it
3958 // is either LTE or IWLAN.
3959 throw new IllegalArgumentException("Invalid radio technology for voice "
3960 + "capability.");
3961 }
3962 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3963 // There is currently no difference in VT provisioning type.
3964 return ims.isVtProvisionedOnDevice();
3965 }
3966 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3967 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3968 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3969 }
3970 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003971 throw new IllegalArgumentException(
3972 "Tried to get provisioning for MmTel capability '" + capability
3973 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003974 }
3975 }
3976
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
3980 }
3981
3982 @Override
3983 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3984 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3985 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3986 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3987 }
3988 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3989 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3990 return (provisionedBits & capability) > 0;
3991 }
3992
3993 @Override
3994 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3995 boolean isProvisioned) {
3996 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3997 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3998 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3999 }
4000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4001 "setProvisioningStatusForCapability");
4002 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4003 // If the current provisioning status for capability already matches isProvisioned,
4004 // do nothing.
4005 if (((provisionedBits & capability) > 0) == isProvisioned) {
4006 return;
4007 }
4008 if (isProvisioned) {
4009 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4010 } else {
4011 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4012 }
4013 }
4014
4015 /**
4016 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4017 * technology. The bitfield should mirror the bitfield defined by
4018 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4019 */
4020 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4021 String key = getMmTelProvisioningKey(subId, tech);
4022 // Default is no capabilities are provisioned.
4023 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4024 }
4025
4026 /**
4027 * Sets the MmTel capability provisioning bitfield (defined by
4028 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4029 * technology specified.
4030 *
4031 * Note: This is a synchronous command and should not be called on UI thread.
4032 */
4033 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4034 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4035 String key = getMmTelProvisioningKey(subId, tech);
4036 editor.putInt(key, newField);
4037 editor.commit();
4038 }
4039
4040 private static String getMmTelProvisioningKey(int subId, int tech) {
4041 // resulting key is provision_ims_mmtel_{subId}_{tech}
4042 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4043 }
4044
4045 /**
4046 * Query CarrierConfig to see if the specified capability requires provisioning for the
4047 * carrier associated with the subscription id.
4048 */
4049 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4050 int capability) {
4051 CarrierConfigManager configManager = new CarrierConfigManager(context);
4052 PersistableBundle c = configManager.getConfigForSubId(subId);
4053 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004054 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004055 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4056 false);
4057 boolean requireVoiceVtProvisioning = c.getBoolean(
4058 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4059
4060 // First check to make sure that the capability requires provisioning.
4061 switch (capability) {
4062 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4063 // intentional fallthrough
4064 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4065 if (requireVoiceVtProvisioning) {
4066 // Voice and Video requires provisioning
4067 return true;
4068 }
4069 break;
4070 }
4071 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4072 if (requireUtProvisioning) {
4073 // UT requires provisioning
4074 return true;
4075 }
4076 break;
4077 }
4078 }
4079 return false;
4080 }
4081
allenwtsu99c623b2020-01-03 18:24:23 +08004082 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4083 int capability) {
4084 CarrierConfigManager configManager = new CarrierConfigManager(context);
4085 PersistableBundle c = configManager.getConfigForSubId(subId);
4086
4087 boolean requireRcsProvisioning = c.getBoolean(
4088 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4089
4090 // First check to make sure that the capability requires provisioning.
4091 switch (capability) {
4092 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4093 // intentional fallthrough
4094 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4095 if (requireRcsProvisioning) {
4096 // OPTION or PRESENCE requires provisioning
4097 return true;
4098 }
4099 break;
4100 }
4101 }
4102 return false;
4103 }
4104
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004105 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004106 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4108 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4109 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004110 enforceReadPrivilegedPermission("getImsProvisioningInt");
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004114 int slotId = getSlotIndex(subId);
4115 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4116 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4117 + subId + "' for key:" + key);
4118 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4119 }
4120 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004122 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4123 + subId + "' for key:" + key);
4124 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
4128 }
4129
4130 @Override
4131 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004132 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4133 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4134 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004135 enforceReadPrivilegedPermission("getImsProvisioningString");
4136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 int slotId = getSlotIndex(subId);
4140 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4141 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4142 + subId + "' for key:" + key);
4143 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4144 }
4145 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004146 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4148 + subId + "' for key:" + key);
4149 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154
4155 @Override
4156 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004157 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4158 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4159 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4161 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004165 int slotId = getSlotIndex(subId);
4166 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4167 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4168 + subId + "' for key:" + key);
4169 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4170 }
4171 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004173 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4174 + "' for key:" + key);
4175 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
4179 }
4180
4181 @Override
4182 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4184 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4185 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4187 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004191 int slotId = getSlotIndex(subId);
4192 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4193 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4194 + subId + "' for key:" + key);
4195 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4196 }
4197 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4200 + "' for key:" + key);
4201 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
4205 }
4206
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 int slotId = SubscriptionManager.getSlotIndex(subId);
4209 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4211 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 }
4213 return slotId;
4214 }
4215
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 private int getSlotIndex(int subId) {
4217 int slotId = SubscriptionManager.getSlotIndex(subId);
4218 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4219 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4220 }
4221 return slotId;
4222 }
4223
Wink Saville36469e72014-06-11 15:17:00 -07004224 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004225 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004226 */
4227 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004228 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4229 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004230 final int targetSdk = getTargetSdk(callingPackage);
4231 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004232 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004233 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004234 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004235 mApp, subId, callingPackage, callingFeatureId,
4236 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004237 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4238 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 final Phone phone = getPhone(subId);
4243 if (phone != null) {
4244 return phone.getServiceState().getDataNetworkType();
4245 } else {
4246 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4247 }
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004251 }
4252
4253 /**
4254 * Returns the data network type
4255 */
4256 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004257 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4258 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4259 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004260 }
4261
4262 /**
4263 * Returns the data network type for a subId
4264 */
4265 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004266 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4267 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 mApp, subId, callingPackage, callingFeatureId,
4270 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004271 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4272 }
4273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 final Phone phone = getPhone(subId);
4277 if (phone != null) {
4278 return phone.getServiceState().getDataNetworkType();
4279 } else {
4280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4281 }
4282 } finally {
4283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004285 }
4286
4287 /**
Wink Saville36469e72014-06-11 15:17:00 -07004288 * Returns the Voice network type for a subId
4289 */
4290 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004291 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4292 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004294 mApp, subId, callingPackage, callingFeatureId,
4295 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004296 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4297 }
4298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 final Phone phone = getPhone(subId);
4302 if (phone != null) {
4303 return phone.getServiceState().getVoiceNetworkType();
4304 } else {
4305 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4306 }
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004310 }
4311
4312 /**
4313 * @return true if a ICC card is present
4314 */
4315 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004316 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004317 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4318 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004319 }
4320
4321 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004322 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004323 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004324 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004325 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 final Phone phone = PhoneFactory.getPhone(slotIndex);
4329 if (phone != null) {
4330 return phone.getIccCard().hasIccCard();
4331 } else {
4332 return false;
4333 }
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004337 }
4338
4339 /**
4340 * Return if the current radio is LTE on CDMA. This
4341 * is a tri-state return value as for a period of time
4342 * the mode may be unknown.
4343 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004344 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004345 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004346 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004347 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004348 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004349 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4350 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4351 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004352 }
4353
Sanket Padawe356d7632015-06-22 14:03:32 -07004354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004355 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4356 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004357 try {
4358 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4359 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004360 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4361 }
4362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 final Phone phone = getPhone(subId);
4366 if (phone == null) {
4367 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4368 } else {
4369 return phone.getLteOnCdmaMode();
4370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004373 }
Wink Saville36469e72014-06-11 15:17:00 -07004374 }
4375
Wink Saville36469e72014-06-11 15:17:00 -07004376 /**
4377 * {@hide}
4378 * Returns Default subId, 0 in the case of single standby.
4379 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004380 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004381 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004382 }
4383
Shishir Agrawala9f32182016-04-12 12:00:16 -07004384 private int getSlotForDefaultSubscription() {
4385 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4386 }
4387
Wink Savilleb564aae2014-10-23 10:18:09 -07004388 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004389 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004390 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004391
Pengquan Menge92a50d2018-09-21 15:54:48 -07004392 private boolean isActiveSubscription(int subId) {
4393 return mSubscriptionController.isActiveSubId(subId);
4394 }
4395
Ihab Awadf2177b72013-11-25 13:33:23 -08004396 /**
4397 * @see android.telephony.TelephonyManager.WifiCallingChoices
4398 */
4399 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 final long identity = Binder.clearCallingIdentity();
4401 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004402 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4404 getWhenToMakeWifiCallsDefaultPreference());
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004408 }
4409
4410 /**
4411 * @see android.telephony.TelephonyManager.WifiCallingChoices
4412 */
4413 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004417 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004422 }
4423
Sailesh Nepald1e68152013-12-12 19:08:02 -08004424 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004425 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004426 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004427 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004428
Jordan Liu4c733742019-02-28 12:03:40 -08004429 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4430 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4431 if (phoneId == -1) {
4432 throw new IllegalArgumentException("Given slot index: " + slotIndex
4433 + " does not correspond to an active phone");
4434 }
4435 return PhoneFactory.getPhone(phoneId);
4436 }
4437
Shishir Agrawal566b7612013-10-28 14:41:00 -07004438 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004439 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4440 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4442 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004444 if (DBG) {
4445 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4446 }
4447 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4448 p2);
4449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004450
Jordan Liu4c733742019-02-28 12:03:40 -08004451
4452 @Override
4453 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4454 int slotIndex, String callingPackage, String aid, int p2) {
4455 enforceModifyPermission();
4456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4457 if (DBG) {
4458 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4459 }
4460 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4461 callingPackage, aid, p2);
4462 }
4463
4464 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4465 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 if (TextUtils.equals(ISDR_AID, aid)) {
4469 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004470 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4471 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 if (bestComponent == null
4473 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4474 loge("The calling package is not allowed to access ISD-R.");
4475 throw new SecurityException(
4476 "The calling package is not allowed to access ISD-R.");
4477 }
Derek Tan740e1672017-06-27 14:56:27 -07004478 }
Derek Tan740e1672017-06-27 14:56:27 -07004479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004481 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4482 null /* workSource */);
4483 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 return response;
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004488 }
4489
4490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004491 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004494 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4495 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004497
Jordan Liu4c733742019-02-28 12:03:40 -08004498 @Override
4499 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4500 enforceModifyPermission();
4501 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4502 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4503 channel);
4504 }
4505
4506 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509 if (channel < 0) {
4510 return false;
4511 }
Jordan Liu4c733742019-02-28 12:03:40 -08004512 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4513 null /* workSource */);
4514 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 return success;
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004518 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004519 }
4520
4521 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004522 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004523 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004526 if (DBG) {
4527 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4528 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4529 + p3 + " data=" + data);
4530 }
4531 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4532 command, p1, p2, p3, data);
4533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534
Jordan Liu4c733742019-02-28 12:03:40 -08004535 @Override
4536 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4537 int command, int p1, int p2, int p3, String data) {
4538 enforceModifyPermission();
4539 if (DBG) {
4540 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4541 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4542 + p3 + " data=" + data);
4543 }
4544 return iccTransmitApduLogicalChannelWithPermission(
4545 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4546 data);
4547 }
4548
4549 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4550 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 final long identity = Binder.clearCallingIdentity();
4552 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004553 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 return "";
4555 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004558 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4559 null /* workSource */);
4560 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 // Append the returned status code to the end of the response payload.
4563 String s = Integer.toHexString(
4564 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4565 if (response.payload != null) {
4566 s = IccUtils.bytesToHexString(response.payload) + s;
4567 }
4568 return s;
4569 } finally {
4570 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004572 }
Jake Hambye994d462014-02-03 13:10:13 -08004573
Evan Charltonc66da362014-05-16 14:06:40 -07004574 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004575 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4576 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4578 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004580 if (DBG) {
4581 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4582 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4583 }
4584 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4585 cla, command, p1, p2, p3, data);
4586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004587
Jordan Liu4c733742019-02-28 12:03:40 -08004588 @Override
4589 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4590 int command, int p1, int p2, int p3, String data) {
4591 enforceModifyPermission();
4592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4593 if (DBG) {
4594 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4595 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4596 + " data=" + data);
4597 }
4598
4599 return iccTransmitApduBasicChannelWithPermission(
4600 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4601 p2, p3, data);
4602 }
4603
4604 // open APDU basic channel assuming the caller has sufficient permissions
4605 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4606 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4610 && TextUtils.equals(ISDR_AID, data)) {
4611 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004612 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4613 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 if (bestComponent == null
4615 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4616 loge("The calling package is not allowed to select ISD-R.");
4617 throw new SecurityException(
4618 "The calling package is not allowed to select ISD-R.");
4619 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004620 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004623 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4624 null /* workSource */);
4625 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 // Append the returned status code to the end of the response payload.
4628 String s = Integer.toHexString(
4629 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4630 if (response.payload != null) {
4631 s = IccUtils.bytesToHexString(response.payload) + s;
4632 }
4633 return s;
4634 } finally {
4635 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004636 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004637 }
4638
4639 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004640 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004641 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 if (DBG) {
4648 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4649 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4650 }
4651
4652 IccIoResult response =
4653 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4654 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4655 subId);
4656
4657 if (DBG) {
4658 log("Exchange SIM_IO [R]" + response);
4659 }
4660
4661 byte[] result = null;
4662 int length = 2;
4663 if (response.payload != null) {
4664 length = 2 + response.payload.length;
4665 result = new byte[length];
4666 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4667 } else {
4668 result = new byte[length];
4669 }
4670
4671 result[length - 1] = (byte) response.sw2;
4672 result[length - 2] = (byte) response.sw1;
4673 return result;
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004676 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004677 }
4678
Nathan Haroldb3014052017-01-25 15:57:32 -08004679 /**
4680 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4681 * on a particular subscription
4682 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004683 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4684 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004686 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004687 return null;
4688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 if (appType != TelephonyManager.APPTYPE_USIM
4693 && appType != TelephonyManager.APPTYPE_SIM) {
4694 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4695 return null;
4696 }
4697 Object response = sendRequest(
4698 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4699 if (response instanceof String[]) {
4700 return (String[]) response;
4701 }
yincheng zhao2737e882019-09-06 17:06:54 -07004702 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004704 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004707 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004708 }
4709
yincheng zhao2737e882019-09-06 17:06:54 -07004710 /**
4711 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4712 * subscription.
4713 *
4714 * @param subId the id of the subscription.
4715 * @param appType the uicc app type, must be USIM or SIM.
4716 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4717 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004718 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004719 * @return number of fplmns that is successfully written to the SIM.
4720 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004721 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4722 String callingFeatureId) {
4723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4724 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004725 if (DBG) logv("no permissions for setForbiddenplmns");
4726 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4727 }
4728 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4729 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4730 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4731 }
4732 if (fplmns == null) {
4733 throw new IllegalArgumentException("Fplmn List provided is null");
4734 }
4735 for (String fplmn : fplmns) {
4736 if (!CellIdentity.isValidPlmn(fplmn)) {
4737 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4738 }
4739 }
4740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 Object response = sendRequest(
4743 CMD_SET_FORBIDDEN_PLMNS,
4744 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4745 subId);
4746 return (int) response;
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
4750 }
4751
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004753 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4755 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4760 if (response.payload == null) {
4761 return "";
4762 }
Evan Charltonc66da362014-05-16 14:06:40 -07004763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 // Append the returned status code to the end of the response payload.
4765 String s = Integer.toHexString(
4766 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4767 s = IccUtils.bytesToHexString(response.payload) + s;
4768 return s;
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
Evan Charltonc66da362014-05-16 14:06:40 -07004772 }
4773
Jake Hambye994d462014-02-03 13:10:13 -08004774 /**
4775 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4776 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4777 *
4778 * @param itemID the ID of the item to read
4779 * @return the NV item as a String, or null on error.
4780 */
4781 @Override
4782 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004783 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4785 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786
4787 final long identity = Binder.clearCallingIdentity();
4788 try {
4789 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004790 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4792 return value;
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
4795 }
Jake Hambye994d462014-02-03 13:10:13 -08004796 }
4797
4798 /**
4799 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4800 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4801 *
4802 * @param itemID the ID of the item to read
4803 * @param itemValue the value to write, as a String
4804 * @return true on success; false on any failure
4805 */
4806 @Override
4807 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004808 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4810 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811
4812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4815 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004816 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4818 return success;
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
Jake Hambye994d462014-02-03 13:10:13 -08004822 }
4823
4824 /**
4825 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4826 * Used for device configuration by some CDMA operators.
4827 *
4828 * @param preferredRoamingList byte array containing the new PRL
4829 * @return true on success; false on any failure
4830 */
4831 @Override
4832 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4834 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835
4836 final long identity = Binder.clearCallingIdentity();
4837 try {
4838 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4839 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4840 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4841 return success;
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Jake Hambye994d462014-02-03 13:10:13 -08004845 }
4846
4847 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004848 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004849 * Used for device configuration by some CDMA operators.
4850 *
chen xu6dac5ab2018-10-26 17:39:23 -07004851 * @param slotIndex - device slot.
4852 *
Jake Hambye994d462014-02-03 13:10:13 -08004853 * @return true on success; false on any failure
4854 */
4855 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004856 public boolean resetModemConfig(int slotIndex) {
4857 Phone phone = PhoneFactory.getPhone(slotIndex);
4858 if (phone != null) {
4859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4860 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861
chen xu6dac5ab2018-10-26 17:39:23 -07004862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4865 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4866 return success;
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 }
chen xu6dac5ab2018-10-26 17:39:23 -07004871 return false;
4872 }
4873
4874 /**
4875 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4876 *
4877 * @param slotIndex - device slot.
4878 *
4879 * @return true on success; false on any failure
4880 */
4881 @Override
4882 public boolean rebootModem(int slotIndex) {
4883 Phone phone = PhoneFactory.getPhone(slotIndex);
4884 if (phone != null) {
4885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4886 mApp, phone.getSubId(), "rebootModem");
4887
4888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4891 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4892 return success;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004898 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004899
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004900 public String[] getPcscfAddress(String apnType, String callingPackage,
4901 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004902 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4904 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004905 return new String[0];
4906 }
4907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 final long identity = Binder.clearCallingIdentity();
4909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004910 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
Wink Saville36469e72014-06-11 15:17:00 -07004914 }
4915
Brad Ebinger51f743a2017-01-23 13:50:20 -08004916 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004917 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4918 * {@link #disableIms(int)}.
4919 * @param slotIndex device slot.
4920 */
4921 public void resetIms(int slotIndex) {
4922 enforceModifyPermission();
4923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 if (mImsResolver == null) {
4927 // may happen if the does not support IMS.
4928 return;
4929 }
4930 mImsResolver.disableIms(slotIndex);
4931 mImsResolver.enableIms(slotIndex);
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004938 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4939 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004940 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004941 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004946 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004947 // may happen if the device does not support IMS.
4948 return;
4949 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004950 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004954 }
4955
4956 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004957 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4958 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004959 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 public void disableIms(int slotId) {
4961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004965 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004966 // may happen if the device does not support IMS.
4967 return;
4968 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004969 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004973 }
4974
4975 /**
4976 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4977 * feature or {@link null} if the service is not available. If the feature is available, the
4978 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4979 */
4980 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004981 IImsServiceFeatureCallback callback) {
4982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983
4984 final long identity = Binder.clearCallingIdentity();
4985 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004986 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004987 // may happen if the device does not support IMS.
4988 return null;
4989 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004990 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004994 }
4995
4996 /**
4997 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4998 * feature during emergency calling or {@link null} if the service is not available. If the
4999 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5000 * listener for feature updates.
5001 */
5002 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005007 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005008 // may happen if the device does not support IMS.
5009 return null;
5010 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005011 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005015 }
5016
Brad Ebinger5f64b052017-12-14 14:26:15 -08005017 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005018 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5019 */
5020 public void unregisterImsFeatureCallback(int slotId, int featureType,
5021 IImsServiceFeatureCallback callback) {
5022 enforceModifyPermission();
5023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 if (mImsResolver == null) return;
5027 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
5031 }
5032
5033 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005034 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005035 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005036 */
5037 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039
5040 final long identity = Binder.clearCallingIdentity();
5041 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005042 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005043 // may happen if the device does not support IMS.
5044 return null;
5045 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005046 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005050 }
5051
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005052 /**
5053 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005054 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005055 */
5056 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5057 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005062 // may happen if the device does not support IMS.
5063 return null;
5064 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005065 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005069 }
5070
Brad Ebinger884c07b2018-02-15 16:17:40 -08005071 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005072 * Sets the ImsService Package Name that Telephony will bind to.
5073 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005074 * @param slotIndex the slot ID that the ImsService should bind for.
5075 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005077 * @param featureTypes An integer array of feature types associated with a packageName.
5078 * @param packageName The name of the package that the current configuration will be replaced
5079 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005081 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005082 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5083 int[] featureTypes, String packageName) {
5084 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5087 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005088 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005092 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005093 // may happen if the device does not support IMS.
5094 return false;
5095 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005096 Map<Integer, String> featureConfig = new HashMap<>();
5097 for (int featureType : featureTypes) {
5098 featureConfig.put(featureType, packageName);
5099 }
5100 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5101 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005105 }
5106
5107 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005108 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005109 *
5110 * @param slotId The slot that the ImsService is associated with.
5111 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5112 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005113 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005114 * @return the package name of the ImsService configuration.
5115 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005116 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5117 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005118 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005119 TelephonyPermissions
5120 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5121 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5122 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 final long identity = Binder.clearCallingIdentity();
5125 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005126 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005127 // may happen if the device does not support IMS.
5128 return "";
5129 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005130 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005131 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5132 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005136 }
5137
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005138 /**
5139 * Get the MmTelFeature state associated with the requested subscription id.
5140 * @param subId The subscription that the MmTelFeature is associated with.
5141 * @param callback A callback with an integer containing the
5142 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5143 */
5144 @Override
5145 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5146 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5147 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5148 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5149 "IMS not available on device.");
5150 }
5151 final long token = Binder.clearCallingIdentity();
5152 try {
5153 int slotId = getSlotIndex(subId);
5154 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5155 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5156 + subId + "'");
5157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5158 }
5159 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5160 try {
5161 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5162 } catch (RemoteException e) {
5163 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5164 + "Ignore");
5165 }
5166 });
5167 } finally {
5168 Binder.restoreCallingIdentity(token);
5169 }
5170 }
5171
Wink Saville36469e72014-06-11 15:17:00 -07005172 public void setImsRegistrationState(boolean registered) {
5173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174
5175 final long identity = Binder.clearCallingIdentity();
5176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005177 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
Wink Saville36469e72014-06-11 15:17:00 -07005181 }
5182
5183 /**
Stuart Scott54788802015-03-30 13:18:01 -07005184 * Set the network selection mode to automatic.
5185 *
5186 */
5187 @Override
5188 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
shilufc958392020-01-20 11:36:01 -08005194 if (!isActiveSubscription(subId)) {
5195 return;
5196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5198 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Stuart Scott54788802015-03-30 13:18:01 -07005202 }
5203
Pengquan Mengea84e042018-09-20 14:57:26 -07005204 /**
5205 * Ask the radio to connect to the input network and change selection mode to manual.
5206 *
5207 * @param subId the id of the subscription.
5208 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5209 * the operator to attach to.
5210 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5211 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5212 * normal network selection next time.
5213 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005214 */
5215 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005216 public boolean setNetworkSelectionModeManual(
5217 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005220
5221 if (!isActiveSubscription(subId)) {
5222 return false;
5223 }
5224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005227 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005229 if (DBG) {
5230 log("setNetworkSelectionModeManual: subId: " + subId
5231 + " operator: " + operatorInfo);
5232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005237 }
shilu84f6e8b2019-12-19 13:58:01 -08005238 /**
5239 * Get the manual network selection
5240 *
5241 * @param subId the id of the subscription.
5242 *
5243 * @return the previously saved user selected PLMN
5244 */
5245 @Override
5246 public String getManualNetworkSelectionPlmn(int subId) {
5247 TelephonyPermissions
5248 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5249 mApp, subId, "getManualNetworkSelectionPlmn");
5250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 if (!isActiveSubscription(subId)) {
5254 return "";
5255 }
5256
5257 final Phone phone = getPhone(subId);
5258 if (phone == null) {
5259 return "";
5260 }
5261 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5262 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5263 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
5267 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005268
5269 /**
5270 * Scans for available networks.
5271 */
5272 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005273 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005277 LocationAccessPolicy.LocationPermissionResult locationResult =
5278 LocationAccessPolicy.checkLocationPermission(mApp,
5279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5280 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005281 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005282 .setCallingPid(Binder.getCallingPid())
5283 .setCallingUid(Binder.getCallingUid())
5284 .setMethod("getCellNetworkScanResults")
5285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5286 .build());
5287 switch (locationResult) {
5288 case DENIED_HARD:
5289 throw new SecurityException("Not allowed to access scan results -- location");
5290 case DENIED_SOFT:
5291 return null;
5292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293
Pengquan Menga1bb6272018-09-06 09:59:22 -07005294 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 try {
5296 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005297 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005302 }
5303
5304 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005305 * Get the call forwarding info, given the call forwarding reason.
5306 */
5307 @Override
5308 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5309 enforceReadPrivilegedPermission("getCallForwarding");
5310 long identity = Binder.clearCallingIdentity();
5311 try {
5312 if (DBG) {
5313 log("getCallForwarding: subId " + subId
5314 + " callForwardingReason" + callForwardingReason);
5315 }
5316 return (CallForwardingInfo) sendRequest(
5317 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
5321 }
5322
5323 /**
5324 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5325 * reason, the number to forward, and the timeout before the forwarding is attempted.
5326 */
5327 @Override
5328 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5329 enforceModifyPermission();
5330 long identity = Binder.clearCallingIdentity();
5331 try {
5332 if (DBG) {
5333 log("setCallForwarding: subId " + subId
5334 + " callForwardingInfo" + callForwardingInfo);
5335 }
5336 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
5340 }
5341
5342 /**
5343 * Get the call forwarding info, given the call forwarding reason.
5344 */
5345 @Override
5346 public int getCallWaitingStatus(int subId) {
5347 enforceReadPrivilegedPermission("getCallForwarding");
5348 long identity = Binder.clearCallingIdentity();
5349 try {
5350 if (DBG) log("getCallWaitingStatus: subId " + subId);
5351 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356
5357 /**
5358 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5359 * reason, the number to forward, and the timeout before the forwarding is attempted.
5360 */
5361 @Override
5362 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5363 enforceModifyPermission();
5364 long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5367 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
5371 }
5372
5373 /**
yinxub1bed742017-04-17 11:45:04 -07005374 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005375 *
yinxub1bed742017-04-17 11:45:04 -07005376 * @param subId id of the subscription
5377 * @param request contains the radio access networks with bands/channels to scan
5378 * @param messenger callback messenger for scan results or errors
5379 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005380 * @return the id of the requested scan which can be used to stop the scan.
5381 */
5382 @Override
5383 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005384 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5386 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005387 LocationAccessPolicy.LocationPermissionResult locationResult =
5388 LocationAccessPolicy.checkLocationPermission(mApp,
5389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5390 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005392 .setCallingPid(Binder.getCallingPid())
5393 .setCallingUid(Binder.getCallingUid())
5394 .setMethod("requestNetworkScan")
5395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5396 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005397 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005398 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005399 if (e != null) {
5400 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5401 throw e;
5402 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005403 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005404 return TelephonyScanManager.INVALID_SCAN_ID;
5405 }
5406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 }
Hall Liu912dfd32019-04-25 14:02:26 -07005408 int callingUid = Binder.getCallingUid();
5409 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 return mNetworkScanRequestTracker.startNetworkScan(
5413 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005414 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
yinxu504e1392017-04-12 16:03:22 -07005418 }
5419
Hall Liub2ac8ef2019-02-28 15:56:23 -08005420 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005421 NetworkScanRequest request, int subId) {
5422 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5423 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5424 boolean hasNetworkScanPermission =
5425 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5426 == PERMISSION_GRANTED;
5427
5428 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5429 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5430 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005431 }
5432
5433 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5434 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005435 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5436 return new SecurityException("Specific channels must not be"
5437 + " scanned without location access.");
5438 }
5439 }
5440 }
5441
Hall Liub2ac8ef2019-02-28 15:56:23 -08005442 return null;
5443 }
5444
yinxu504e1392017-04-12 16:03:22 -07005445 /**
5446 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005447 *
5448 * @param subId id of the subscription
5449 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005450 */
5451 @Override
5452 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
Hall Liu912dfd32019-04-25 14:02:26 -07005456 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005459 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
yinxu504e1392017-04-12 16:03:22 -07005463 }
5464
5465 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005466 * Get the calculated preferred network type.
5467 * Used for debugging incorrect network type.
5468 *
5469 * @return the preferred network type, defined in RILConstants.java.
5470 */
5471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005472 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005473 final Phone defaultPhone = getDefaultPhone();
5474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005475 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005476 return RILConstants.PREFERRED_NETWORK_MODE;
5477 }
5478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005482 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Junda Liu84d15a22014-07-02 11:21:04 -07005486 }
5487
5488 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005489 * Get the preferred network type.
5490 * Used for device configuration by some CDMA operators.
5491 *
5492 * @return the preferred network type, defined in RILConstants.java.
5493 */
5494 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005495 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005496 TelephonyPermissions
5497 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5498 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 if (DBG) log("getPreferredNetworkType");
5503 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5504 int networkType = (result != null ? result[0] : -1);
5505 if (DBG) log("getPreferredNetworkType: " + networkType);
5506 return networkType;
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005510 }
5511
5512 /**
5513 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005514 *
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);
calvinpan8ed33732020-03-12 14:17:55 +08005527
5528 Boolean success = (Boolean) sendRequest(
5529 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5530 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5531 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005534 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005535 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005536
5537 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005538 * Get the allowed network types that store in the telephony provider.
5539 *
5540 * @param subId the id of the subscription.
5541 * @return allowedNetworkTypes the allowed network types.
5542 */
5543 @Override
5544 public long getAllowedNetworkTypes(int subId) {
5545 TelephonyPermissions
5546 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5547 mApp, subId, "getAllowedNetworkTypes");
5548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 return SubscriptionManager.getLongSubscriptionProperty(
5552 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
5556 }
5557
5558 /**
5559 * Set the allowed network types.
5560 *
5561 * @param subId the id of the subscription.
5562 * @param allowedNetworkTypes the allowed network types.
5563 * @return true on success; false on any failure.
5564 */
5565 @Override
5566 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5568 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005569
calvinpan8ed33732020-03-12 14:17:55 +08005570 SubscriptionManager.setSubscriptionProperty(subId,
5571 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5572 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005573
calvinpan8ed33732020-03-12 14:17:55 +08005574 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5575 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5576 RILConstants.PREFERRED_NETWORK_MODE);
5577 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005578 }
5579
5580 /**
Miaoa84611c2019-03-15 09:21:10 +08005581 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005582 *
Miaoa84611c2019-03-15 09:21:10 +08005583 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005584 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005585 * @hide
5586 */
5587 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005588 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 try {
Miaoa84611c2019-03-15 09:21:10 +08005593 if (phone != null) {
5594 return phone.hasMatchedTetherApnSetting();
5595 } else {
5596 return false;
5597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005600 }
Junda Liu475951f2014-11-07 16:45:03 -08005601 }
5602
5603 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005604 * Set mobile data enabled
5605 * Used by the user through settings etc to turn on/off mobile data
5606 *
5607 * @param enable {@code true} turn turn data on, else {@code false}
5608 */
5609 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005610 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5612 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613
5614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 int phoneId = mSubscriptionController.getPhoneId(subId);
5617 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5618 Phone phone = PhoneFactory.getPhone(phoneId);
5619 if (phone != null) {
5620 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005621 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005623 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 }
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005627 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005628 }
5629
5630 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005631 * Enable or disable always reporting signal strength changes from radio.
5632 *
5633 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5634 */
5635 @Override
5636 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5637 enforceModifyPermission();
5638 enforceSystemCaller();
5639
5640 final long identity = Binder.clearCallingIdentity();
5641 final Phone phone = getPhone(subId);
5642 try {
5643 if (phone != null) {
5644 if (DBG) {
5645 log("setAlwaysReportSignalStrength: subId=" + subId
5646 + " isEnable=" + isEnable);
5647 }
5648 phone.setAlwaysReportSignalStrength(isEnable);
5649 } else {
5650 loge("setAlwaysReportSignalStrength: no phone found for subId="
5651 + subId);
5652 }
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
5656 }
5657
5658 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005659 * Get the user enabled state of Mobile Data.
5660 *
5661 * TODO: remove and use isUserDataEnabled.
5662 * This can't be removed now because some vendor codes
5663 * calls through ITelephony directly while they should
5664 * use TelephonyManager.
5665 *
5666 * @return true on enabled
5667 */
5668 @Override
5669 public boolean getDataEnabled(int subId) {
5670 return isUserDataEnabled(subId);
5671 }
5672
5673 /**
5674 * Get whether mobile data is enabled per user setting.
5675 *
5676 * There are other factors deciding whether mobile data is actually enabled, but they are
5677 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005678 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005679 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005680 *
5681 * @return {@code true} if data is enabled else {@code false}
5682 */
5683 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005684 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005685 try {
5686 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5687 null);
5688 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5690 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 int phoneId = mSubscriptionController.getPhoneId(subId);
5696 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5697 Phone phone = PhoneFactory.getPhone(phoneId);
5698 if (phone != null) {
5699 boolean retVal = phone.isUserDataEnabled();
5700 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5701 return retVal;
5702 } else {
5703 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5704 return false;
5705 }
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005708 }
5709 }
5710
5711 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005712 * Checks if the device is capable of mobile data by considering whether whether the
5713 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5714 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005715 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005716 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005717 */
5718 @Override
5719 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005720 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 int phoneId = mSubscriptionController.getPhoneId(subId);
5725 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5726 Phone phone = PhoneFactory.getPhone(phoneId);
5727 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005728 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5730 return retVal;
5731 } else {
5732 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5733 return false;
5734 }
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005737 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005738 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005739
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005740 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005741 Phone phone) {
5742 //load access rules from carrier configs, and check those as well: b/139133814
5743 SubscriptionController subController = SubscriptionController.getInstance();
5744 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5745 || subController == null) return privilegeFromSim;
5746
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005747 PackageManager pkgMgr = phone.getContext().getPackageManager();
5748 String[] packages = pkgMgr.getPackagesForUid(uid);
5749
5750 final long identity = Binder.clearCallingIdentity();
5751 try {
5752 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5753 SubscriptionManager subManager = (SubscriptionManager)
5754 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5755 for (String pkg : packages) {
5756 if (subManager.canManageSubscription(subInfo, pkg)) {
5757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5758 }
5759 }
5760 return privilegeFromSim;
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
5764 }
5765
5766 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5767 String pkgName) {
5768 //load access rules from carrier configs, and check those as well: b/139133814
5769 SubscriptionController subController = SubscriptionController.getInstance();
5770 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5771 || subController == null) return privilegeFromSim;
5772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5776 SubscriptionManager subManager = (SubscriptionManager)
5777 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5778 return subManager.canManageSubscription(subInfo, pkgName)
5779 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
5783 }
5784
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005785 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005786 public int getCarrierPrivilegeStatus(int subId) {
5787 final Phone phone = getPhone(subId);
5788 if (phone == null) {
5789 loge("getCarrierPrivilegeStatus: Invalid subId");
5790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5791 }
5792 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005793 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005794 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005795 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5796 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005797
5798 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5799 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005800 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005801 }
Junda Liu29340342014-07-10 15:23:27 -07005802
5803 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005804 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005805 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005806 final Phone phone = getPhone(subId);
5807 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005808 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005809 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5810 }
5811 UiccProfile profile =
5812 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5813 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005814 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5816 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005817 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005818 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005819 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005820 }
5821
5822 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005823 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5824 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005826 }
5827
5828 int phoneId = SubscriptionManager.getPhoneId(subId);
5829 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005830 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005831 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005832 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5833 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005834 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5835 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5836 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005837 }
5838
5839 @Override
5840 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005841 if (TextUtils.isEmpty(pkgName))
5842 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005843 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5844 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5845 UiccCard card = UiccController.getInstance().getUiccCard(i);
5846 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005847 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005848 continue;
5849 }
5850
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005851 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5852 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5853 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005854 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5855 break;
5856 }
5857 }
5858
5859 return result;
Junda Liu29340342014-07-10 15:23:27 -07005860 }
Derek Tan89e89d42014-07-08 17:00:10 -07005861
5862 @Override
Junda Liue64de782015-04-16 17:19:16 -07005863 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5864 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5865 loge("phoneId " + phoneId + " is not valid.");
5866 return null;
5867 }
5868 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005869 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005870 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005871 return null ;
5872 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005873 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005874 }
5875
Amith Yamasani6e118872016-02-19 12:53:51 -08005876 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005877 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005878 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005879 List<String> privilegedPackages = new ArrayList<>();
5880 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005881 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5882 // has UICC in that slot.
5883 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005884 if (card.hasCarrierPrivilegeRules()) {
5885 if (packages == null) {
5886 // Only check packages in user 0 for now
5887 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005888 PackageManager.MATCH_DISABLED_COMPONENTS
5889 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005890 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005891 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005892 }
5893 for (int p = packages.size() - 1; p >= 0; p--) {
5894 PackageInfo pkgInfo = packages.get(p);
5895 if (pkgInfo != null && pkgInfo.packageName != null
5896 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005897 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005898 privilegedPackages.add(pkgInfo.packageName);
5899 }
5900 }
5901 }
5902 }
5903 return privilegedPackages;
5904 }
5905
chen xuf7e9fe82019-05-09 19:31:02 -07005906 @Override
5907 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005908 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5909
5910 final long identity = Binder.clearCallingIdentity();
5911
chen xuf7e9fe82019-05-09 19:31:02 -07005912 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005913 try {
5914 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5915 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5916 }
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005919 }
5920 return privilegedPackages;
5921 }
5922
Wink Savilleb564aae2014-10-23 10:18:09 -07005923 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005924 final Phone phone = getPhone(subId);
5925 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005926 if (card == null) {
5927 loge("getIccId: No UICC");
5928 return null;
5929 }
5930 String iccId = card.getIccId();
5931 if (TextUtils.isEmpty(iccId)) {
5932 loge("getIccId: ICC ID is null or empty.");
5933 return null;
5934 }
5935 return iccId;
5936 }
5937
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005938 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005939 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5940 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 final String iccId = getIccId(subId);
5947 final Phone phone = getPhone(subId);
5948 if (phone == null) {
5949 return false;
5950 }
5951 final String subscriberId = phone.getSubscriberId();
5952
5953 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005954 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 + subscriberId + " to " + number);
5956 }
5957
5958 if (TextUtils.isEmpty(iccId)) {
5959 return false;
5960 }
5961
5962 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5963
5964 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5965 if (alphaTag == null) {
5966 editor.remove(alphaTagPrefKey);
5967 } else {
5968 editor.putString(alphaTagPrefKey, alphaTag);
5969 }
5970
5971 // Record both the line number and IMSI for this ICCID, since we need to
5972 // track all merged IMSIs based on line number
5973 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5974 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5975 if (number == null) {
5976 editor.remove(numberPrefKey);
5977 editor.remove(subscriberPrefKey);
5978 } else {
5979 editor.putString(numberPrefKey, number);
5980 editor.putString(subscriberPrefKey, subscriberId);
5981 }
5982
5983 editor.commit();
5984 return true;
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005987 }
Derek Tan7226c842014-07-02 17:42:23 -07005988 }
5989
5990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005991 public String getLine1NumberForDisplay(int subId, String callingPackage,
5992 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005993 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005995 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005996 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005997 return null;
5998 }
Derek Tan97ebb422014-09-05 16:55:38 -07005999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 String iccId = getIccId(subId);
6003 if (iccId != null) {
6004 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6005 if (DBG_MERGE) {
6006 log("getLine1NumberForDisplay returning "
6007 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6008 }
6009 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6012 return null;
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006015 }
Derek Tan7226c842014-07-02 17:42:23 -07006016 }
6017
6018 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006019 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6020 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006022 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006023 return null;
6024 }
Derek Tan97ebb422014-09-05 16:55:38 -07006025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026 final long identity = Binder.clearCallingIdentity();
6027 try {
6028 String iccId = getIccId(subId);
6029 if (iccId != null) {
6030 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6031 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6032 }
6033 return null;
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006036 }
Derek Tan7226c842014-07-02 17:42:23 -07006037 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006038
6039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006040 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6041 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006042 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6043 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006045 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006046 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006047 return null;
6048 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006049
Jordan Liub49b04b2019-05-06 14:45:15 -07006050 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6051 // the process, where TelephonyManager was instantiated.
6052 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006053 final long identity = Binder.clearCallingIdentity();
6054 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006055 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 final TelephonyManager tele = TelephonyManager.from(context);
6057 final SubscriptionManager sub = SubscriptionManager.from(context);
6058
6059 // Figure out what subscribers are currently active
6060 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061
Jordan Liub49b04b2019-05-06 14:45:15 -07006062 // Only consider subs which match the current subId
6063 // This logic can be simplified. See b/131189269 for progress.
6064 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006065 activeSubscriberIds.add(tele.getSubscriberId(subId));
6066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067
6068 // First pass, find a number override for an active subscriber
6069 String mergeNumber = null;
6070 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6071 for (String key : prefs.keySet()) {
6072 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6073 final String subscriberId = (String) prefs.get(key);
6074 if (activeSubscriberIds.contains(subscriberId)) {
6075 final String iccId = key.substring(
6076 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6077 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6078 mergeNumber = (String) prefs.get(numberKey);
6079 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006080 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 + " for active subscriber " + subscriberId);
6082 }
6083 if (!TextUtils.isEmpty(mergeNumber)) {
6084 break;
6085 }
6086 }
6087 }
6088 }
6089
6090 // Shortcut when no active merged subscribers
6091 if (TextUtils.isEmpty(mergeNumber)) {
6092 return null;
6093 }
6094
6095 // Second pass, find all subscribers under that line override
6096 final ArraySet<String> result = new ArraySet<>();
6097 for (String key : prefs.keySet()) {
6098 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6099 final String number = (String) prefs.get(key);
6100 if (mergeNumber.equals(number)) {
6101 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6102 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6103 final String subscriberId = (String) prefs.get(subscriberKey);
6104 if (!TextUtils.isEmpty(subscriberId)) {
6105 result.add(subscriberId);
6106 }
6107 }
6108 }
6109 }
6110
6111 final String[] resultArray = result.toArray(new String[result.size()]);
6112 Arrays.sort(resultArray);
6113 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006114 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6116 }
6117 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006118 } finally {
6119 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006120 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006121 }
6122
6123 @Override
zoey chen38003472019-12-13 17:16:31 +08006124 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6125 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 final TelephonyManager telephonyManager = mApp.getSystemService(
6130 TelephonyManager.class);
6131 String subscriberId = telephonyManager.getSubscriberId(subId);
6132 if (subscriberId == null) {
6133 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006134 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006135 + subId);
6136 }
6137 return null;
6138 }
6139
6140 final SubscriptionInfo info = SubscriptionController.getInstance()
6141 .getSubscriptionInfo(subId);
6142 final ParcelUuid groupUuid = info.getGroupUuid();
6143 // If it doesn't belong to any group, return just subscriberId of itself.
6144 if (groupUuid == null) {
6145 return new String[]{subscriberId};
6146 }
6147
6148 // Get all subscriberIds from the group.
6149 final List<String> mergedSubscriberIds = new ArrayList<>();
6150 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006151 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006152 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006153 for (SubscriptionInfo subInfo : groupInfos) {
6154 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6155 if (subscriberId != null) {
6156 mergedSubscriberIds.add(subscriberId);
6157 }
6158 }
6159
6160 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163
6164 }
6165 }
6166
6167 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006168 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006169 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006170 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171
6172 final long identity = Binder.clearCallingIdentity();
6173 try {
6174 final Phone phone = getPhone(subId);
6175 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006179 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006180
6181 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006182 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006183 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6184 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006185 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6186 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 final Phone phone = getPhone(subId);
6191 if (phone == null) {
6192 return false;
6193 }
6194 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6195 cdmaNonRoamingList);
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006198 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006199 }
6200
6201 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006202 @Deprecated
6203 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6204 enforceModifyPermission();
6205
6206 int returnValue = 0;
6207 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006208 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006209 if(result.exception == null) {
6210 if (result.result != null) {
6211 byte[] responseData = (byte[])(result.result);
6212 if(responseData.length > oemResp.length) {
6213 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6214 responseData.length + "bytes. Buffer Size is " +
6215 oemResp.length + "bytes.");
6216 }
6217 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6218 returnValue = responseData.length;
6219 }
6220 } else {
6221 CommandException ex = (CommandException) result.exception;
6222 returnValue = ex.getCommandError().ordinal();
6223 if(returnValue > 0) returnValue *= -1;
6224 }
6225 } catch (RuntimeException e) {
6226 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6227 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6228 if(returnValue > 0) returnValue *= -1;
6229 }
6230
6231 return returnValue;
6232 }
6233
6234 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006235 public void setRadioCapability(RadioAccessFamily[] rafs) {
6236 try {
6237 ProxyController.getInstance().setRadioCapability(rafs);
6238 } catch (RuntimeException e) {
6239 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6240 }
6241 }
6242
6243 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006244 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006245 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006246 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006247 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006248 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 final long identity = Binder.clearCallingIdentity();
6251 try {
chen xub97461a2018-10-26 14:17:57 -07006252 TelephonyPermissions
6253 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6254 mApp, phone.getSubId(), "getRadioAccessFamily");
6255 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 } finally {
6257 Binder.restoreCallingIdentity(identity);
6258 }
chen xub97461a2018-10-26 14:17:57 -07006259 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006260 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006261
6262 @Override
6263 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006264 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006265 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006269 ImsManager.getInstance(defaultPhone.getContext(),
6270 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 } finally {
6272 Binder.restoreCallingIdentity(identity);
6273 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006274 }
6275
6276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006277 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006278 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6280 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006281 return false;
6282 }
Svet Ganovb320e182015-04-16 12:30:10 -07006283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 // Check the user preference and the system-level IMS setting. Even if the user has
6287 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6288 // In the long run, we may instead need to check if there exists a connection service
6289 // which can support video calling.
6290 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006291 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 return imsManager.isVtEnabledByPlatform()
6293 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6294 && imsManager.isVtEnabledByUser();
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006298 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006299
Andrew Leea1239f22015-03-02 17:44:07 -08006300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006301 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6302 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006304 mApp, subId, callingPackage, callingFeatureId,
6305 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 return false;
6307 }
6308
6309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 CarrierConfigManager configManager =
6312 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006313 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Andrew Leea1239f22015-03-02 17:44:07 -08006318 }
6319
6320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006321 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006323 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 return false;
6325 }
6326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 CarrierConfigManager configManager =
6330 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
Andrew Leea1239f22015-03-02 17:44:07 -08006336 }
6337
Andrew Lee9431b832015-03-09 18:46:45 -07006338 @Override
6339 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006340 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006341 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006342 }
6343
6344 @Override
6345 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 final long identity = Binder.clearCallingIdentity();
6347 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006348 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
Andrew Lee9431b832015-03-09 18:46:45 -07006352 }
6353
Hall Liuf6668912018-10-31 17:05:23 -07006354 /**
6355 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6356 * support for the feature and device firmware support.
6357 *
6358 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6359 */
6360 @Override
6361 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006363 final Phone phone = getPhone(subscriptionId);
6364 if (phone == null) {
6365 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6366 return false;
6367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006369 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6371 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006372 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 return isCarrierSupported && isDeviceSupported;
6374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
Hall Liu98187582018-01-22 19:15:32 -08006377 }
6378
Hall Liuf6668912018-10-31 17:05:23 -07006379 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006380 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6381 * RTT setting, will return true if the device and carrier both support RTT.
6382 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006383 */
6384 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006387 boolean isRttSupported = isRttSupported(subscriptionId);
6388 boolean isUserRttSettingOn = Settings.Secure.getInt(
6389 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6390 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6391 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6392 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006396 }
6397
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006398 @Deprecated
6399 @Override
6400 public String getDeviceId(String callingPackage) {
6401 return getDeviceIdWithFeature(callingPackage, null);
6402 }
6403
Sanket Padawe7310cc72015-01-14 09:53:20 -08006404 /**
6405 * Returns the unique device ID of phone, for example, the IMEI for
6406 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6407 *
6408 * <p>Requires Permission:
6409 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6410 */
6411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006412 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006413 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006414 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006415 return null;
6416 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006417 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006418 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006419 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006420 return null;
6421 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422
6423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 return phone.getDeviceId();
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
6428 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006429 }
6430
Ping Sunc67b7c22016-03-02 19:16:45 +08006431 /**
6432 * {@hide}
6433 * Returns the IMS Registration Status on a particular subid
6434 *
6435 * @param subId
6436 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006437 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006438 Phone phone = getPhone(subId);
6439 if (phone != null) {
6440 return phone.isImsRegistered();
6441 } else {
6442 return false;
6443 }
6444 }
6445
Santos Cordon7a1885b2015-02-03 11:15:19 -08006446 @Override
6447 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006454 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006455
Tyler Gunnf70ed162019-04-03 15:28:53 -07006456 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006457 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006458 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006460 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006461 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6462 }
6463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006472 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 Phone phone = getPhone(subscriptionId);
6476 if (phone == null) {
6477 return null;
6478 }
6479 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 }
6484
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006485 /**
6486 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006487 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006488 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 Phone phone = getPhone(subId);
6492 if (phone != null) {
6493 return phone.isWifiCallingEnabled();
6494 } else {
6495 return false;
6496 }
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006499 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006500 }
6501
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006502 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006503 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006504 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006505 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 Phone phone = getPhone(subId);
6509 if (phone != null) {
6510 return phone.isVideoEnabled();
6511 } else {
6512 return false;
6513 }
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006516 }
6517 }
6518
6519 /**
6520 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6521 * defined in {@link ImsRegistrationImplBase}.
6522 */
6523 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 Phone phone = getPhone(subId);
6527 if (phone != null) {
6528 return phone.getImsRegistrationTech();
6529 } else {
6530 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6531 }
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006534 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006535 }
6536
Stuart Scott8eef64f2015-04-08 15:13:54 -07006537 @Override
6538 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006539 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006540 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6541 return;
6542 }
6543
Svet Ganovcc087f82015-05-12 20:35:54 -07006544 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006545
Svet Ganovcc087f82015-05-12 20:35:54 -07006546 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006547 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6548 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006549 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006550 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006551 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006552 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6553 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006554 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006555 // There has been issues when Sms raw table somehow stores orphan
6556 // fragments. They lead to garbled message when new fragments come
6557 // in and combined with those stale ones. In case this happens again,
6558 // user can reset all network settings which will clean up this table.
6559 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006560 // Clean up IMS settings as well here.
6561 int slotId = getSlotIndex(subId);
6562 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6563 ImsManager.getInstance(mApp, slotId).factoryReset();
6564 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006565
6566 // Erase modem config if erase modem on network setting is enabled.
6567 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6568 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6569 if (configValue != null && Boolean.parseBoolean(configValue)) {
6570 sendEraseModemConfig(getDefaultPhone());
6571 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006572 } finally {
6573 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006574 }
6575 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006576
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006577 private void cleanUpSmsRawTable(Context context) {
6578 ContentResolver resolver = context.getContentResolver();
6579 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6580 resolver.delete(uri, null, null);
6581 }
6582
Narayan Kamath1c496c22015-04-16 14:40:19 +01006583 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006584 public String getSimLocaleForSubscriber(int subId) {
6585 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6586 final Phone phone = getPhone(subId);
6587 if (phone == null) {
6588 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006589 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 final long identity = Binder.clearCallingIdentity();
6592 try {
chen xu5d3637b2019-01-21 23:31:38 -08006593 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006594 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006595 if (info == null) {
6596 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6597 return null;
6598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 // Try and fetch the locale from the carrier properties or from the SIM language
6600 // preferences (EF-PL and EF-LI)...
6601 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006603 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6604 if (localeFromDefaultSim != null) {
6605 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6606 if (DBG) log("Using locale from subId: " + subId + " locale: "
6607 + localeFromDefaultSim);
6608 return localeFromDefaultSim.toLanguageTag();
6609 } else {
6610 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 }
6612 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 // The SIM language preferences only store a language (e.g. fr = French), not an
6615 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6616 // the SIM and carrier preferences does not include a country we add the country
6617 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006618 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006620 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 return mccLocale.toLanguageTag();
6622 }
6623
6624 if (DBG) log("No locale found - returning null");
6625 return null;
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006629 }
6630
6631 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006632 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006633 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006634 }
6635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 /**
6637 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6638 */
6639 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006640 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006641 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006642 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006643
Chenjie Yu1ba97252018-01-11 18:16:20 -08006644 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006645 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006646
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006647 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006648 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6649 * representing the state of the modem.
6650 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006651 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6652 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006653 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006654 */
6655 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006656 public void requestModemActivityInfo(ResultReceiver result) {
6657 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
Shuo Qian1d931ee2020-02-20 17:12:10 -08006662 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 } finally {
6664 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006665 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006666 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006667
Siddharth Rayb8114062018-06-17 15:02:38 -07006668 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6669 // less than total activity duration.
6670 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6671 if (info == null) {
6672 return false;
6673 }
6674 int activityDurationMs =
6675 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6676 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006677 int[] txTimeMs = info.getTransmitTimeMillis();
6678 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6679 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006680 }
6681 return (info.isValid()
6682 && (info.getSleepTimeMillis() <= activityDurationMs)
6683 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006684 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006685 && (totalTxTimeMs <= activityDurationMs));
6686 }
6687
Jack Yu85bd38a2015-11-09 11:34:32 -08006688 /**
6689 * {@hide}
6690 * Returns the service state information on specified subscription.
6691 */
6692 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006693 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6694 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006696 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006697 return null;
6698 }
6699
Hall Liuf19c44f2018-11-27 14:38:17 -08006700 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6701 LocationAccessPolicy.checkLocationPermission(mApp,
6702 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6703 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006704 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006705 .setCallingPid(Binder.getCallingPid())
6706 .setCallingUid(Binder.getCallingUid())
6707 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006708 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006709 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6710 .build());
6711
6712 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6713 LocationAccessPolicy.checkLocationPermission(mApp,
6714 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6715 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006716 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006717 .setCallingPid(Binder.getCallingPid())
6718 .setCallingUid(Binder.getCallingUid())
6719 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006720 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006721 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6722 .build());
6723 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6724 boolean hasFinePermission =
6725 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6726 boolean hasCoarsePermission =
6727 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 final long identity = Binder.clearCallingIdentity();
6730 try {
6731 final Phone phone = getPhone(subId);
6732 if (phone == null) {
6733 return null;
6734 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006735
Hall Liuf19c44f2018-11-27 14:38:17 -08006736 ServiceState ss = phone.getServiceState();
6737
6738 // Scrub out the location info in ServiceState depending on what level of access
6739 // the caller has.
6740 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006741 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6742 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006746 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006747
6748 /**
6749 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6750 *
6751 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6752 * voicemail ringtone.
6753 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6754 * PhoneAccount.
6755 */
6756 @Override
6757 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6761 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006762 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006769 }
6770
6771 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006772 * Sets the per-account voicemail ringtone.
6773 *
6774 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6775 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6776 *
6777 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6778 * voicemail ringtone.
6779 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6780 * PhoneAccount.
6781 */
6782 @Override
6783 public void setVoicemailRingtoneUri(String callingPackage,
6784 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006785 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006787 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6788 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6790 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6791 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
6796 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6797 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006798 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 }
6800 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006803 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006804 }
6805
6806 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006807 * Returns whether vibration is set for voicemail notification in Phone settings.
6808 *
6809 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6810 * voicemail vibration setting.
6811 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6812 */
6813 @Override
6814 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6818 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006819 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
6825 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006826 }
6827
Youhan Wange64578a2016-05-02 15:32:42 -07006828 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006829 * Sets the per-account voicemail vibration.
6830 *
6831 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6832 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6833 *
6834 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6835 * voicemail vibration setting.
6836 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6837 * specific PhoneAccount.
6838 */
6839 @Override
6840 public void setVoicemailVibrationEnabled(String callingPackage,
6841 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006842 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006843 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006844 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6845 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6847 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6848 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006849 }
6850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6854 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006855 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 }
6857 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6858 } finally {
6859 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006860 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006861 }
6862
6863 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006864 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6865 *
6866 * @throws SecurityException if the caller does not have the required permission
6867 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006868 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006869 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006870 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006871 }
6872
6873 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006874 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6875 * permission.
6876 *
6877 * @throws SecurityException if the caller does not have the required permission
6878 */
6879 private void enforceSendSmsPermission() {
6880 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6881 }
6882
6883 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006884 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006885 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006886 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006887 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006888 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006892 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 if (componentName == null) {
6894 throw new SecurityException(
6895 "Caller not current active visual voicemail package[null]");
6896 }
6897 String vvmPackage = componentName.getPackageName();
6898 if (!callingPackage.equals(vvmPackage)) {
6899 throw new SecurityException("Caller not current active visual voicemail package["
6900 + vvmPackage + "]");
6901 }
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006904 }
6905 }
6906
6907 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006908 * Return the application ID for the app type.
6909 *
6910 * @param subId the subscription ID that this request applies to.
6911 * @param appType the uicc app type.
6912 * @return Application ID for specificied app type, or null if no uicc.
6913 */
6914 @Override
6915 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006916 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006917 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918
6919 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006920 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 if (phone == null) {
6922 return null;
6923 }
6924 String aid = null;
6925 try {
6926 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6927 .getApplicationByType(appType).getAid();
6928 } catch (Exception e) {
6929 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6930 }
6931 return aid;
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006934 }
Youhan Wange64578a2016-05-02 15:32:42 -07006935 }
6936
Youhan Wang4001d252016-05-11 10:29:41 -07006937 /**
6938 * Return the Electronic Serial Number.
6939 *
6940 * @param subId the subscription ID that this request applies to.
6941 * @return ESN or null if error.
6942 */
6943 @Override
6944 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006945 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006946 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947
6948 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006949 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 if (phone == null) {
6951 return null;
6952 }
6953 String esn = null;
6954 try {
6955 esn = phone.getEsn();
6956 } catch (Exception e) {
6957 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6958 }
6959 return esn;
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006962 }
Youhan Wang4001d252016-05-11 10:29:41 -07006963 }
6964
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006965 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006966 * Return the Preferred Roaming List Version.
6967 *
6968 * @param subId the subscription ID that this request applies to.
6969 * @return PRLVersion or null if error.
6970 */
6971 @Override
6972 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006973 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006974 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975
6976 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006977 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 if (phone == null) {
6979 return null;
6980 }
6981 String cdmaPrlVersion = null;
6982 try {
6983 cdmaPrlVersion = phone.getCdmaPrlVersion();
6984 } catch (Exception e) {
6985 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6986 }
6987 return cdmaPrlVersion;
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006990 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006991 }
6992
6993 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006994 * Get snapshot of Telephony histograms
6995 * @return List of Telephony histograms
6996 * @hide
6997 */
6998 @Override
6999 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7001 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 return RIL.getTelephonyRILTimingHistograms();
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007009 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007010
7011 /**
7012 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007013 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7014 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007015 * Require system privileges. In the future we may add this to carrier APIs.
7016 *
Michele Berionne482f8202018-11-27 18:57:59 -08007017 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007018 */
7019 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007020 @TelephonyManager.SetCarrierRestrictionResult
7021 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007022 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007024
Michele Berionne482f8202018-11-27 18:57:59 -08007025 if (carrierRestrictionRules == null) {
7026 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007027 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007031 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007032 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007036 }
7037
7038 /**
7039 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007040 * Get the allowed carrier list and the excluded carrier list, including the priority between
7041 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007042 * Require system privileges. In the future we may add this to carrier APIs.
7043 *
Michele Berionne482f8202018-11-27 18:57:59 -08007044 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007045 */
7046 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007047 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007048 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007049 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007053 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7054 if (response instanceof CarrierRestrictionRules) {
7055 return (CarrierRestrictionRules) response;
7056 }
7057 // Response is an Exception of some kind,
7058 // which is signalled to the user as a NULL retval
7059 return null;
7060 } catch (Exception e) {
7061 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7062 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007066 }
7067
fionaxu59545b42016-05-25 15:53:37 -07007068 /**
7069 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7070 * @param subId the subscription ID that this action applies to.
7071 * @param enabled control enable or disable metered apns.
7072 * {@hide}
7073 */
7074 @Override
7075 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7076 enforceModifyPermission();
7077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078
7079 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007080 if (phone == null) {
7081 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7082 return;
7083 }
7084 try {
7085 phone.carrierActionSetMeteredApnsEnabled(enabled);
7086 } catch (Exception e) {
7087 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 } finally {
7089 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007090 }
7091 }
7092
7093 /**
7094 * Action set from carrier signalling broadcast receivers to enable/disable radio
7095 * @param subId the subscription ID that this action applies to.
7096 * @param enabled control enable or disable radio.
7097 * {@hide}
7098 */
7099 @Override
7100 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7101 enforceModifyPermission();
7102 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007105 if (phone == null) {
7106 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7107 return;
7108 }
7109 try {
7110 phone.carrierActionSetRadioEnabled(enabled);
7111 } catch (Exception e) {
7112 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 } finally {
7114 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007115 }
7116 }
7117
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007118 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007119 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7120 * network status based on which carrier apps could apply actions accordingly,
7121 * enable/disable default url handler for example.
7122 *
7123 * @param subId the subscription ID that this action applies to.
7124 * @param report control start/stop reporting the default network status.
7125 * {@hide}
7126 */
7127 @Override
7128 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7129 enforceModifyPermission();
7130 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131
7132 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007133 if (phone == null) {
7134 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7135 return;
7136 }
7137 try {
7138 phone.carrierActionReportDefaultNetworkStatus(report);
7139 } catch (Exception e) {
7140 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007143 }
7144 }
7145
7146 /**
fionaxud9622282017-07-17 17:51:30 -07007147 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7148 * @param subId the subscription ID that this action applies to.
7149 * {@hide}
7150 */
7151 @Override
7152 public void carrierActionResetAll(int subId) {
7153 enforceModifyPermission();
7154 final Phone phone = getPhone(subId);
7155 if (phone == null) {
7156 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7157 return;
7158 }
7159 try {
7160 phone.carrierActionResetAll();
7161 } catch (Exception e) {
7162 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7163 }
7164 }
7165
7166 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007167 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7168 * bug report is being generated.
7169 */
7170 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007171 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007172 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7173 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007174 writer.println("Permission Denial: can't dump Phone from pid="
7175 + Binder.getCallingPid()
7176 + ", uid=" + Binder.getCallingUid()
7177 + "without permission "
7178 + android.Manifest.permission.DUMP);
7179 return;
7180 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007181 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007182 }
Jack Yueb89b242016-06-22 13:27:47 -07007183
Brad Ebingerdac2f002018-04-03 15:17:52 -07007184 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007185 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7186 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7187 @NonNull String[] args) {
7188 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7189 this, in.getFileDescriptor(), out.getFileDescriptor(),
7190 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007191 }
7192
Jack Yueb89b242016-06-22 13:27:47 -07007193 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007194 * Policy control of data connection. Usually used when data limit is passed.
7195 * @param enabled True if enabling the data, otherwise disabling.
7196 * @param subId Subscription index
7197 * {@hide}
7198 */
7199 @Override
7200 public void setPolicyDataEnabled(boolean enabled, int subId) {
7201 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 Phone phone = getPhone(subId);
7206 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007207 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 }
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007211 }
7212 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007213
7214 /**
7215 * Get Client request stats
7216 * @return List of Client Request Stats
7217 * @hide
7218 */
7219 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007220 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7221 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007223 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007224 return null;
7225 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007226 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 final long identity = Binder.clearCallingIdentity();
7229 try {
7230 if (phone != null) {
7231 return phone.getClientRequestStats();
7232 }
7233
7234 return null;
7235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007238 }
7239
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007240 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007241 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007242 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007243 }
Jack Yueb4124c2017-02-16 15:32:43 -08007244
7245 /**
Grace Chen70990072017-03-24 17:21:30 -07007246 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007247 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007248 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007249 * @param state State of SIM (power down, power up, pass through)
7250 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7251 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7252 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007253 *
7254 **/
7255 @Override
Grace Chen70990072017-03-24 17:21:30 -07007256 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007257 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007258 Phone phone = PhoneFactory.getPhone(slotIndex);
7259
vagdeviaf9a5b92018-08-15 16:01:53 -07007260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007265 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 }
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007269 }
7270 }
Shuo Qiandd210312017-04-12 22:11:33 +00007271
Tyler Gunn65d45c22017-06-05 11:22:26 -07007272 private boolean isUssdApiAllowed(int subId) {
7273 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007274 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007275 if (configManager == null) {
7276 return false;
7277 }
7278 PersistableBundle pb = configManager.getConfigForSubId(subId);
7279 if (pb == null) {
7280 return false;
7281 }
7282 return pb.getBoolean(
7283 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7284 }
7285
Shuo Qiandd210312017-04-12 22:11:33 +00007286 /**
7287 * Check if phone is in emergency callback mode
7288 * @return true if phone is in emergency callback mode
7289 * @param subId sub id
7290 */
goneil9c5f4872017-12-05 14:07:56 -08007291 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007292 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007293 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007294 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295
7296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 if (phone != null) {
7299 return phone.isInEcm();
7300 } else {
7301 return false;
7302 }
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007305 }
7306 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007307
7308 /**
7309 * Get the current signal strength information for the given subscription.
7310 * Because this information is not updated when the device is in a low power state
7311 * it should not be relied-upon to be current.
7312 * @param subId Subscription index
7313 * @return the most recent cached signal strength info from the modem
7314 */
7315 @Override
7316 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 Phone p = getPhone(subId);
7320 if (p == null) {
7321 return null;
7322 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 return p.getSignalStrength();
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007328 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007329
Pengquan Meng77b7f132018-08-22 14:49:57 -07007330 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007331 * Get the current modem radio state for the given slot.
7332 * @param slotIndex slot index.
7333 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007334 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007335 * @return the current radio power state from the modem
7336 */
7337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007339 Phone phone = PhoneFactory.getPhone(slotIndex);
7340 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7342 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007343 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7344 }
7345
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 return phone.getRadioPowerState();
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
7352 }
7353 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7354 }
7355
7356 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007357 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7358 *
7359 * <p>Requires one of the following permissions:
7360 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7361 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7362 * privileges.
7363 *
7364 * @param subId subscription id
7365 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7366 * {@code false}.
7367 */
7368 @Override
7369 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007370 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7371 null /* message */);
7372
Pengquan Menga1bb6272018-09-06 09:59:22 -07007373 boolean isEnabled = false;
7374 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007375 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007376 Phone phone = getPhone(subId);
7377 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007378 } catch (Exception e) {
7379 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7380 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007381 } finally {
7382 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007383 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007384 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007385 }
7386
7387
7388 /**
7389 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7390 *
7391 * <p> Requires permission:
7392 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7393 * privileges.
7394 *
7395 * @param subId subscription id
7396 * @param isEnabled {@code true} means enable, {@code false} means disable.
7397 */
7398 @Override
7399 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7401 mApp, subId, "setDataRoamingEnabled");
7402
Pengquan Menga1bb6272018-09-06 09:59:22 -07007403 final long identity = Binder.clearCallingIdentity();
7404 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007405 Phone phone = getPhone(subId);
7406 if (phone != null) {
7407 phone.setDataRoamingEnabled(isEnabled);
7408 }
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007411 }
7412 }
7413
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007414 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007415 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007416 TelephonyPermissions
7417 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007418 mApp, subId, "isManualNetworkSelectionAllowed");
7419
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007420 boolean isAllowed = true;
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007423 Phone phone = getPhone(subId);
7424 if (phone != null) {
7425 isAllowed = phone.isCspPlmnEnabled();
7426 }
7427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
7430 return isAllowed;
7431 }
7432
7433 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007434 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007435 // Verify that tha callingPackage belongs to the calling UID
7436 mApp.getSystemService(AppOpsManager.class)
7437 .checkPackage(Binder.getCallingUid(), callingPackage);
7438
Jordan Liu1e142fc2019-04-22 15:10:43 -07007439 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007440 try {
7441 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007442 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007443 } catch (SecurityException e) {
7444 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7445 // has carrier privileges on an active UICC
7446 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7447 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007448 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007449 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007450 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007451
7452 final long identity = Binder.clearCallingIdentity();
7453 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007454 UiccController uiccController = UiccController.getInstance();
7455 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007456 if (hasReadPermission) {
7457 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007458 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007459
7460 // Remove private info if the caller doesn't have access
7461 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7462 for (UiccCardInfo cardInfo : cardInfos) {
7463 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7464 // is available
7465 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7466 if (card == null || card.getUiccProfile() == null) {
7467 // assume no access if the card or profile is unavailable
7468 filteredInfos.add(cardInfo.getUnprivileged());
7469 continue;
7470 }
7471 UiccProfile profile = card.getUiccProfile();
7472 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7473 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7474 filteredInfos.add(cardInfo);
7475 } else {
7476 filteredInfos.add(cardInfo.getUnprivileged());
7477 }
7478 }
7479 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
7483 }
7484
7485 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007486 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007487 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7492 if (slots == null) {
7493 Rlog.i(LOG_TAG, "slots is null.");
7494 return null;
7495 }
7496
7497 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7498 for (int i = 0; i < slots.length; i++) {
7499 UiccSlot slot = slots[i];
7500 if (slot == null) {
7501 continue;
7502 }
7503
Jordan Liu7be7e652019-05-06 18:55:02 +00007504 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 UiccCard card = slot.getUiccCard();
7506 if (card != null) {
7507 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007508 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007509 cardId = slot.getEid();
7510 if (TextUtils.isEmpty(cardId)) {
7511 cardId = slot.getIccId();
7512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 }
7514
Jordan Liu857451f2019-05-09 16:35:35 -07007515 if (cardId != null) {
7516 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7517 // if cardId is an EID, it's all digits so this is fine
7518 cardId = IccUtils.stripTrailingFs(cardId);
7519 }
7520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 int cardState = 0;
7522 switch (slot.getCardState()) {
7523 case CARDSTATE_ABSENT:
7524 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7525 break;
7526 case CARDSTATE_PRESENT:
7527 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7528 break;
7529 case CARDSTATE_ERROR:
7530 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7531 break;
7532 case CARDSTATE_RESTRICTED:
7533 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7534 break;
7535 default:
7536 break;
7537
7538 }
7539
7540 infos[i] = new UiccSlotInfo(
7541 slot.isActive(),
7542 slot.isEuicc(),
7543 cardId,
7544 cardState,
7545 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007546 slot.isExtendedApduSupported(),
7547 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 }
7549 return infos;
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007552 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007553 }
7554
7555 @Override
7556 public boolean switchSlots(int[] physicalSlots) {
7557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558
7559 final long identity = Binder.clearCallingIdentity();
7560 try {
7561 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007565 }
Jack Yu4c988042018-02-27 15:30:01 -08007566
7567 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007568 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 return UiccController.getInstance().getCardIdForDefaultEuicc();
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
7576
Pengquan Meng85728fb2018-03-12 16:31:21 -07007577 /**
goneil47ffb6e2018-04-06 15:40:58 -07007578 * A test API to reload the UICC profile.
7579 *
7580 * <p>Requires that the calling app has permission
7581 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7582 * @hide
7583 */
7584 @Override
7585 public void refreshUiccProfile(int subId) {
7586 enforceModifyPermission();
7587
7588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 Phone phone = getPhone(subId);
7591 if (phone == null) {
7592 return;
7593 }
7594 UiccCard uiccCard = phone.getUiccCard();
7595 if (uiccCard == null) {
7596 return;
7597 }
7598 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7599 if (uiccProfile == null) {
7600 return;
7601 }
7602 uiccProfile.refresh();
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
7606 }
7607
7608 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007609 * Returns false if the mobile data is disabled by default, otherwise return true.
7610 */
7611 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007612 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007613 }
7614
7615 /**
7616 * Returns true if the data roaming is enabled by default, i.e the system property
7617 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7618 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7619 */
7620 private boolean getDefaultDataRoamingEnabled(int subId) {
7621 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007622 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007623 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007624 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7625 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7626 return isDataRoamingEnabled;
7627 }
7628
7629 /**
7630 * Returns the default network type for the given {@code subId}, if the default network type is
7631 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7632 */
7633 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007634 List<Integer> list = TelephonyProperties.default_network();
7635 int phoneId = mSubscriptionController.getPhoneId(subId);
7636 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7637 return list.get(phoneId);
7638 }
7639 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007640 }
fionaxua13278b2018-03-21 00:08:13 -07007641
7642 @Override
7643 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007644 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646
7647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 final Phone phone = getPhone(subId);
7650 if (phone == null) {
7651 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7652 return;
7653 }
chen xueaba88a2019-03-15 13:15:10 -07007654 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7655 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 } finally {
7657 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007658 }
fionaxua13278b2018-03-21 00:08:13 -07007659 }
7660
7661 @Override
7662 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007663 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664
7665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 final Phone phone = getPhone(subId);
7668 if (phone == null) {
7669 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7670 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7671 }
7672 return phone.getCarrierIdListVersion();
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007675 }
fionaxua13278b2018-03-21 00:08:13 -07007676 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007677
7678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007679 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7680 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007682 mApp, subId, callingPackage, callingFeatureId,
7683 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007684 return -1;
7685 }
7686
7687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
7693 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007694
7695 @Override
7696 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007697 TelephonyPermissions
7698 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007699 mApp, subId, "getCdmaRoamingMode");
7700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
7708
7709 @Override
7710 public boolean setCdmaRoamingMode(int subId, int mode) {
7711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7712 mApp, subId, "setCdmaRoamingMode");
7713
7714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
7719 }
7720 }
7721
7722 @Override
7723 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7725 mApp, subId, "setCdmaSubscriptionMode");
7726
7727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
7732 }
7733 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007734
sqianc5eccab2018-10-19 18:46:41 -07007735 @Override
sqian8c685422019-02-22 15:55:18 -08007736 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007737 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007739 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7740 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007741 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7742 }
7743 final long identity = Binder.clearCallingIdentity();
7744 try {
sqian854d44b2018-12-12 16:48:18 -08007745 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7746 for (Phone phone: PhoneFactory.getPhones()) {
7747 if (phone.getEmergencyNumberTracker() != null
7748 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7749 emergencyNumberListInternal.put(
7750 phone.getSubId(),
7751 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7752 }
sqian11b7a0e2018-12-05 18:48:28 -08007753 }
sqian854d44b2018-12-12 16:48:18 -08007754 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007755 } finally {
7756 Binder.restoreCallingIdentity(identity);
7757 }
sqianc5eccab2018-10-19 18:46:41 -07007758 }
7759
7760 @Override
sqian8c685422019-02-22 15:55:18 -08007761 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007762 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007763 if (!exactMatch) {
7764 TelephonyPermissions
7765 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007766 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007767 }
7768 final long identity = Binder.clearCallingIdentity();
7769 try {
sqian854d44b2018-12-12 16:48:18 -08007770 for (Phone phone: PhoneFactory.getPhones()) {
7771 if (phone.getEmergencyNumberTracker() != null
7772 && phone.getEmergencyNumberTracker() != null) {
7773 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7774 number, exactMatch)) {
7775 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007776 }
7777 }
sqian11b7a0e2018-12-05 18:48:28 -08007778 }
7779 return false;
7780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
7783 }
7784
sqianf4ca7ed2019-01-15 18:32:07 -08007785 /**
7786 * Update emergency number list for test mode.
7787 */
7788 @Override
7789 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7791 "updateEmergencyNumberListTestMode");
7792
7793 final long identity = Binder.clearCallingIdentity();
7794 try {
7795 for (Phone phone: PhoneFactory.getPhones()) {
7796 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7797 if (tracker != null) {
7798 tracker.executeEmergencyNumberTestModeCommand(action, num);
7799 }
7800 }
7801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
7804 }
7805
7806 /**
7807 * Get the full emergency number list for test mode.
7808 */
7809 @Override
7810 public List<String> getEmergencyNumberListTestMode() {
7811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7812 "getEmergencyNumberListTestMode");
7813
7814 final long identity = Binder.clearCallingIdentity();
7815 try {
7816 Set<String> emergencyNumbers = new HashSet<>();
7817 for (Phone phone: PhoneFactory.getPhones()) {
7818 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7819 if (tracker != null) {
7820 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7821 emergencyNumbers.add(num.getNumber());
7822 }
7823 }
7824 }
7825 return new ArrayList<>(emergencyNumbers);
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
7829 }
7830
chen xud6b45bd2018-10-30 22:27:10 -07007831 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007832 public int getEmergencyNumberDbVersion(int subId) {
7833 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7834
7835 final long identity = Binder.clearCallingIdentity();
7836 try {
7837 final Phone phone = getPhone(subId);
7838 if (phone == null) {
7839 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7840 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7841 }
7842 return phone.getEmergencyNumberDbVersion();
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
7846 }
7847
7848 @Override
7849 public void notifyOtaEmergencyNumberDbInstalled() {
7850 enforceModifyPermission();
7851
7852 final long identity = Binder.clearCallingIdentity();
7853 try {
7854 for (Phone phone: PhoneFactory.getPhones()) {
7855 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7856 if (tracker != null) {
7857 tracker.updateOtaEmergencyNumberDatabase();
7858 }
7859 }
7860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
7863 }
7864
7865 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007866 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007867 enforceActiveEmergencySessionPermission();
7868
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 for (Phone phone: PhoneFactory.getPhones()) {
7872 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7873 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007874 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7875 }
7876 }
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879 }
7880 }
7881
7882 @Override
7883 public void resetOtaEmergencyNumberDbFilePath() {
7884 enforceActiveEmergencySessionPermission();
7885
7886 final long identity = Binder.clearCallingIdentity();
7887 try {
7888 for (Phone phone: PhoneFactory.getPhones()) {
7889 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7890 if (tracker != null) {
7891 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007892 }
7893 }
7894 } finally {
7895 Binder.restoreCallingIdentity(identity);
7896 }
7897 }
7898
7899 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007900 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7901 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7902 Phone phone = getPhone(subId);
7903 if (phone == null) {
7904 return null;
7905 }
7906 final long identity = Binder.clearCallingIdentity();
7907 try {
7908 UiccProfile profile = UiccController.getInstance()
7909 .getUiccProfileForPhone(phone.getPhoneId());
7910 if (profile != null) {
7911 return profile.getCertsFromCarrierPrivilegeAccessRules();
7912 }
7913 } finally {
7914 Binder.restoreCallingIdentity(identity);
7915 }
7916 return null;
7917 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007918
7919 /**
7920 * Enable or disable a modem stack.
7921 */
7922 @Override
7923 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7924 enforceModifyPermission();
7925
7926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 Phone phone = PhoneFactory.getPhone(slotIndex);
7929 if (phone == null) {
7930 return false;
7931 } else {
7932 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7933 }
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
7937 }
Michelecea4cf22018-12-21 15:00:11 -08007938
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007939 /**
7940 * Whether a modem stack is enabled or not.
7941 */
7942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007943 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7944 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007945 Phone phone = PhoneFactory.getPhone(slotIndex);
7946 if (phone == null) return false;
7947
7948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007949 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7950 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007951 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7952 }
7953
7954 final long identity = Binder.clearCallingIdentity();
7955 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007956 try {
7957 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7958 } catch (NoSuchElementException ex) {
7959 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7960 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007961 } finally {
7962 Binder.restoreCallingIdentity(identity);
7963 }
7964 }
7965
Michelecea4cf22018-12-21 15:00:11 -08007966 @Override
Michele0ea7d782019-03-19 14:58:42 -07007967 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007968 enforceModifyPermission();
7969
7970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007973 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007974 .commit();
7975 } finally {
7976 Binder.restoreCallingIdentity(identity);
7977 }
7978 }
7979
7980 @Override
Michele0ea7d782019-03-19 14:58:42 -07007981 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007982 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007984 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7985 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007986 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007987 }
Michelecea4cf22018-12-21 15:00:11 -08007988
7989 final long identity = Binder.clearCallingIdentity();
7990 try {
Michele0ea7d782019-03-19 14:58:42 -07007991 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007992 } finally {
7993 Binder.restoreCallingIdentity(identity);
7994 }
7995 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007996
Michele0ea7d782019-03-19 14:58:42 -07007997 @TelephonyManager.IsMultiSimSupportedResult
7998 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007999 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8000 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8001 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008002 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8003 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008004 }
8005 // Check if the hardware supports multisim functionality. If usage of multisim is not
8006 // supported by the modem, indicate that it is restricted.
8007 PhoneCapability staticCapability =
8008 mPhoneConfigurationManager.getStaticPhoneCapability();
8009 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008010 loge("isMultiSimSupportedInternal: no static configuration available");
8011 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008012 }
Sarah Chin7caee492020-02-18 20:49:02 +00008013 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008014 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8015 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008016 }
8017 // Check if support of multiple SIMs is restricted by carrier
8018 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008019 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008020 }
8021
Michele0ea7d782019-03-19 14:58:42 -07008022 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008023 }
8024
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008025 /**
8026 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008027 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8028 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8029 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008030 * @param numOfSims number of active sims we want to switch to
8031 */
8032 @Override
8033 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008034 if (numOfSims == 1) {
8035 enforceModifyPermission();
8036 } else {
8037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8038 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8039 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008040 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008041
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008042 try {
Michele30b57b22019-03-01 12:01:14 -08008043 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008044 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008045 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8046 return;
8047 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008048 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8049 } finally {
8050 Binder.restoreCallingIdentity(identity);
8051 }
8052 }
8053
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008054 @Override
8055 public boolean isApplicationOnUicc(int subId, int appType) {
8056 enforceReadPrivilegedPermission("isApplicationOnUicc");
8057 Phone phone = getPhone(subId);
8058 if (phone == null) {
8059 return false;
8060 }
8061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 UiccCard uiccCard = phone.getUiccCard();
8064 if (uiccCard == null) {
8065 return false;
8066 }
8067 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8068 if (uiccProfile == null) {
8069 return false;
8070 }
8071 if (TelephonyManager.APPTYPE_SIM <= appType
8072 && appType <= TelephonyManager.APPTYPE_ISIM) {
8073 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8074 }
8075 return false;
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
8078 }
8079 }
8080
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008081 /**
chen xub4baa772019-04-03 10:23:41 -07008082 * Get whether making changes to modem configurations will trigger reboot.
8083 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008084 */
8085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008086 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8087 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008089 mApp, subId, callingPackage, callingFeatureId,
8090 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008091 return false;
8092 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008093 final long identity = Binder.clearCallingIdentity();
8094 try {
8095 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
8098 }
8099 }
8100
Nathan Harold29f5f052019-02-15 13:41:57 -08008101 private void updateModemStateMetrics() {
8102 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8103 // TODO: check the state for each modem if the api is ready.
8104 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8105 }
8106
Pengquan Meng3889a572019-01-23 11:16:29 -08008107 @Override
8108 public int[] getSlotsMapping() {
8109 enforceReadPrivilegedPermission("getSlotsMapping");
8110
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8114 // All logical slots should have a mapping to a physical slot.
8115 int[] logicalSlotsMapping = new int[phoneCount];
8116 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8117 for (int i = 0; i < slotInfos.length; i++) {
8118 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8119 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8120 }
8121 }
8122 return logicalSlotsMapping;
8123 } finally {
8124 Binder.restoreCallingIdentity(identity);
8125 }
8126 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008127
8128 /**
8129 * Get the IRadio HAL Version
8130 */
8131 @Override
8132 public int getRadioHalVersion() {
8133 Phone phone = getDefaultPhone();
8134 if (phone == null) return -1;
8135 HalVersion hv = phone.getHalVersion();
8136 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8137 return hv.major * 100 + hv.minor;
8138 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008139
8140 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008141 * Get the current calling package name.
8142 * @return the current calling package name
8143 */
8144 @Override
8145 public String getCurrentPackageName() {
8146 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8147 }
8148
8149 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008150 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8151 * corresponding network requests on a subId.
8152 *
8153 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008154 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008155 * 2) APN is un-metered for this subscription, or
8156 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008157 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008158 *
8159 * @return whether data is allowed for a apn type.
8160 *
8161 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008162 */
8163 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008164 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008165 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8166 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008167
8168 // Now that all security checks passes, perform the operation as ourselves.
8169 final long identity = Binder.clearCallingIdentity();
8170 try {
8171 Phone phone = getPhone(subId);
8172 if (phone == null) return false;
8173
Jack Yu41407ee2019-05-13 16:54:09 -07008174 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008175 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8176 } finally {
8177 Binder.restoreCallingIdentity(identity);
8178 }
8179 }
8180
8181 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008182 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008183 enforceReadPrivilegedPermission("isApnMetered");
8184
8185 // Now that all security checks passes, perform the operation as ourselves.
8186 final long identity = Binder.clearCallingIdentity();
8187 try {
8188 Phone phone = getPhone(subId);
8189 if (phone == null) return true; // By default return true.
8190
Jack Yu41407ee2019-05-13 16:54:09 -07008191 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
8195 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008196
8197 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008198 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8199 int subscriptionId, IBooleanConsumer resultCallback) {
8200 enforceModifyPermission();
8201 long token = Binder.clearCallingIdentity();
8202 try {
8203 Phone phone = getPhone(subscriptionId);
8204 if (phone == null) {
8205 try {
8206 if (resultCallback != null) {
8207 resultCallback.accept(false);
8208 }
8209 } catch (RemoteException e) {
8210 // ignore
8211 }
8212 return;
8213 }
8214 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8215 Pair.create(specifiers, (x) -> {
8216 try {
8217 if (resultCallback != null) {
8218 resultCallback.accept(x);
8219 }
8220 } catch (RemoteException e) {
8221 // ignore
8222 }
8223 });
8224 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8225 } finally {
8226 Binder.restoreCallingIdentity(token);
8227 }
8228 }
8229
8230 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008231 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008232 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008233 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8234 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8235 if (iccRecords == null) {
8236 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8237 return false;
8238 }
8239 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8240 }
8241
8242 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008243 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8244 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008245 if (callingPackage == null) {
8246 callingPackage = getCurrentPackageName();
8247 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008248 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8249 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008250 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8251 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008252 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8253 }
8254 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8255 Intent intent = new Intent();
8256 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8257 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8258 // Bring up choose default SMS subscription dialog right now
8259 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8260 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8261 mApp.startActivity(intent);
8262 }
chen xud5ca2d52019-05-28 15:20:57 -07008263
8264 @Override
8265 public String getMmsUAProfUrl(int subId) {
8266 //TODO investigate if this API should require proper permission check in R b/133791609
8267 final long identity = Binder.clearCallingIdentity();
8268 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008269 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8270 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
8274 }
8275
8276 @Override
8277 public String getMmsUserAgent(int subId) {
8278 //TODO investigate if this API should require proper permission check in R b/133791609
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008281 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8282 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
Jack Yub07d4972019-05-28 16:12:25 -07008287
8288 @Override
8289 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8290 enforceModifyPermission();
8291
8292 // Now that all security checks passes, perform the operation as ourselves.
8293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 Phone phone = getPhone(subId);
8296 if (phone == null) return false;
8297
8298 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8299 } finally {
8300 Binder.restoreCallingIdentity(identity);
8301 }
8302 }
8303
8304 @Override
8305 public boolean isDataAllowedInVoiceCall(int subId) {
8306 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8307
8308 // Now that all security checks passes, perform the operation as ourselves.
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 Phone phone = getPhone(subId);
8312 if (phone == null) return false;
8313
8314 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
8318 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008319
changbettyd5c246e2019-12-24 15:40:37 +08008320 @Override
8321 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8322 enforceModifyPermission();
8323
8324 // Now that all security checks passes, perform the operation as ourselves.
8325 final long identity = Binder.clearCallingIdentity();
8326 try {
8327 Phone phone = getPhone(subId);
8328 if (phone == null) return false;
8329
8330 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
8334 }
8335
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008336 /**
8337 * Updates whether conference event pacakge handling is enabled.
8338 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8339 * otherwise.
8340 */
8341 @Override
8342 public void setCepEnabled(boolean isCepEnabled) {
8343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8344
8345 final long identity = Binder.clearCallingIdentity();
8346 try {
8347 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8348 for (Phone phone : PhoneFactory.getPhones()) {
8349 Phone defaultPhone = phone.getImsPhone();
8350 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8351 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8352 ImsPhoneCallTracker imsPhoneCallTracker =
8353 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8354 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8355 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8356 + imsPhone.getMsisdn());
8357 }
8358 }
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
8361 }
8362 }
allenwtsu46dcc572020-01-08 18:24:03 +08008363
8364 /**
8365 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8366 *
8367 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8368 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8369 * before being read.
8370 */
8371 @Override
8372 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8373 isCompressed) {
8374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8375 mApp, subId, "notifyRcsAutoConfigurationReceived");
8376 try {
8377 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8378 if (configBinder == null) {
8379 Rlog.e(LOG_TAG, "null result for getImsConfig");
8380 } else {
8381 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8382 }
8383 } catch (RemoteException e) {
8384 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8385 }
8386 }
zoey chene02881a2019-12-30 16:11:23 +08008387
8388 @Override
8389 public boolean isIccLockEnabled(int subId) {
8390 enforceReadPrivilegedPermission("isIccLockEnabled");
8391
8392 // Now that all security checks passes, perform the operation as ourselves.
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 Phone phone = getPhone(subId);
8396 if (phone != null && phone.getIccCard() != null) {
8397 return phone.getIccCard().getIccLockEnabled();
8398 } else {
8399 return false;
8400 }
8401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
8404 }
8405
8406 /**
8407 * Set the ICC pin lock enabled or disabled.
8408 *
8409 * @return an integer representing the status of IccLock enabled or disabled in the following
8410 * three cases:
8411 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8412 * successfully.
8413 * - Positive number and zero for remaining password attempts.
8414 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8415 *
8416 */
8417 @Override
8418 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8419 enforceModifyPermission();
8420
8421 Phone phone = getPhone(subId);
8422 if (phone == null) {
8423 return 0;
8424 }
8425 // Now that all security checks passes, perform the operation as ourselves.
8426 final long identity = Binder.clearCallingIdentity();
8427 try {
8428 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8429 new Pair<Boolean, String>(enabled, password), phone, null);
8430 return attemptsRemaining;
8431
8432 } catch (Exception e) {
8433 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 return 0;
8438 }
8439
8440 /**
8441 * Change the ICC password used in ICC pin lock.
8442 *
8443 * @return an integer representing the status of IccLock changed in the following three cases:
8444 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8445 * - Positive number and zero for remaining password attempts.
8446 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8447 *
8448 */
8449 @Override
8450 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8451 enforceModifyPermission();
8452
8453 Phone phone = getPhone(subId);
8454 if (phone == null) {
8455 return 0;
8456 }
8457 // Now that all security checks passes, perform the operation as ourselves.
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8461 new Pair<String, String>(oldPassword, newPassword), phone, null);
8462 return attemptsRemaining;
8463
8464 } catch (Exception e) {
8465 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 return 0;
8470 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008471
8472 /**
8473 * Request for receiving user activity notification
8474 */
8475 @Override
8476 public void requestUserActivityNotification() {
8477 if (!mNotifyUserActivity.get()
8478 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8479 mNotifyUserActivity.set(true);
8480 }
8481 }
8482
8483 /**
8484 * Called when userActivity is signalled in the power manager.
8485 * This is safe to call from any thread, with any window manager locks held or not.
8486 */
8487 @Override
8488 public void userActivity() {
8489 // ***************************************
8490 // * Inherited from PhoneWindowManager *
8491 // ***************************************
8492 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8493 // WITH ITS LOCKS HELD.
8494 //
8495 // This code must be VERY careful about the locks
8496 // it acquires.
8497 // In fact, the current code acquires way too many,
8498 // and probably has lurking deadlocks.
8499
8500 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8501 throw new SecurityException("Only the OS may call notifyUserActivity()");
8502 }
8503
8504 if (mNotifyUserActivity.getAndSet(false)) {
8505 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8506 USER_ACTIVITY_NOTIFICATION_DELAY);
8507 }
8508 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008509
8510 @Override
8511 public boolean canConnectTo5GInDsdsMode() {
8512 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008514}