blob: 38edd88e34d55e650a38c54fce110997b6ff809f [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 Qian8f4750a2020-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 Qian8f4750a2020-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 Qian8f4750a2020-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 Qian8f4750a2020-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);
Jack Yu5f7092c2018-04-13 14:05:37 -07002317 // Todo: fix this when we can get the actual cellular network info when the device
2318 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002319 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002320 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08002321 mApp.getAttributionTag())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002322 return "";
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324 Phone phone = PhoneFactory.getPhone(phoneId);
2325 if (phone != null) {
2326 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002327 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 if (sst != null) {
2329 LocaleTracker lt = sst.getLocaleTracker();
2330 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002331 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2332 return lt.getCurrentCountry();
2333 } else if (emergencyNumberTracker != null) {
2334 return emergencyNumberTracker.getEmergencyCountryIso();
2335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 }
2337 }
2338 }
2339 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002340 } finally {
2341 Binder.restoreCallingIdentity(identity);
2342 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002343 }
2344
2345 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002347 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002348 }
2349
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002351 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 mApp.enforceCallingOrSelfPermission(
2353 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002354
2355 final long identity = Binder.clearCallingIdentity();
2356 try {
2357 final Phone phone = getPhone(subId);
2358 if (phone != null) {
2359 phone.enableLocationUpdates();
2360 }
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
2366 @Override
2367 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002368 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002372 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 mApp.enforceCallingOrSelfPermission(
2374 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
2376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 final Phone phone = getPhone(subId);
2379 if (phone != null) {
2380 phone.disableLocationUpdates();
2381 }
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 }
2386
Nathan Harold31d7ff32018-10-15 20:20:30 -07002387 /**
2388 * Returns the target SDK version number for a given package name.
2389 *
Nathan Haroldec184742019-07-10 17:04:16 -07002390 * This call MUST be invoked before clearing the calling UID.
2391 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002392 * @return target SDK if the package is found or INT_MAX.
2393 */
2394 private int getTargetSdk(String packageName) {
2395 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002396 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002397 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002398 if (ai != null) return ai.targetSdkVersion;
2399 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002400 loge("Failed to get package info for pkg="
2401 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002402 }
2403 return Integer.MAX_VALUE;
2404 }
2405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 @Override
2407 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002408 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2409 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002410 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002411 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2412 throw new SecurityException(
2413 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2414 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002415
Jordan Liu1617b712019-07-10 15:06:26 -07002416 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2418 return null;
2419 }
Svetoslav64fad262015-04-14 14:35:21 -07002420
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002421 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002423 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002424 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425
Nathan Haroldf180aac2018-06-01 18:43:55 -07002426 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2427 for (CellInfo ci : info) {
2428 if (ci instanceof CellInfoGsm) {
2429 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2430 } else if (ci instanceof CellInfoWcdma) {
2431 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002434 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 private List<CellInfo> getCachedCellInfo() {
2438 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2439 for (Phone phone : PhoneFactory.getPhones()) {
2440 List<CellInfo> info = phone.getAllCellInfo();
2441 if (info != null) cellInfos.addAll(info);
2442 }
2443 return cellInfos;
2444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445
2446 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002447 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002448 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002449 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002450
2451 LocationAccessPolicy.LocationPermissionResult locationResult =
2452 LocationAccessPolicy.checkLocationPermission(mApp,
2453 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2454 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002455 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002456 .setCallingPid(Binder.getCallingPid())
2457 .setCallingUid(Binder.getCallingUid())
2458 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002459 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2461 .build());
2462 switch (locationResult) {
2463 case DENIED_HARD:
2464 throw new SecurityException("Not allowed to access cell info");
2465 case DENIED_SOFT:
2466 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002469 final int targetSdk = getTargetSdk(callingPackage);
2470 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2471 return getCachedCellInfo();
2472 }
2473
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002474 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002475 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2479 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002480 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002481 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 if (info != null) cellInfos.addAll(info);
2483 }
2484 return cellInfos;
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488 }
2489
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002490 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002491 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2492 String callingFeatureId) {
2493 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2494 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002495 }
2496
2497 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002498 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2499 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002500 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002501 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002502 }
2503
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002504 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2505 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002506 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002507 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002508
2509 LocationAccessPolicy.LocationPermissionResult locationResult =
2510 LocationAccessPolicy.checkLocationPermission(mApp,
2511 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2512 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002513 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002514 .setCallingPid(Binder.getCallingPid())
2515 .setCallingUid(Binder.getCallingUid())
2516 .setMethod("requestCellInfoUpdate")
2517 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2518 .build());
2519 switch (locationResult) {
2520 case DENIED_HARD:
2521 throw new SecurityException("Not allowed to access cell info");
2522 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002523 try {
2524 cb.onCellInfo(new ArrayList<CellInfo>());
2525 } catch (RemoteException re) {
2526 // Drop without consequences
2527 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002528 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002529 }
2530
Nathan Harolda939a962019-05-09 10:13:47 -07002531
2532 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002533 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2534
2535 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2536 }
2537
2538 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002540 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002541 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002545 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 } finally {
2547 Binder.restoreCallingIdentity(identity);
2548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 }
2550
Shishir Agrawala9f32182016-04-12 12:00:16 -07002551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002552 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002553 Phone phone = PhoneFactory.getPhone(slotIndex);
2554 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 return null;
2556 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002557 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002558 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002559 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 return null;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 return phone.getImei();
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002569 }
2570
2571 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002572 public String getTypeAllocationCodeForSlot(int slotIndex) {
2573 Phone phone = PhoneFactory.getPhone(slotIndex);
2574 String tac = null;
2575 if (phone != null) {
2576 String imei = phone.getImei();
2577 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2578 }
2579 return tac;
2580 }
2581
2582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002583 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002584 Phone phone = PhoneFactory.getPhone(slotIndex);
2585 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002586 return null;
2587 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002588
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002590 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002591 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002592 return null;
2593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 return phone.getMeid();
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
2600 }
Jack Yu2af8d712017-03-15 17:14:14 -07002601 }
2602
2603 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002604 public String getManufacturerCodeForSlot(int slotIndex) {
2605 Phone phone = PhoneFactory.getPhone(slotIndex);
2606 String manufacturerCode = null;
2607 if (phone != null) {
2608 String meid = phone.getMeid();
2609 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2610 }
2611 return manufacturerCode;
2612 }
2613
2614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2616 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002617 Phone phone = PhoneFactory.getPhone(slotIndex);
2618 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 return null;
2620 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002621 int subId = phone.getSubId();
2622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002623 mApp, subId, callingPackage, callingFeatureId,
2624 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002625 return null;
2626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 return phone.getDeviceSvn();
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002634 }
2635
fionaxu43304da2017-11-27 22:51:16 -08002636 @Override
2637 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
fionaxu43304da2017-11-27 22:51:16 -08002645 }
2646
2647 @Override
2648 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
2652 return phone == null ? null : phone.getCarrierName();
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
fionaxu43304da2017-11-27 22:51:16 -08002656 }
2657
calvinpanffe225e2018-11-01 19:43:06 +08002658 @Override
chen xu0026ca62019-03-06 15:28:50 -08002659 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002664 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
2668 }
2669
2670 @Override
chen xu0026ca62019-03-06 15:28:50 -08002671 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002675 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
2679 }
2680
chen xu651eec72018-11-11 19:03:44 -08002681 @Override
chen xu864e11c2018-12-06 22:10:03 -08002682 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2683 if (!isSubscriptionMccMnc) {
2684 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2685 }
chen xu651eec72018-11-11 19:03:44 -08002686 final Phone phone = PhoneFactory.getPhone(slotIndex);
2687 if (phone == null) {
2688 return TelephonyManager.UNKNOWN_CARRIER_ID;
2689 }
2690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
2696 }
2697
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 //
2699 // Internal helper methods.
2700 //
2701
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002702 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2704 *
2705 * @throws SecurityException if the caller does not have the required permission
2706 */
2707 private void enforceModifyPermission() {
2708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2709 }
2710
Shuo Qiancd19c462020-01-16 20:51:11 -08002711 /**
2712 * Make sure the caller is system.
2713 *
2714 * @throws SecurityException if the caller is not system.
2715 */
2716 private void enforceSystemCaller() {
2717 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2718 throw new SecurityException("Caller must be system");
2719 }
2720 }
2721
Shuo Qian3b6ee772019-11-13 17:43:31 -08002722 private void enforceActiveEmergencySessionPermission() {
2723 mApp.enforceCallingOrSelfPermission(
2724 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2725 }
2726
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 /**
2728 * Make sure the caller has the CALL_PHONE permission.
2729 *
2730 * @throws SecurityException if the caller does not have the required permission
2731 */
2732 private void enforceCallPermission() {
2733 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2734 }
2735
paulhu5a773602019-08-23 19:17:33 +08002736 private void enforceSettingsPermission() {
2737 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002738 }
2739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 private String createTelUrl(String number) {
2741 if (TextUtils.isEmpty(number)) {
2742 return null;
2743 }
2744
Jake Hambye994d462014-02-03 13:10:13 -08002745 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
Ihab Awadf9e92732013-12-05 18:02:52 -08002748 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002749 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2750 }
2751
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002752 private static void logv(String msg) {
2753 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2754 }
2755
Ihab Awadf9e92732013-12-05 18:02:52 -08002756 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2758 }
2759
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002762 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002763 }
2764
Sanket Padawe356d7632015-06-22 14:03:32 -07002765 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002766 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = PhoneFactory.getPhone(slotIndex);
2770 if (phone == null) {
2771 return PhoneConstants.PHONE_TYPE_NONE;
2772 } else {
2773 return phone.getPhoneType();
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 /**
2781 * Returns the CDMA ERI icon index to display
2782 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002784 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2785 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2786 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002787 }
2788
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002790 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2791 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002793 mApp, subId, callingPackage, callingFeatureId,
2794 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002795 return -1;
2796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
2802 return phone.getCdmaEriIconIndex();
2803 } else {
2804 return -1;
2805 }
2806 } finally {
2807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 }
2810
2811 /**
2812 * Returns the CDMA ERI icon mode,
2813 * 0 - ON
2814 * 1 - FLASHING
2815 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002816 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002817 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2818 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2819 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002820 }
2821
Sanket Padawe356d7632015-06-22 14:03:32 -07002822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002823 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2824 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002826 mApp, subId, callingPackage, callingFeatureId,
2827 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002828 return -1;
2829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 final Phone phone = getPhone(subId);
2834 if (phone != null) {
2835 return phone.getCdmaEriIconMode();
2836 } else {
2837 return -1;
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
2844 /**
2845 * Returns the CDMA ERI text,
2846 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002848 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2849 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2850 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002851 }
2852
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002854 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2855 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002857 mApp, subId, callingPackage, callingFeatureId,
2858 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002859 return null;
2860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 final Phone phone = getPhone(subId);
2865 if (phone != null) {
2866 return phone.getCdmaEriText();
2867 } else {
2868 return null;
2869 }
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 }
2874
2875 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002876 * Returns the CDMA MDN.
2877 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002879 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2881 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002886 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 return phone.getLine1Number();
2888 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002889 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 return null;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002894 }
2895 }
2896
2897 /**
2898 * Returns the CDMA MIN.
2899 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002901 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2903 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2909 return phone.getCdmaMin();
2910 } else {
2911 return null;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002915 }
2916 }
2917
Hall Liud892bec2018-11-30 14:51:45 -08002918 @Override
2919 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2920 INumberVerificationCallback callback, String callingPackage) {
2921 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2922 != PERMISSION_GRANTED) {
2923 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2924 }
2925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2926
2927 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2928 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2929 throw new SecurityException("Calling package must be configured in the device config");
2930 }
2931
2932 if (range == null) {
2933 throw new NullPointerException("Range must be non-null");
2934 }
2935
2936 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002937 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002938
2939 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2940 }
2941
Junda Liuca05d5d2014-08-14 22:36:34 -07002942 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 * Returns true if CDMA provisioning needs to run.
2944 */
2945 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 final long identity = Binder.clearCallingIdentity();
2947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 } finally {
2950 Binder.restoreCallingIdentity(identity);
2951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002955 * Sets the voice mail number of a given subId.
2956 */
2957 @Override
2958 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002959 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2960 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002961
2962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2965 new Pair<String, String>(alphaTag, number), new Integer(subId));
2966 return success;
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002970 }
2971
Ta-wei Yen87c49842016-05-13 21:19:52 -07002972 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002973 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002975 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2976 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002977 if (!TextUtils.equals(callingPackage, systemDialer)) {
2978 throw new SecurityException("caller must be system dialer");
2979 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2984 if (phoneAccountHandle == null) {
2985 return null;
2986 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002990 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002991 }
2992
2993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002994 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2995 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002998 mApp, subId, callingPackage, callingFeatureId,
2999 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003000 return null;
3001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003003 final long identity = Binder.clearCallingIdentity();
3004 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003005 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003009 }
3010
3011 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003012 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3013 VisualVoicemailSmsFilterSettings settings) {
3014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003019 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003023 }
3024
3025 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003026 public void disableVisualVoicemailSmsFilter(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 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
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 Yenb6929602016-05-24 15:48:27 -07003039 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3040 String callingPackage, int subId) {
3041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003050 }
3051
3052 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003053 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003059 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003063 }
3064
3065 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003066 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3067 String callingAttributionTag, int subId, String number, int port, String text,
3068 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003070 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003071 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003072 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003073 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3074 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003075 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003076
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003077 /**
fionaxu0152e512016-11-14 13:36:14 -08003078 * Sets the voice activation state of a given subId.
3079 */
3080 @Override
3081 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3083 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 final Phone phone = getPhone(subId);
3088 if (phone != null) {
3089 phone.setVoiceActivationState(activationState);
3090 } else {
3091 loge("setVoiceActivationState fails with invalid subId: " + subId);
3092 }
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003095 }
3096 }
3097
3098 /**
3099 * Sets the data activation state of a given subId.
3100 */
3101 @Override
3102 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3104 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 if (phone != null) {
3110 phone.setDataActivationState(activationState);
3111 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003112 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003116 }
3117 }
3118
3119 /**
3120 * Returns the voice activation state of a given subId.
3121 */
3122 @Override
3123 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003125
fionaxu0152e512016-11-14 13:36:14 -08003126 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 if (phone != null) {
3130 return phone.getVoiceActivationState();
3131 } else {
3132 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3133 }
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003136 }
3137 }
3138
3139 /**
3140 * Returns the data activation state of a given subId.
3141 */
3142 @Override
3143 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145
fionaxu0152e512016-11-14 13:36:14 -08003146 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 if (phone != null) {
3150 return phone.getDataActivationState();
3151 } else {
3152 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003156 }
3157 }
3158
3159 /**
Wink Saville36469e72014-06-11 15:17:00 -07003160 * Returns the unread count of voicemails for a subId
3161 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003163 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3164 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003166 mApp, subId, callingPackage, callingFeatureId,
3167 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003168 return 0;
3169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 final Phone phone = getPhone(subId);
3173 if (phone != null) {
3174 return phone.getVoiceMessageCount();
3175 } else {
3176 return 0;
3177 }
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 }
3182
3183 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003184 * returns true, if the device is in a state where both voice and data
3185 * are supported simultaneously. This can change based on location or network condition.
3186 */
3187 @Override
3188 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = getPhone(subId);
3192 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003196 }
3197
3198 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003199 * Send the dialer code if called from the current default dialer or the caller has
3200 * carrier privilege.
3201 * @param inputCode The dialer code to send
3202 */
3203 @Override
3204 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003206 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003207 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3208 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003209 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003210 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003211 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003216 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
fionaxu235cc5e2017-03-06 22:25:57 -08003220 }
3221
Pengquan Menga1bb6272018-09-06 09:59:22 -07003222 @Override
3223 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003224 TelephonyPermissions
3225 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3226 mApp, subId, "getNetworkSelectionMode");
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 if (!isActiveSubscription(subId)) {
3230 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3231 }
3232 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003235 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003236 }
3237
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003239 public boolean isInEmergencySmsMode() {
3240 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 for (Phone phone : PhoneFactory.getPhones()) {
3244 if (phone.isInEmergencySmsMode()) {
3245 return true;
3246 }
3247 }
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
3251 return false;
3252 }
3253
shilu366312e2019-12-17 09:28:10 -08003254 /**
3255 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3256 * @param subId The subscription to use to check the configuration.
3257 * @param c The callback that will be used to send the result.
3258 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003259 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003260 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3261 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003262 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3263 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003264
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003265 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3266 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3267 "IMS not available on device.");
3268 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 final long token = Binder.clearCallingIdentity();
3270 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (ImsException e) {
3275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 } finally {
3277 Binder.restoreCallingIdentity(token);
3278 }
3279 }
3280
shilu366312e2019-12-17 09:28:10 -08003281 /**
3282 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3283 * @param subId The subscription to use to check the configuration.
3284 * @param c The callback that will be used to send the result.
3285 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003287 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003288 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3289 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3291 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3292 }
Meng Wangafbc5852019-09-19 17:37:13 -07003293 final long token = Binder.clearCallingIdentity();
3294 try {
3295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3296 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3297 .removeRegistrationCallbackForSubscription(c, subId);
3298 } catch (ImsException e) {
3299 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3300 + "is inactive, ignoring unregister.");
3301 // If the subscription is no longer active, just return, since the callback
3302 // will already have been removed internally.
3303 } finally {
3304 Binder.restoreCallingIdentity(token);
3305 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 }
3307
Brad Ebingera34a6c22019-10-22 17:36:18 -07003308 /**
3309 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3310 */
3311 @Override
3312 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3313 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3316 "IMS not available on device.");
3317 }
3318 final long token = Binder.clearCallingIdentity();
3319 try {
3320 Phone phone = getPhone(subId);
3321 if (phone == null) {
3322 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3323 + subId + "'");
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3325 }
3326 phone.getImsRegistrationState(regState -> {
3327 try {
3328 consumer.accept((regState == null)
3329 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3330 } catch (RemoteException e) {
3331 // Ignore if the remote process is no longer available to call back.
3332 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3333 }
3334 });
3335 } finally {
3336 Binder.restoreCallingIdentity(token);
3337 }
3338 }
3339
3340 /**
3341 * Get the transport type for the IMS service registration state.
3342 */
3343 @Override
3344 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003345 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3346 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003347 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3348 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3349 "IMS not available on device.");
3350 }
3351 final long token = Binder.clearCallingIdentity();
3352 try {
3353 Phone phone = getPhone(subId);
3354 if (phone == null) {
3355 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3356 + subId + "'");
3357 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3358 }
3359 phone.getImsRegistrationTech(regTech -> {
3360 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3361 int regTechConverted = (regTech == null)
3362 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3363 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3364 regTechConverted);
3365 try {
3366 consumer.accept(regTechConverted);
3367 } catch (RemoteException e) {
3368 // Ignore if the remote process is no longer available to call back.
3369 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3370 }
3371 });
3372 } finally {
3373 Binder.restoreCallingIdentity(token);
3374 }
3375 }
3376
shilu366312e2019-12-17 09:28:10 -08003377 /**
3378 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3379 * @param subId The subscription to use to check the configuration.
3380 * @param c The callback that will be used to send the result.
3381 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003383 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3384 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003385 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3386 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003387 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3388 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3389 "IMS not available on device.");
3390 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3392 final long token = Binder.clearCallingIdentity();
3393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003395 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003396 } catch (ImsException e) {
3397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 } finally {
3399 Binder.restoreCallingIdentity(token);
3400 }
3401 }
3402
shilu366312e2019-12-17 09:28:10 -08003403 /**
3404 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3405 * @param subId The subscription to use to check the configuration.
3406 * @param c The callback that will be used to send the result.
3407 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003408 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003409 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003410 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3411 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003412 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3413 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3414 }
Meng Wangafbc5852019-09-19 17:37:13 -07003415
3416 final long token = Binder.clearCallingIdentity();
3417 try {
3418 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3419 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003420 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003421 } catch (ImsException e) {
3422 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3423 + "is inactive, ignoring unregister.");
3424 // If the subscription is no longer active, just return, since the callback
3425 // will already have been removed internally.
3426 } finally {
3427 Binder.restoreCallingIdentity(token);
3428 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 }
3430
3431 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003432 public boolean isCapable(int subId, int capability, int regTech) {
3433 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3435 final long token = Binder.clearCallingIdentity();
3436 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003437 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003438 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003439 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3441 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003443 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3444 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 } finally {
3446 Binder.restoreCallingIdentity(token);
3447 }
3448 }
3449
3450 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003451 public boolean isAvailable(int subId, int capability, int regTech) {
3452 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 final long token = Binder.clearCallingIdentity();
3454 try {
3455 Phone phone = getPhone(subId);
3456 if (phone == null) return false;
3457 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003458 } catch (com.android.ims.ImsException e) {
3459 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3460 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 } finally {
3462 Binder.restoreCallingIdentity(token);
3463 }
3464 }
3465
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003466 /**
3467 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3468 * subscription.
3469 * @param subId The subscription to use to check the configuration.
3470 * @param callback The callback that will be used to send the result.
3471 * @param capability The MmTelFeature capability that will be used to send the result.
3472 * @param transportType The transport type of the MmTelFeature capability.
3473 */
3474 @Override
3475 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3476 int transportType) {
3477 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3478 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3479 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3480 "IMS not available on device.");
3481 }
3482 final long token = Binder.clearCallingIdentity();
3483 try {
3484 int slotId = getSlotIndex(subId);
3485 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3486 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3487 + subId + "'");
3488 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3489 }
3490 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3491 transportType, aBoolean -> {
3492 try {
3493 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3494 } catch (RemoteException e) {
3495 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3496 + "running. Ignore");
3497 }
3498 });
3499 } finally {
3500 Binder.restoreCallingIdentity(token);
3501 }
3502 }
3503
shilu366312e2019-12-17 09:28:10 -08003504 /**
3505 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3506 * @param subId The subscription to use to check the configuration.
3507 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003508 @Override
3509 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003510 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3511 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003512
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3514 final long token = Binder.clearCallingIdentity();
3515 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003516 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003518 } catch (ImsException e) {
3519 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 } finally {
3521 Binder.restoreCallingIdentity(token);
3522 }
3523 }
3524
3525 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003526 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003528 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003532 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003534 } catch (ImsException e) {
3535 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
3539 }
3540
shilu366312e2019-12-17 09:28:10 -08003541 /**
3542 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3543 * @param subId The subscription to use to check the configuration.
3544 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003546 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003547 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3548 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3553 } catch (ImsException e) {
3554 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
3559
3560 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003561 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003563 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003567 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003568 } catch (ImsException e) {
3569 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 } finally {
3571 Binder.restoreCallingIdentity(identity);
3572 }
3573 }
3574
shilu366312e2019-12-17 09:28:10 -08003575 /**
3576 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3577 * @param subId The subscription to use to check the configuration.
3578 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 @Override
3580 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003581 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3582 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003586 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003588 } catch (ImsException e) {
3589 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 } finally {
3591 Binder.restoreCallingIdentity(identity);
3592 }
3593 }
3594
3595 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003596 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003598 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003602 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003603 } catch (ImsException e) {
3604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
3609
shilu366312e2019-12-17 09:28:10 -08003610 /**
3611 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3612 * @param subId The subscription to use to check the configuration.
3613 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 @Override
3615 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003616 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3617 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003623 } catch (ImsException e) {
3624 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629
3630 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003631 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003633 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003639 } catch (ImsException e) {
3640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 }
3645
3646 @Override
3647 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3649 "setVoWiFiNonPersistent");
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003654 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003655 } catch (ImsException e) {
3656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
3660 }
3661
shilu366312e2019-12-17 09:28:10 -08003662 /**
3663 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3664 * @param subId The subscription to use to check the configuration.
3665 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 @Override
3667 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003668 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3669 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003673 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003675 } catch (ImsException e) {
3676 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
3680 }
3681
3682 @Override
3683 public void setVoWiFiModeSetting(int subId, int mode) {
3684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3685 "setVoWiFiModeSetting");
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003689 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003691 } catch (ImsException e) {
3692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
3696 }
3697
3698 @Override
3699 public int getVoWiFiRoamingModeSetting(int subId) {
3700 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003706 } catch (ImsException e) {
3707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
3713 @Override
3714 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3716 "setVoWiFiRoamingModeSetting");
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003720 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 } catch (ImsException e) {
3723 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 }
3728
3729 @Override
3730 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3732 "setRttCapabilityEnabled");
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003736 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3737 } catch (ImsException e) {
3738 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
3742 }
3743
shilu366312e2019-12-17 09:28:10 -08003744 /**
3745 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3746 * @param subId The subscription to use to check the configuration.
3747 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 @Override
3749 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003750 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3751 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003757 } catch (ImsException e) {
3758 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 } finally {
3760 Binder.restoreCallingIdentity(identity);
3761 }
3762 }
3763
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003764 @Override
3765 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3766 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3767 final long identity = Binder.clearCallingIdentity();
3768 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003769 if (!isImsAvailableOnDevice()) {
3770 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3771 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003772 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003775 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003776 } catch (ImsException e) {
3777 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 } finally {
3779 Binder.restoreCallingIdentity(identity);
3780 }
3781 }
3782
3783 @Override
3784 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3785 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3786 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3788 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3789 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003790 try {
3791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003792 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003793 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003795 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3796 + "is inactive, ignoring unregister.");
3797 // If the subscription is no longer active, just return, since the callback will already
3798 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003799 } finally {
3800 Binder.restoreCallingIdentity(identity);
3801 }
3802 }
3803
allenwtsu99c623b2020-01-03 18:24:23 +08003804
3805 private void checkModifyPhoneStatePermission(int subId, String message) {
3806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3807 message);
3808 }
3809
3810 private boolean isImsProvisioningRequired(int subId, int capability,
3811 boolean isMmtelCapability) {
3812 Phone phone = getPhone(subId);
3813 if (phone == null) {
3814 loge("phone instance null for subid " + subId);
3815 return false;
3816 }
3817 if (isMmtelCapability) {
3818 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3819 return false;
3820 }
3821 } else {
3822 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3823 return false;
3824 }
3825 }
3826 return true;
3827 }
3828
3829 @Override
3830 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3831 boolean isProvisioned) {
3832 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3833
3834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3837 if (!isImsProvisioningRequired(subId, capability, false)) {
3838 return;
3839 }
3840
3841 // this capability requires provisioning, route to the correct API.
3842 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3843 switch (capability) {
3844 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3845 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3846 ims.setEabProvisioned(isProvisioned);
3847 break;
3848 default: {
3849 throw new IllegalArgumentException("Tried to set provisioning for "
3850 + "rcs capability '" + capability + "', which does not require "
3851 + "provisioning.");
3852 }
3853 }
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857
3858 }
3859
3860
3861 @Override
3862 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3863 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3867 if (!isImsProvisioningRequired(subId, capability, false)) {
3868 return true;
3869 }
3870
3871 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3872 switch (capability) {
3873 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3874 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3875 return ims.isEabProvisionedOnDevice();
3876
3877 default: {
3878 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3879 + "capability '" + capability + "', which does not require "
3880 + "provisioning.");
3881 }
3882 }
3883
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
3887 }
3888
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003889 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003890 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3891 boolean isProvisioned) {
3892 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3893 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3894 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3895 }
allenwtsu99c623b2020-01-03 18:24:23 +08003896 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003900 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003901 return;
3902 }
3903
3904 // this capability requires provisioning, route to the correct API.
3905 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3906 switch (capability) {
3907 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3908 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3909 ims.setVolteProvisioned(isProvisioned);
3910 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3911 ims.setWfcProvisioned(isProvisioned);
3912 }
3913 break;
3914 }
3915 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3916 // There is currently no difference in VT provisioning type.
3917 ims.setVtProvisioned(isProvisioned);
3918 break;
3919 }
3920 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3921 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3922 // change the capability of the feature instead if needed.
3923 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3924 == isProvisioned) {
3925 // No change in provisioning.
3926 return;
3927 }
3928 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3929 try {
3930 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003931 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003932 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3933 + ", Exception" + e.getMessage());
3934 }
3935 break;
3936 }
3937 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003938 throw new IllegalArgumentException("Tried to set provisioning for "
3939 + "MmTel capability '" + capability + "', which does not require "
3940 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003941 }
3942 }
3943
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 }
3948
3949 @Override
3950 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3951 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3952 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3953 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3954 }
3955 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003959 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 return true;
3961 }
3962
3963 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3964 switch (capability) {
3965 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3966 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3967 return ims.isVolteProvisionedOnDevice();
3968 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3969 return ims.isWfcProvisionedOnDevice();
3970 }
3971 // This should never happen, since we are checking tech above to make sure it
3972 // is either LTE or IWLAN.
3973 throw new IllegalArgumentException("Invalid radio technology for voice "
3974 + "capability.");
3975 }
3976 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3977 // There is currently no difference in VT provisioning type.
3978 return ims.isVtProvisionedOnDevice();
3979 }
3980 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3981 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3982 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3983 }
3984 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003985 throw new IllegalArgumentException(
3986 "Tried to get provisioning for MmTel capability '" + capability
3987 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003988 }
3989 }
3990
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
3994 }
3995
3996 @Override
3997 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3998 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3999 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4000 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4001 }
4002 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4003 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4004 return (provisionedBits & capability) > 0;
4005 }
4006
4007 @Override
4008 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4009 boolean isProvisioned) {
4010 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4011 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4012 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4013 }
4014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4015 "setProvisioningStatusForCapability");
4016 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4017 // If the current provisioning status for capability already matches isProvisioned,
4018 // do nothing.
4019 if (((provisionedBits & capability) > 0) == isProvisioned) {
4020 return;
4021 }
4022 if (isProvisioned) {
4023 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4024 } else {
4025 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4026 }
4027 }
4028
4029 /**
4030 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4031 * technology. The bitfield should mirror the bitfield defined by
4032 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4033 */
4034 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4035 String key = getMmTelProvisioningKey(subId, tech);
4036 // Default is no capabilities are provisioned.
4037 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4038 }
4039
4040 /**
4041 * Sets the MmTel capability provisioning bitfield (defined by
4042 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4043 * technology specified.
4044 *
4045 * Note: This is a synchronous command and should not be called on UI thread.
4046 */
4047 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4048 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4049 String key = getMmTelProvisioningKey(subId, tech);
4050 editor.putInt(key, newField);
4051 editor.commit();
4052 }
4053
4054 private static String getMmTelProvisioningKey(int subId, int tech) {
4055 // resulting key is provision_ims_mmtel_{subId}_{tech}
4056 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4057 }
4058
4059 /**
4060 * Query CarrierConfig to see if the specified capability requires provisioning for the
4061 * carrier associated with the subscription id.
4062 */
4063 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4064 int capability) {
4065 CarrierConfigManager configManager = new CarrierConfigManager(context);
4066 PersistableBundle c = configManager.getConfigForSubId(subId);
4067 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004068 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004069 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4070 false);
4071 boolean requireVoiceVtProvisioning = c.getBoolean(
4072 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4073
4074 // First check to make sure that the capability requires provisioning.
4075 switch (capability) {
4076 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4077 // intentional fallthrough
4078 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4079 if (requireVoiceVtProvisioning) {
4080 // Voice and Video requires provisioning
4081 return true;
4082 }
4083 break;
4084 }
4085 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4086 if (requireUtProvisioning) {
4087 // UT requires provisioning
4088 return true;
4089 }
4090 break;
4091 }
4092 }
4093 return false;
4094 }
4095
allenwtsu99c623b2020-01-03 18:24:23 +08004096 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4097 int capability) {
4098 CarrierConfigManager configManager = new CarrierConfigManager(context);
4099 PersistableBundle c = configManager.getConfigForSubId(subId);
4100
4101 boolean requireRcsProvisioning = c.getBoolean(
4102 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4103
4104 // First check to make sure that the capability requires provisioning.
4105 switch (capability) {
4106 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4107 // intentional fallthrough
4108 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4109 if (requireRcsProvisioning) {
4110 // OPTION or PRESENCE requires provisioning
4111 return true;
4112 }
4113 break;
4114 }
4115 }
4116 return false;
4117 }
4118
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004120 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4122 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4123 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004124 enforceReadPrivilegedPermission("getImsProvisioningInt");
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004128 int slotId = getSlotIndex(subId);
4129 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4130 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4131 + subId + "' for key:" + key);
4132 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4133 }
4134 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004136 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4137 + subId + "' for key:" + key);
4138 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
4142 }
4143
4144 @Override
4145 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4147 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4148 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004149 enforceReadPrivilegedPermission("getImsProvisioningString");
4150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004153 int slotId = getSlotIndex(subId);
4154 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4155 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4156 + subId + "' for key:" + key);
4157 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4158 }
4159 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004160 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004161 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4162 + subId + "' for key:" + key);
4163 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
4169 @Override
4170 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004171 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4172 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4173 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4175 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004179 int slotId = getSlotIndex(subId);
4180 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4181 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4182 + subId + "' for key:" + key);
4183 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4184 }
4185 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004187 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4188 + "' for key:" + key);
4189 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
4193 }
4194
4195 @Override
4196 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004197 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4198 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4199 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4201 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004202 final long identity = Binder.clearCallingIdentity();
4203 try {
4204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004205 int slotId = getSlotIndex(subId);
4206 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4207 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4208 + subId + "' for key:" + key);
4209 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4210 }
4211 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004213 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4214 + "' for key:" + key);
4215 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004216 } finally {
4217 Binder.restoreCallingIdentity(identity);
4218 }
4219 }
4220
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004221 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 int slotId = SubscriptionManager.getSlotIndex(subId);
4223 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004224 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4225 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 }
4227 return slotId;
4228 }
4229
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004230 private int getSlotIndex(int subId) {
4231 int slotId = SubscriptionManager.getSlotIndex(subId);
4232 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4233 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4234 }
4235 return slotId;
4236 }
4237
Wink Saville36469e72014-06-11 15:17:00 -07004238 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004239 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004240 */
4241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004242 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4243 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004244 final int targetSdk = getTargetSdk(callingPackage);
4245 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004246 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004247 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004248 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004249 mApp, subId, callingPackage, callingFeatureId,
4250 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4252 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 final Phone phone = getPhone(subId);
4257 if (phone != null) {
4258 return phone.getServiceState().getDataNetworkType();
4259 } else {
4260 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4261 }
4262 } finally {
4263 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004265 }
4266
4267 /**
4268 * Returns the data network type
4269 */
4270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004271 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4272 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4273 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004274 }
4275
4276 /**
4277 * Returns the data network type for a subId
4278 */
4279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004280 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4281 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004283 mApp, subId, callingPackage, callingFeatureId,
4284 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4286 }
4287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 final Phone phone = getPhone(subId);
4291 if (phone != null) {
4292 return phone.getServiceState().getDataNetworkType();
4293 } else {
4294 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4295 }
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004299 }
4300
4301 /**
Wink Saville36469e72014-06-11 15:17:00 -07004302 * Returns the Voice network type for a subId
4303 */
4304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004305 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4306 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004308 mApp, subId, callingPackage, callingFeatureId,
4309 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4311 }
4312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 final Phone phone = getPhone(subId);
4316 if (phone != null) {
4317 return phone.getServiceState().getVoiceNetworkType();
4318 } else {
4319 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4320 }
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004324 }
4325
4326 /**
4327 * @return true if a ICC card is present
4328 */
4329 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004330 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004331 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4332 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004333 }
4334
4335 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004336 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004337 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004338 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004339 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340 final long identity = Binder.clearCallingIdentity();
4341 try {
4342 final Phone phone = PhoneFactory.getPhone(slotIndex);
4343 if (phone != null) {
4344 return phone.getIccCard().hasIccCard();
4345 } else {
4346 return false;
4347 }
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004351 }
4352
4353 /**
4354 * Return if the current radio is LTE on CDMA. This
4355 * is a tri-state return value as for a period of time
4356 * the mode may be unknown.
4357 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004358 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004359 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004360 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004361 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004363 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4364 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4365 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004366 }
4367
Sanket Padawe356d7632015-06-22 14:03:32 -07004368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004369 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4370 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004371 try {
4372 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4373 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004374 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4375 }
4376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 final Phone phone = getPhone(subId);
4380 if (phone == null) {
4381 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4382 } else {
4383 return phone.getLteOnCdmaMode();
4384 }
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004387 }
Wink Saville36469e72014-06-11 15:17:00 -07004388 }
4389
Wink Saville36469e72014-06-11 15:17:00 -07004390 /**
4391 * {@hide}
4392 * Returns Default subId, 0 in the case of single standby.
4393 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004394 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004395 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004396 }
4397
Shishir Agrawala9f32182016-04-12 12:00:16 -07004398 private int getSlotForDefaultSubscription() {
4399 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4400 }
4401
Wink Savilleb564aae2014-10-23 10:18:09 -07004402 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004403 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004404 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004405
Pengquan Menge92a50d2018-09-21 15:54:48 -07004406 private boolean isActiveSubscription(int subId) {
4407 return mSubscriptionController.isActiveSubId(subId);
4408 }
4409
Ihab Awadf2177b72013-11-25 13:33:23 -08004410 /**
4411 * @see android.telephony.TelephonyManager.WifiCallingChoices
4412 */
4413 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004416 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4418 getWhenToMakeWifiCallsDefaultPreference());
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004422 }
4423
4424 /**
4425 * @see android.telephony.TelephonyManager.WifiCallingChoices
4426 */
4427 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004431 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004436 }
4437
Sailesh Nepald1e68152013-12-12 19:08:02 -08004438 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004439 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004440 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004441 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004442
Jordan Liu4c733742019-02-28 12:03:40 -08004443 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4444 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4445 if (phoneId == -1) {
4446 throw new IllegalArgumentException("Given slot index: " + slotIndex
4447 + " does not correspond to an active phone");
4448 }
4449 return PhoneFactory.getPhone(phoneId);
4450 }
4451
Shishir Agrawal566b7612013-10-28 14:41:00 -07004452 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004453 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4454 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4456 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004458 if (DBG) {
4459 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4460 }
4461 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4462 p2);
4463 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004464
Jordan Liu4c733742019-02-28 12:03:40 -08004465
4466 @Override
4467 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4468 int slotIndex, String callingPackage, String aid, int p2) {
4469 enforceModifyPermission();
4470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4471 if (DBG) {
4472 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4473 }
4474 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4475 callingPackage, aid, p2);
4476 }
4477
4478 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4479 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 if (TextUtils.equals(ISDR_AID, aid)) {
4483 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004484 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4485 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 if (bestComponent == null
4487 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4488 loge("The calling package is not allowed to access ISD-R.");
4489 throw new SecurityException(
4490 "The calling package is not allowed to access ISD-R.");
4491 }
Derek Tan740e1672017-06-27 14:56:27 -07004492 }
Derek Tan740e1672017-06-27 14:56:27 -07004493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004495 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4496 null /* workSource */);
4497 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 return response;
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004502 }
4503
4504 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004505 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4507 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004508 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4509 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4510 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004511
Jordan Liu4c733742019-02-28 12:03:40 -08004512 @Override
4513 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4514 enforceModifyPermission();
4515 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4516 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4517 channel);
4518 }
4519
4520 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 final long identity = Binder.clearCallingIdentity();
4522 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 if (channel < 0) {
4524 return false;
4525 }
Jordan Liu4c733742019-02-28 12:03:40 -08004526 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4527 null /* workSource */);
4528 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 return success;
4530 } finally {
4531 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004532 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004533 }
4534
4535 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004536 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004537 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4539 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004540 if (DBG) {
4541 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4542 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4543 + p3 + " data=" + data);
4544 }
4545 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4546 command, p1, p2, p3, data);
4547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004548
Jordan Liu4c733742019-02-28 12:03:40 -08004549 @Override
4550 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4551 int command, int p1, int p2, int p3, String data) {
4552 enforceModifyPermission();
4553 if (DBG) {
4554 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4555 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4556 + p3 + " data=" + data);
4557 }
4558 return iccTransmitApduLogicalChannelWithPermission(
4559 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4560 data);
4561 }
4562
4563 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4564 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 final long identity = Binder.clearCallingIdentity();
4566 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004567 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 return "";
4569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004572 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4573 null /* workSource */);
4574 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 // Append the returned status code to the end of the response payload.
4577 String s = Integer.toHexString(
4578 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4579 if (response.payload != null) {
4580 s = IccUtils.bytesToHexString(response.payload) + s;
4581 }
4582 return s;
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004585 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004586 }
Jake Hambye994d462014-02-03 13:10:13 -08004587
Evan Charltonc66da362014-05-16 14:06:40 -07004588 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004589 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4590 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4592 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004594 if (DBG) {
4595 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4596 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4597 }
4598 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4599 cla, command, p1, p2, p3, data);
4600 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004601
Jordan Liu4c733742019-02-28 12:03:40 -08004602 @Override
4603 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4604 int command, int p1, int p2, int p3, String data) {
4605 enforceModifyPermission();
4606 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4607 if (DBG) {
4608 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4609 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4610 + " data=" + data);
4611 }
4612
4613 return iccTransmitApduBasicChannelWithPermission(
4614 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4615 p2, p3, data);
4616 }
4617
4618 // open APDU basic channel assuming the caller has sufficient permissions
4619 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4620 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
4622 try {
4623 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4624 && TextUtils.equals(ISDR_AID, data)) {
4625 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004626 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4627 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 if (bestComponent == null
4629 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4630 loge("The calling package is not allowed to select ISD-R.");
4631 throw new SecurityException(
4632 "The calling package is not allowed to select ISD-R.");
4633 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004634 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004637 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4638 null /* workSource */);
4639 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 // Append the returned status code to the end of the response payload.
4642 String s = Integer.toHexString(
4643 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4644 if (response.payload != null) {
4645 s = IccUtils.bytesToHexString(response.payload) + s;
4646 }
4647 return s;
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004650 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004651 }
4652
4653 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004654 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004655 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4657 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 final long identity = Binder.clearCallingIdentity();
4660 try {
4661 if (DBG) {
4662 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4663 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4664 }
4665
4666 IccIoResult response =
4667 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4668 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4669 subId);
4670
4671 if (DBG) {
4672 log("Exchange SIM_IO [R]" + response);
4673 }
4674
4675 byte[] result = null;
4676 int length = 2;
4677 if (response.payload != null) {
4678 length = 2 + response.payload.length;
4679 result = new byte[length];
4680 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4681 } else {
4682 result = new byte[length];
4683 }
4684
4685 result[length - 1] = (byte) response.sw2;
4686 result[length - 2] = (byte) response.sw1;
4687 return result;
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004690 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004691 }
4692
Nathan Haroldb3014052017-01-25 15:57:32 -08004693 /**
4694 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4695 * on a particular subscription
4696 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004697 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4698 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004700 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004701 return null;
4702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 if (appType != TelephonyManager.APPTYPE_USIM
4707 && appType != TelephonyManager.APPTYPE_SIM) {
4708 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4709 return null;
4710 }
4711 Object response = sendRequest(
4712 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4713 if (response instanceof String[]) {
4714 return (String[]) response;
4715 }
yincheng zhao2737e882019-09-06 17:06:54 -07004716 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004718 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 } finally {
4720 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004721 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004722 }
4723
yincheng zhao2737e882019-09-06 17:06:54 -07004724 /**
4725 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4726 * subscription.
4727 *
4728 * @param subId the id of the subscription.
4729 * @param appType the uicc app type, must be USIM or SIM.
4730 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4731 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004732 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004733 * @return number of fplmns that is successfully written to the SIM.
4734 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004735 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4736 String callingFeatureId) {
4737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4738 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004739 if (DBG) logv("no permissions for setForbiddenplmns");
4740 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4741 }
4742 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4743 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4744 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4745 }
4746 if (fplmns == null) {
4747 throw new IllegalArgumentException("Fplmn List provided is null");
4748 }
4749 for (String fplmn : fplmns) {
4750 if (!CellIdentity.isValidPlmn(fplmn)) {
4751 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4752 }
4753 }
4754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 Object response = sendRequest(
4757 CMD_SET_FORBIDDEN_PLMNS,
4758 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4759 subId);
4760 return (int) response;
4761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
4764 }
4765
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004766 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004767 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4769 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 final long identity = Binder.clearCallingIdentity();
4772 try {
4773 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4774 if (response.payload == null) {
4775 return "";
4776 }
Evan Charltonc66da362014-05-16 14:06:40 -07004777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 // Append the returned status code to the end of the response payload.
4779 String s = Integer.toHexString(
4780 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4781 s = IccUtils.bytesToHexString(response.payload) + s;
4782 return s;
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
Evan Charltonc66da362014-05-16 14:06:40 -07004786 }
4787
Jake Hambye994d462014-02-03 13:10:13 -08004788 /**
4789 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4790 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4791 *
4792 * @param itemID the ID of the item to read
4793 * @return the NV item as a String, or null on error.
4794 */
4795 @Override
4796 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4799 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800
4801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004804 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4806 return value;
4807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
Jake Hambye994d462014-02-03 13:10:13 -08004810 }
4811
4812 /**
4813 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4814 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4815 *
4816 * @param itemID the ID of the item to read
4817 * @param itemValue the value to write, as a String
4818 * @return true on success; false on any failure
4819 */
4820 @Override
4821 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004822 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4824 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825
4826 final long identity = Binder.clearCallingIdentity();
4827 try {
4828 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4829 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004830 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4832 return success;
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
Jake Hambye994d462014-02-03 13:10:13 -08004836 }
4837
4838 /**
4839 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4840 * Used for device configuration by some CDMA operators.
4841 *
4842 * @param preferredRoamingList byte array containing the new PRL
4843 * @return true on success; false on any failure
4844 */
4845 @Override
4846 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4848 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4853 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4854 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4855 return success;
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
Jake Hambye994d462014-02-03 13:10:13 -08004859 }
4860
4861 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004862 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004863 * Used for device configuration by some CDMA operators.
4864 *
chen xu6dac5ab2018-10-26 17:39:23 -07004865 * @param slotIndex - device slot.
4866 *
Jake Hambye994d462014-02-03 13:10:13 -08004867 * @return true on success; false on any failure
4868 */
4869 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004870 public boolean resetModemConfig(int slotIndex) {
4871 Phone phone = PhoneFactory.getPhone(slotIndex);
4872 if (phone != null) {
4873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4874 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875
chen xu6dac5ab2018-10-26 17:39:23 -07004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4879 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4880 return success;
4881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 }
chen xu6dac5ab2018-10-26 17:39:23 -07004885 return false;
4886 }
4887
4888 /**
4889 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4890 *
4891 * @param slotIndex - device slot.
4892 *
4893 * @return true on success; false on any failure
4894 */
4895 @Override
4896 public boolean rebootModem(int slotIndex) {
4897 Phone phone = PhoneFactory.getPhone(slotIndex);
4898 if (phone != null) {
4899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4900 mApp, phone.getSubId(), "rebootModem");
4901
4902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4905 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4906 return success;
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004912 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004913
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004914 public String[] getPcscfAddress(String apnType, String callingPackage,
4915 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004916 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4918 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004919 return new String[0];
4920 }
4921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004924 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
Wink Saville36469e72014-06-11 15:17:00 -07004928 }
4929
Brad Ebinger51f743a2017-01-23 13:50:20 -08004930 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004931 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4932 * {@link #disableIms(int)}.
4933 * @param slotIndex device slot.
4934 */
4935 public void resetIms(int slotIndex) {
4936 enforceModifyPermission();
4937
4938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 if (mImsResolver == null) {
4941 // may happen if the does not support IMS.
4942 return;
4943 }
4944 mImsResolver.disableIms(slotIndex);
4945 mImsResolver.enableIms(slotIndex);
4946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
4951 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004952 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4953 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004954 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004955 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004956 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957
4958 final long identity = Binder.clearCallingIdentity();
4959 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004960 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004961 // may happen if the device does not support IMS.
4962 return;
4963 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004964 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 } finally {
4966 Binder.restoreCallingIdentity(identity);
4967 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004968 }
4969
4970 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004971 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4972 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004973 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004974 public void disableIms(int slotId) {
4975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976
4977 final long identity = Binder.clearCallingIdentity();
4978 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004979 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004980 // may happen if the device does not support IMS.
4981 return;
4982 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004983 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 } finally {
4985 Binder.restoreCallingIdentity(identity);
4986 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004987 }
4988
4989 /**
4990 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4991 * feature or {@link null} if the service is not available. If the feature is available, the
4992 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4993 */
4994 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004995 IImsServiceFeatureCallback callback) {
4996 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997
4998 final long identity = Binder.clearCallingIdentity();
4999 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005000 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005001 // may happen if the device does not support IMS.
5002 return null;
5003 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005004 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 } finally {
5006 Binder.restoreCallingIdentity(identity);
5007 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005008 }
5009
5010 /**
5011 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5012 * feature during emergency calling or {@link null} if the service is not available. If the
5013 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5014 * listener for feature updates.
5015 */
5016 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018
5019 final long identity = Binder.clearCallingIdentity();
5020 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005021 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005022 // may happen if the device does not support IMS.
5023 return null;
5024 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005025 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 } finally {
5027 Binder.restoreCallingIdentity(identity);
5028 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005029 }
5030
Brad Ebinger5f64b052017-12-14 14:26:15 -08005031 /**
5032 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005033 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005034 */
5035 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037
5038 final long identity = Binder.clearCallingIdentity();
5039 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005040 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005041 // may happen if the device does not support IMS.
5042 return null;
5043 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005044 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005048 }
5049
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005050 /**
5051 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005052 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005053 */
5054 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5055 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056
5057 final long identity = Binder.clearCallingIdentity();
5058 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005059 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005060 // may happen if the device does not support IMS.
5061 return null;
5062 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005063 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005067 }
5068
Brad Ebinger884c07b2018-02-15 16:17:40 -08005069 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005070 * Sets the ImsService Package Name that Telephony will bind to.
5071 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005072 * @param slotIndex the slot ID that the ImsService should bind for.
5073 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005074 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005075 * @param featureTypes An integer array of feature types associated with a packageName.
5076 * @param packageName The name of the package that the current configuration will be replaced
5077 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005078 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005079 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005080 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5081 int[] featureTypes, String packageName) {
5082 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5085 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005086 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 final long identity = Binder.clearCallingIdentity();
5089 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005090 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005091 // may happen if the device does not support IMS.
5092 return false;
5093 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005094 Map<Integer, String> featureConfig = new HashMap<>();
5095 for (int featureType : featureTypes) {
5096 featureConfig.put(featureType, packageName);
5097 }
5098 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5099 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005103 }
5104
5105 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005106 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005107 *
5108 * @param slotId The slot that the ImsService is associated with.
5109 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5110 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005111 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005112 * @return the package name of the ImsService configuration.
5113 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005114 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5115 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005116 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005117 TelephonyPermissions
5118 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5119 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5120 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 final long identity = Binder.clearCallingIdentity();
5123 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005124 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005125 // may happen if the device does not support IMS.
5126 return "";
5127 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005128 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005129 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5130 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 } finally {
5132 Binder.restoreCallingIdentity(identity);
5133 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005134 }
5135
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005136 /**
5137 * Get the MmTelFeature state associated with the requested subscription id.
5138 * @param subId The subscription that the MmTelFeature is associated with.
5139 * @param callback A callback with an integer containing the
5140 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5141 */
5142 @Override
5143 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5144 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5145 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5146 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5147 "IMS not available on device.");
5148 }
5149 final long token = Binder.clearCallingIdentity();
5150 try {
5151 int slotId = getSlotIndex(subId);
5152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5153 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5154 + subId + "'");
5155 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5156 }
5157 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5158 try {
5159 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5160 } catch (RemoteException e) {
5161 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5162 + "Ignore");
5163 }
5164 });
5165 } finally {
5166 Binder.restoreCallingIdentity(token);
5167 }
5168 }
5169
Wink Saville36469e72014-06-11 15:17:00 -07005170 public void setImsRegistrationState(boolean registered) {
5171 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172
5173 final long identity = Binder.clearCallingIdentity();
5174 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
Wink Saville36469e72014-06-11 15:17:00 -07005179 }
5180
5181 /**
Stuart Scott54788802015-03-30 13:18:01 -07005182 * Set the network selection mode to automatic.
5183 *
5184 */
5185 @Override
5186 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5188 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189
5190 final long identity = Binder.clearCallingIdentity();
5191 try {
shilufc958392020-01-20 11:36:01 -08005192 if (!isActiveSubscription(subId)) {
5193 return;
5194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5196 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
Stuart Scott54788802015-03-30 13:18:01 -07005200 }
5201
Pengquan Mengea84e042018-09-20 14:57:26 -07005202 /**
5203 * Ask the radio to connect to the input network and change selection mode to manual.
5204 *
5205 * @param subId the id of the subscription.
5206 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5207 * the operator to attach to.
5208 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5209 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5210 * normal network selection next time.
5211 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005212 */
5213 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005214 public boolean setNetworkSelectionModeManual(
5215 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5217 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005218
5219 if (!isActiveSubscription(subId)) {
5220 return false;
5221 }
5222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005225 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005227 if (DBG) {
5228 log("setNetworkSelectionModeManual: subId: " + subId
5229 + " operator: " + operatorInfo);
5230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005235 }
shilu84f6e8b2019-12-19 13:58:01 -08005236 /**
5237 * Get the manual network selection
5238 *
5239 * @param subId the id of the subscription.
5240 *
5241 * @return the previously saved user selected PLMN
5242 */
5243 @Override
5244 public String getManualNetworkSelectionPlmn(int subId) {
5245 TelephonyPermissions
5246 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5247 mApp, subId, "getManualNetworkSelectionPlmn");
5248
5249 final long identity = Binder.clearCallingIdentity();
5250 try {
5251 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005252 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005253 }
5254
5255 final Phone phone = getPhone(subId);
5256 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005257 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005258 }
5259 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5260 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5261 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
5265 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005266
5267 /**
5268 * Scans for available networks.
5269 */
5270 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005271 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5272 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5274 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005275 LocationAccessPolicy.LocationPermissionResult locationResult =
5276 LocationAccessPolicy.checkLocationPermission(mApp,
5277 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5278 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005279 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005280 .setCallingPid(Binder.getCallingPid())
5281 .setCallingUid(Binder.getCallingUid())
5282 .setMethod("getCellNetworkScanResults")
5283 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5284 .build());
5285 switch (locationResult) {
5286 case DENIED_HARD:
5287 throw new SecurityException("Not allowed to access scan results -- location");
5288 case DENIED_SOFT:
5289 return null;
5290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291
Pengquan Menga1bb6272018-09-06 09:59:22 -07005292 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 try {
5294 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005295 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 } finally {
5298 Binder.restoreCallingIdentity(identity);
5299 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005300 }
5301
5302 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005303 * Get the call forwarding info, given the call forwarding reason.
5304 */
5305 @Override
5306 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5307 enforceReadPrivilegedPermission("getCallForwarding");
5308 long identity = Binder.clearCallingIdentity();
5309 try {
5310 if (DBG) {
5311 log("getCallForwarding: subId " + subId
5312 + " callForwardingReason" + callForwardingReason);
5313 }
5314 return (CallForwardingInfo) sendRequest(
5315 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 /**
5322 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5323 * reason, the number to forward, and the timeout before the forwarding is attempted.
5324 */
5325 @Override
5326 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5327 enforceModifyPermission();
5328 long identity = Binder.clearCallingIdentity();
5329 try {
5330 if (DBG) {
5331 log("setCallForwarding: subId " + subId
5332 + " callForwardingInfo" + callForwardingInfo);
5333 }
5334 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
5338 }
5339
5340 /**
5341 * Get the call forwarding info, given the call forwarding reason.
5342 */
5343 @Override
5344 public int getCallWaitingStatus(int subId) {
5345 enforceReadPrivilegedPermission("getCallForwarding");
5346 long identity = Binder.clearCallingIdentity();
5347 try {
5348 if (DBG) log("getCallWaitingStatus: subId " + subId);
5349 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
5353 }
5354
5355 /**
5356 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5357 * reason, the number to forward, and the timeout before the forwarding is attempted.
5358 */
5359 @Override
5360 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5361 enforceModifyPermission();
5362 long identity = Binder.clearCallingIdentity();
5363 try {
5364 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5365 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
5369 }
5370
5371 /**
yinxub1bed742017-04-17 11:45:04 -07005372 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005373 *
yinxub1bed742017-04-17 11:45:04 -07005374 * @param subId id of the subscription
5375 * @param request contains the radio access networks with bands/channels to scan
5376 * @param messenger callback messenger for scan results or errors
5377 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005378 * @return the id of the requested scan which can be used to stop the scan.
5379 */
5380 @Override
5381 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005382 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5384 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005385 LocationAccessPolicy.LocationPermissionResult locationResult =
5386 LocationAccessPolicy.checkLocationPermission(mApp,
5387 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5388 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005389 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005390 .setCallingPid(Binder.getCallingPid())
5391 .setCallingUid(Binder.getCallingUid())
5392 .setMethod("requestNetworkScan")
5393 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5394 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005395 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005396 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005397 if (e != null) {
5398 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5399 throw e;
5400 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005401 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005402 return TelephonyScanManager.INVALID_SCAN_ID;
5403 }
5404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 }
Hall Liu912dfd32019-04-25 14:02:26 -07005406 int callingUid = Binder.getCallingUid();
5407 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 return mNetworkScanRequestTracker.startNetworkScan(
5411 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005412 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
yinxu504e1392017-04-12 16:03:22 -07005416 }
5417
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005419 NetworkScanRequest request, int subId) {
5420 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5421 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5422 boolean hasNetworkScanPermission =
5423 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5424 == PERMISSION_GRANTED;
5425
5426 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5427 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5428 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005429 }
5430
5431 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5432 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005433 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5434 return new SecurityException("Specific channels must not be"
5435 + " scanned without location access.");
5436 }
5437 }
5438 }
5439
Hall Liub2ac8ef2019-02-28 15:56:23 -08005440 return null;
5441 }
5442
yinxu504e1392017-04-12 16:03:22 -07005443 /**
5444 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005445 *
5446 * @param subId id of the subscription
5447 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005448 */
5449 @Override
5450 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5452 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453
Hall Liu912dfd32019-04-25 14:02:26 -07005454 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455 final long identity = Binder.clearCallingIdentity();
5456 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005457 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
yinxu504e1392017-04-12 16:03:22 -07005461 }
5462
5463 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005464 * Get the calculated preferred network type.
5465 * Used for debugging incorrect network type.
5466 *
5467 * @return the preferred network type, defined in RILConstants.java.
5468 */
5469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005470 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005471 final Phone defaultPhone = getDefaultPhone();
5472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005473 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005474 return RILConstants.PREFERRED_NETWORK_MODE;
5475 }
5476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 final long identity = Binder.clearCallingIdentity();
5478 try {
5479 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005480 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Junda Liu84d15a22014-07-02 11:21:04 -07005484 }
5485
5486 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005487 * Get the preferred network type.
5488 * Used for device configuration by some CDMA operators.
5489 *
5490 * @return the preferred network type, defined in RILConstants.java.
5491 */
5492 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005493 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005494 TelephonyPermissions
5495 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5496 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497
5498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 if (DBG) log("getPreferredNetworkType");
5501 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5502 int networkType = (result != null ? result[0] : -1);
5503 if (DBG) log("getPreferredNetworkType: " + networkType);
5504 return networkType;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005508 }
5509
5510 /**
5511 * Set the preferred network type.
5512 * Used for device configuration by some CDMA operators.
5513 *
5514 * @param networkType the preferred network type, defined in RILConstants.java.
5515 * @return true on success; false on any failure.
5516 */
5517 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005518 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5520 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521
5522 final long identity = Binder.clearCallingIdentity();
5523 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005524 Settings.Global.putInt(mApp.getContentResolver(),
5525 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5526 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 } finally {
5528 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005529 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005530 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005531
5532 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005533 * Get the allowed network types that store in the telephony provider.
5534 *
5535 * @param subId the id of the subscription.
5536 * @return allowedNetworkTypes the allowed network types.
5537 */
5538 @Override
5539 public long getAllowedNetworkTypes(int subId) {
5540 TelephonyPermissions
5541 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5542 mApp, subId, "getAllowedNetworkTypes");
5543
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 return SubscriptionManager.getLongSubscriptionProperty(
5547 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
5553 /**
5554 * Set the allowed network types.
5555 *
5556 * @param subId the id of the subscription.
5557 * @param allowedNetworkTypes the allowed network types.
5558 * @return true on success; false on any failure.
5559 */
5560 @Override
5561 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5563 mApp, subId, "setAllowedNetworkTypes");
5564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 SubscriptionManager.setSubscriptionProperty(subId,
5567 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5568 String.valueOf(allowedNetworkTypes));
5569 return setPreferredNetworkTypesInternal(subId);
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
5573 }
5574
5575 private boolean setPreferredNetworkTypesInternal(int subId) {
5576 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5577 Settings.Global.getInt(mApp.getContentResolver(),
5578 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5579 RILConstants.PREFERRED_NETWORK_MODE));
5580 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5581 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5582 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5583 (int) (networkTypeBitMask & allowedNetworkTypes));
5584
5585 if (DBG) {
5586 log("setPreferredNetworkTypesInternal: subId " + subId
5587 + " networkTypes " + networkTypeBitMask
5588 + " allowedNetworkTypes " + allowedNetworkTypes
5589 + " networkMode " + networkMode);
5590 }
5591
5592 Boolean success = (Boolean) sendRequest(
5593 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5594 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5595 return success;
5596 }
5597
5598 /**
Miaoa84611c2019-03-15 09:21:10 +08005599 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005600 *
Miaoa84611c2019-03-15 09:21:10 +08005601 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005602 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005603 * @hide
5604 */
5605 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005606 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005609 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 try {
Miaoa84611c2019-03-15 09:21:10 +08005611 if (phone != null) {
5612 return phone.hasMatchedTetherApnSetting();
5613 } else {
5614 return false;
5615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 } finally {
5617 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005618 }
Junda Liu475951f2014-11-07 16:45:03 -08005619 }
5620
5621 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005622 * Set mobile data enabled
5623 * Used by the user through settings etc to turn on/off mobile data
5624 *
5625 * @param enable {@code true} turn turn data on, else {@code false}
5626 */
5627 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005628 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 int phoneId = mSubscriptionController.getPhoneId(subId);
5635 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5636 Phone phone = PhoneFactory.getPhone(phoneId);
5637 if (phone != null) {
5638 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005639 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005641 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 }
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005645 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005646 }
5647
5648 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005649 * Enable or disable always reporting signal strength changes from radio.
5650 *
5651 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5652 */
5653 @Override
5654 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5655 enforceModifyPermission();
5656 enforceSystemCaller();
5657
5658 final long identity = Binder.clearCallingIdentity();
5659 final Phone phone = getPhone(subId);
5660 try {
5661 if (phone != null) {
5662 if (DBG) {
5663 log("setAlwaysReportSignalStrength: subId=" + subId
5664 + " isEnable=" + isEnable);
5665 }
5666 phone.setAlwaysReportSignalStrength(isEnable);
5667 } else {
5668 loge("setAlwaysReportSignalStrength: no phone found for subId="
5669 + subId);
5670 }
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
5673 }
5674 }
5675
5676 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005677 * Get the user enabled state of Mobile Data.
5678 *
5679 * TODO: remove and use isUserDataEnabled.
5680 * This can't be removed now because some vendor codes
5681 * calls through ITelephony directly while they should
5682 * use TelephonyManager.
5683 *
5684 * @return true on enabled
5685 */
5686 @Override
5687 public boolean getDataEnabled(int subId) {
5688 return isUserDataEnabled(subId);
5689 }
5690
5691 /**
5692 * Get whether mobile data is enabled per user setting.
5693 *
5694 * There are other factors deciding whether mobile data is actually enabled, but they are
5695 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005696 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005697 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005698 *
5699 * @return {@code true} if data is enabled else {@code false}
5700 */
5701 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005702 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005703 try {
5704 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5705 null);
5706 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5708 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710
5711 final long identity = Binder.clearCallingIdentity();
5712 try {
5713 int phoneId = mSubscriptionController.getPhoneId(subId);
5714 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5715 Phone phone = PhoneFactory.getPhone(phoneId);
5716 if (phone != null) {
5717 boolean retVal = phone.isUserDataEnabled();
5718 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5719 return retVal;
5720 } else {
5721 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5722 return false;
5723 }
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005726 }
5727 }
5728
5729 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005730 * Checks if the device is capable of mobile data by considering whether whether the
5731 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5732 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005733 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005734 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005735 */
5736 @Override
5737 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005738 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
5742 int phoneId = mSubscriptionController.getPhoneId(subId);
5743 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5744 Phone phone = PhoneFactory.getPhone(phoneId);
5745 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005746 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5748 return retVal;
5749 } else {
5750 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5751 return false;
5752 }
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005755 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005756 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005757
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005758 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005759 Phone phone) {
5760 //load access rules from carrier configs, and check those as well: b/139133814
5761 SubscriptionController subController = SubscriptionController.getInstance();
5762 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5763 || subController == null) return privilegeFromSim;
5764
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005765 PackageManager pkgMgr = phone.getContext().getPackageManager();
5766 String[] packages = pkgMgr.getPackagesForUid(uid);
5767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5771 SubscriptionManager subManager = (SubscriptionManager)
5772 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5773 for (String pkg : packages) {
5774 if (subManager.canManageSubscription(subInfo, pkg)) {
5775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5776 }
5777 }
5778 return privilegeFromSim;
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
5781 }
5782 }
5783
5784 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5785 String pkgName) {
5786 //load access rules from carrier configs, and check those as well: b/139133814
5787 SubscriptionController subController = SubscriptionController.getInstance();
5788 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5789 || subController == null) return privilegeFromSim;
5790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5794 SubscriptionManager subManager = (SubscriptionManager)
5795 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5796 return subManager.canManageSubscription(subInfo, pkgName)
5797 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
5801 }
5802
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005803 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005804 public int getCarrierPrivilegeStatus(int subId) {
5805 final Phone phone = getPhone(subId);
5806 if (phone == null) {
5807 loge("getCarrierPrivilegeStatus: Invalid subId");
5808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5809 }
5810 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005811 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005812 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5814 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005815
5816 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5817 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005818 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005819 }
Junda Liu29340342014-07-10 15:23:27 -07005820
5821 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005822 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005823 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005824 final Phone phone = getPhone(subId);
5825 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005826 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5828 }
5829 UiccProfile profile =
5830 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5831 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005832 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005833 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5834 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005835 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005836 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005837 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005838 }
5839
5840 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005841 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5842 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005844 }
5845
5846 int phoneId = SubscriptionManager.getPhoneId(subId);
5847 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005848 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005849 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5851 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005852 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5853 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5854 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005855 }
5856
5857 @Override
5858 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005859 if (TextUtils.isEmpty(pkgName))
5860 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005861 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5862 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5863 UiccCard card = UiccController.getInstance().getUiccCard(i);
5864 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005865 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005866 continue;
5867 }
5868
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005869 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5870 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5871 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005872 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5873 break;
5874 }
5875 }
5876
5877 return result;
Junda Liu29340342014-07-10 15:23:27 -07005878 }
Derek Tan89e89d42014-07-08 17:00:10 -07005879
5880 @Override
Junda Liue64de782015-04-16 17:19:16 -07005881 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5882 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5883 loge("phoneId " + phoneId + " is not valid.");
5884 return null;
5885 }
5886 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005887 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005888 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005889 return null ;
5890 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005891 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005892 }
5893
Amith Yamasani6e118872016-02-19 12:53:51 -08005894 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005895 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005896 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005897 List<String> privilegedPackages = new ArrayList<>();
5898 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005899 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5900 // has UICC in that slot.
5901 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005902 if (card.hasCarrierPrivilegeRules()) {
5903 if (packages == null) {
5904 // Only check packages in user 0 for now
5905 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005906 PackageManager.MATCH_DISABLED_COMPONENTS
5907 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005908 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005909 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005910 }
5911 for (int p = packages.size() - 1; p >= 0; p--) {
5912 PackageInfo pkgInfo = packages.get(p);
5913 if (pkgInfo != null && pkgInfo.packageName != null
5914 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005915 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005916 privilegedPackages.add(pkgInfo.packageName);
5917 }
5918 }
5919 }
5920 }
5921 return privilegedPackages;
5922 }
5923
chen xuf7e9fe82019-05-09 19:31:02 -07005924 @Override
5925 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005926 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5927
5928 final long identity = Binder.clearCallingIdentity();
5929
chen xuf7e9fe82019-05-09 19:31:02 -07005930 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005931 try {
5932 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5933 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5934 }
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005937 }
5938 return privilegedPackages;
5939 }
5940
Wink Savilleb564aae2014-10-23 10:18:09 -07005941 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005942 final Phone phone = getPhone(subId);
5943 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005944 if (card == null) {
5945 loge("getIccId: No UICC");
5946 return null;
5947 }
5948 String iccId = card.getIccId();
5949 if (TextUtils.isEmpty(iccId)) {
5950 loge("getIccId: ICC ID is null or empty.");
5951 return null;
5952 }
5953 return iccId;
5954 }
5955
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005956 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005957 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5958 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005959 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005960 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 final String iccId = getIccId(subId);
5965 final Phone phone = getPhone(subId);
5966 if (phone == null) {
5967 return false;
5968 }
5969 final String subscriberId = phone.getSubscriberId();
5970
5971 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005972 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 + subscriberId + " to " + number);
5974 }
5975
5976 if (TextUtils.isEmpty(iccId)) {
5977 return false;
5978 }
5979
5980 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5981
5982 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5983 if (alphaTag == null) {
5984 editor.remove(alphaTagPrefKey);
5985 } else {
5986 editor.putString(alphaTagPrefKey, alphaTag);
5987 }
5988
5989 // Record both the line number and IMSI for this ICCID, since we need to
5990 // track all merged IMSIs based on line number
5991 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5992 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5993 if (number == null) {
5994 editor.remove(numberPrefKey);
5995 editor.remove(subscriberPrefKey);
5996 } else {
5997 editor.putString(numberPrefKey, number);
5998 editor.putString(subscriberPrefKey, subscriberId);
5999 }
6000
6001 editor.commit();
6002 return true;
6003 } finally {
6004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006005 }
Derek Tan7226c842014-07-02 17:42:23 -07006006 }
6007
6008 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006009 public String getLine1NumberForDisplay(int subId, String callingPackage,
6010 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006011 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006013 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006014 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006015 return null;
6016 }
Derek Tan97ebb422014-09-05 16:55:38 -07006017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 final long identity = Binder.clearCallingIdentity();
6019 try {
6020 String iccId = getIccId(subId);
6021 if (iccId != null) {
6022 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6023 if (DBG_MERGE) {
6024 log("getLine1NumberForDisplay returning "
6025 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6026 }
6027 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6030 return null;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006033 }
Derek Tan7226c842014-07-02 17:42:23 -07006034 }
6035
6036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006037 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6038 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006040 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006041 return null;
6042 }
Derek Tan97ebb422014-09-05 16:55:38 -07006043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 String iccId = getIccId(subId);
6047 if (iccId != null) {
6048 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6049 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6050 }
6051 return null;
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006054 }
Derek Tan7226c842014-07-02 17:42:23 -07006055 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006056
6057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006058 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6059 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006060 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6061 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006063 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006064 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006065 return null;
6066 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006067
Jordan Liub49b04b2019-05-06 14:45:15 -07006068 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6069 // the process, where TelephonyManager was instantiated.
6070 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006071 final long identity = Binder.clearCallingIdentity();
6072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006073 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 final TelephonyManager tele = TelephonyManager.from(context);
6075 final SubscriptionManager sub = SubscriptionManager.from(context);
6076
6077 // Figure out what subscribers are currently active
6078 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079
Jordan Liub49b04b2019-05-06 14:45:15 -07006080 // Only consider subs which match the current subId
6081 // This logic can be simplified. See b/131189269 for progress.
6082 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006083 activeSubscriberIds.add(tele.getSubscriberId(subId));
6084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 // First pass, find a number override for an active subscriber
6087 String mergeNumber = null;
6088 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6089 for (String key : prefs.keySet()) {
6090 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6091 final String subscriberId = (String) prefs.get(key);
6092 if (activeSubscriberIds.contains(subscriberId)) {
6093 final String iccId = key.substring(
6094 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6095 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6096 mergeNumber = (String) prefs.get(numberKey);
6097 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006098 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 + " for active subscriber " + subscriberId);
6100 }
6101 if (!TextUtils.isEmpty(mergeNumber)) {
6102 break;
6103 }
6104 }
6105 }
6106 }
6107
6108 // Shortcut when no active merged subscribers
6109 if (TextUtils.isEmpty(mergeNumber)) {
6110 return null;
6111 }
6112
6113 // Second pass, find all subscribers under that line override
6114 final ArraySet<String> result = new ArraySet<>();
6115 for (String key : prefs.keySet()) {
6116 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6117 final String number = (String) prefs.get(key);
6118 if (mergeNumber.equals(number)) {
6119 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6120 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6121 final String subscriberId = (String) prefs.get(subscriberKey);
6122 if (!TextUtils.isEmpty(subscriberId)) {
6123 result.add(subscriberId);
6124 }
6125 }
6126 }
6127 }
6128
6129 final String[] resultArray = result.toArray(new String[result.size()]);
6130 Arrays.sort(resultArray);
6131 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006132 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6134 }
6135 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006138 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006139 }
6140
6141 @Override
zoey chen38003472019-12-13 17:16:31 +08006142 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6143 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006144
6145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 final TelephonyManager telephonyManager = mApp.getSystemService(
6148 TelephonyManager.class);
6149 String subscriberId = telephonyManager.getSubscriberId(subId);
6150 if (subscriberId == null) {
6151 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006152 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006153 + subId);
6154 }
6155 return null;
6156 }
6157
6158 final SubscriptionInfo info = SubscriptionController.getInstance()
6159 .getSubscriptionInfo(subId);
6160 final ParcelUuid groupUuid = info.getGroupUuid();
6161 // If it doesn't belong to any group, return just subscriberId of itself.
6162 if (groupUuid == null) {
6163 return new String[]{subscriberId};
6164 }
6165
6166 // Get all subscriberIds from the group.
6167 final List<String> mergedSubscriberIds = new ArrayList<>();
6168 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006169 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006170 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006171 for (SubscriptionInfo subInfo : groupInfos) {
6172 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6173 if (subscriberId != null) {
6174 mergedSubscriberIds.add(subscriberId);
6175 }
6176 }
6177
6178 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181
6182 }
6183 }
6184
6185 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006186 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006187 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006188 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 final Phone phone = getPhone(subId);
6193 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006197 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006198
6199 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006200 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006201 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6202 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006203 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6204 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205
6206 final long identity = Binder.clearCallingIdentity();
6207 try {
6208 final Phone phone = getPhone(subId);
6209 if (phone == null) {
6210 return false;
6211 }
6212 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6213 cdmaNonRoamingList);
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006216 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006217 }
6218
6219 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006220 @Deprecated
6221 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6222 enforceModifyPermission();
6223
6224 int returnValue = 0;
6225 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006226 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006227 if(result.exception == null) {
6228 if (result.result != null) {
6229 byte[] responseData = (byte[])(result.result);
6230 if(responseData.length > oemResp.length) {
6231 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6232 responseData.length + "bytes. Buffer Size is " +
6233 oemResp.length + "bytes.");
6234 }
6235 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6236 returnValue = responseData.length;
6237 }
6238 } else {
6239 CommandException ex = (CommandException) result.exception;
6240 returnValue = ex.getCommandError().ordinal();
6241 if(returnValue > 0) returnValue *= -1;
6242 }
6243 } catch (RuntimeException e) {
6244 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6245 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6246 if(returnValue > 0) returnValue *= -1;
6247 }
6248
6249 return returnValue;
6250 }
6251
6252 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006253 public void setRadioCapability(RadioAccessFamily[] rafs) {
6254 try {
6255 ProxyController.getInstance().setRadioCapability(rafs);
6256 } catch (RuntimeException e) {
6257 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6258 }
6259 }
6260
6261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006262 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006263 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006264 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006265 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006266 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 final long identity = Binder.clearCallingIdentity();
6269 try {
chen xub97461a2018-10-26 14:17:57 -07006270 TelephonyPermissions
6271 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6272 mApp, phone.getSubId(), "getRadioAccessFamily");
6273 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 } finally {
6275 Binder.restoreCallingIdentity(identity);
6276 }
chen xub97461a2018-10-26 14:17:57 -07006277 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006278 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006279
6280 @Override
6281 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006282 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006287 ImsManager.getInstance(defaultPhone.getContext(),
6288 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006292 }
6293
6294 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006295 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006296 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6298 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006299 return false;
6300 }
Svet Ganovb320e182015-04-16 12:30:10 -07006301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 final long identity = Binder.clearCallingIdentity();
6303 try {
6304 // Check the user preference and the system-level IMS setting. Even if the user has
6305 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6306 // In the long run, we may instead need to check if there exists a connection service
6307 // which can support video calling.
6308 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006309 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 return imsManager.isVtEnabledByPlatform()
6311 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6312 && imsManager.isVtEnabledByUser();
6313 } finally {
6314 Binder.restoreCallingIdentity(identity);
6315 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006316 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006317
Andrew Leea1239f22015-03-02 17:44:07 -08006318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006319 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6320 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006322 mApp, subId, callingPackage, callingFeatureId,
6323 "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_DTMF_TYPE_ENABLED_BOOL);
6333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
Andrew Leea1239f22015-03-02 17:44:07 -08006336 }
6337
6338 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006339 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006341 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342 return false;
6343 }
6344
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 CarrierConfigManager configManager =
6348 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006349 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
Andrew Leea1239f22015-03-02 17:44:07 -08006354 }
6355
Andrew Lee9431b832015-03-09 18:46:45 -07006356 @Override
6357 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006358 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006359 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006360 }
6361
6362 @Override
6363 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 final long identity = Binder.clearCallingIdentity();
6365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006366 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Andrew Lee9431b832015-03-09 18:46:45 -07006370 }
6371
Hall Liuf6668912018-10-31 17:05:23 -07006372 /**
6373 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6374 * support for the feature and device firmware support.
6375 *
6376 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6377 */
6378 @Override
6379 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006381 final Phone phone = getPhone(subscriptionId);
6382 if (phone == null) {
6383 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6384 return false;
6385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006387 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6389 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006390 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 return isCarrierSupported && isDeviceSupported;
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Hall Liu98187582018-01-22 19:15:32 -08006395 }
6396
Hall Liuf6668912018-10-31 17:05:23 -07006397 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006398 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6399 * RTT setting, will return true if the device and carrier both support RTT.
6400 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006401 */
6402 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 final long identity = Binder.clearCallingIdentity();
6404 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006405 boolean isRttSupported = isRttSupported(subscriptionId);
6406 boolean isUserRttSettingOn = Settings.Secure.getInt(
6407 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6408 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6409 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6410 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006414 }
6415
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006416 @Deprecated
6417 @Override
6418 public String getDeviceId(String callingPackage) {
6419 return getDeviceIdWithFeature(callingPackage, null);
6420 }
6421
Sanket Padawe7310cc72015-01-14 09:53:20 -08006422 /**
6423 * Returns the unique device ID of phone, for example, the IMEI for
6424 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6425 *
6426 * <p>Requires Permission:
6427 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6428 */
6429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006430 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006431 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006432 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006433 return null;
6434 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006435 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006436 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006437 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006438 return null;
6439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 return phone.getDeviceId();
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006447 }
6448
Ping Sunc67b7c22016-03-02 19:16:45 +08006449 /**
6450 * {@hide}
6451 * Returns the IMS Registration Status on a particular subid
6452 *
6453 * @param subId
6454 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006455 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006456 Phone phone = getPhone(subId);
6457 if (phone != null) {
6458 return phone.isImsRegistered();
6459 } else {
6460 return false;
6461 }
6462 }
6463
Santos Cordon7a1885b2015-02-03 11:15:19 -08006464 @Override
6465 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466 final long identity = Binder.clearCallingIdentity();
6467 try {
6468 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006472 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006473
Tyler Gunnf70ed162019-04-03 15:28:53 -07006474 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006475 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006476 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006478 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006479 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6480 }
6481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 }
6488
6489 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006490 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 Phone phone = getPhone(subscriptionId);
6494 if (phone == null) {
6495 return null;
6496 }
6497 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
6501 }
6502
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006503 /**
6504 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006505 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006506 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507 final long identity = Binder.clearCallingIdentity();
6508 try {
6509 Phone phone = getPhone(subId);
6510 if (phone != null) {
6511 return phone.isWifiCallingEnabled();
6512 } else {
6513 return false;
6514 }
6515 } finally {
6516 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006517 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006518 }
6519
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006520 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006521 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006522 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006523 public boolean isVideoTelephonyAvailable(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.isVideoEnabled();
6529 } else {
6530 return false;
6531 }
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006534 }
6535 }
6536
6537 /**
6538 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6539 * defined in {@link ImsRegistrationImplBase}.
6540 */
6541 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 final long identity = Binder.clearCallingIdentity();
6543 try {
6544 Phone phone = getPhone(subId);
6545 if (phone != null) {
6546 return phone.getImsRegistrationTech();
6547 } else {
6548 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6549 }
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006552 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006553 }
6554
Stuart Scott8eef64f2015-04-08 15:13:54 -07006555 @Override
6556 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006557 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006558 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6559 return;
6560 }
6561
Svet Ganovcc087f82015-05-12 20:35:54 -07006562 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006563
Svet Ganovcc087f82015-05-12 20:35:54 -07006564 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006565 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6566 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006567 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006568 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006569 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006570 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6571 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006572 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006573 // There has been issues when Sms raw table somehow stores orphan
6574 // fragments. They lead to garbled message when new fragments come
6575 // in and combined with those stale ones. In case this happens again,
6576 // user can reset all network settings which will clean up this table.
6577 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006578 // Clean up IMS settings as well here.
6579 int slotId = getSlotIndex(subId);
6580 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6581 ImsManager.getInstance(mApp, slotId).factoryReset();
6582 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006583
6584 // Erase modem config if erase modem on network setting is enabled.
6585 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6586 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6587 if (configValue != null && Boolean.parseBoolean(configValue)) {
6588 sendEraseModemConfig(getDefaultPhone());
6589 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006592 }
6593 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006594
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006595 private void cleanUpSmsRawTable(Context context) {
6596 ContentResolver resolver = context.getContentResolver();
6597 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6598 resolver.delete(uri, null, null);
6599 }
6600
Narayan Kamath1c496c22015-04-16 14:40:19 +01006601 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006602 public String getSimLocaleForSubscriber(int subId) {
6603 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6604 final Phone phone = getPhone(subId);
6605 if (phone == null) {
6606 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006607 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 final long identity = Binder.clearCallingIdentity();
6610 try {
chen xu5d3637b2019-01-21 23:31:38 -08006611 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006612 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006613 if (info == null) {
6614 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6615 return null;
6616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 // Try and fetch the locale from the carrier properties or from the SIM language
6618 // preferences (EF-PL and EF-LI)...
6619 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006621 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6622 if (localeFromDefaultSim != null) {
6623 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6624 if (DBG) log("Using locale from subId: " + subId + " locale: "
6625 + localeFromDefaultSim);
6626 return localeFromDefaultSim.toLanguageTag();
6627 } else {
6628 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 }
6630 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632 // The SIM language preferences only store a language (e.g. fr = French), not an
6633 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6634 // the SIM and carrier preferences does not include a country we add the country
6635 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006636 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006638 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 return mccLocale.toLanguageTag();
6640 }
6641
6642 if (DBG) log("No locale found - returning null");
6643 return null;
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
6646 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006647 }
6648
6649 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006650 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006651 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006652 }
6653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 /**
6655 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6656 */
6657 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006658 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006659 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006660 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006661
Chenjie Yu1ba97252018-01-11 18:16:20 -08006662 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006663 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006664
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006665 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006666 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6667 * representing the state of the modem.
6668 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006669 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6670 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006671 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006672 */
6673 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006674 public void requestModemActivityInfo(ResultReceiver result) {
6675 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006676 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006680 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 } finally {
6682 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006683 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006684 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006685
Siddharth Rayb8114062018-06-17 15:02:38 -07006686 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6687 // less than total activity duration.
6688 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6689 if (info == null) {
6690 return false;
6691 }
6692 int activityDurationMs =
6693 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6694 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006695 int[] txTimeMs = info.getTransmitTimeMillis();
6696 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6697 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006698 }
6699 return (info.isValid()
6700 && (info.getSleepTimeMillis() <= activityDurationMs)
6701 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006702 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006703 && (totalTxTimeMs <= activityDurationMs));
6704 }
6705
Jack Yu85bd38a2015-11-09 11:34:32 -08006706 /**
6707 * {@hide}
6708 * Returns the service state information on specified subscription.
6709 */
6710 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006711 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6712 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006714 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006715 return null;
6716 }
6717
Hall Liuf19c44f2018-11-27 14:38:17 -08006718 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6719 LocationAccessPolicy.checkLocationPermission(mApp,
6720 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6721 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006722 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006723 .setCallingPid(Binder.getCallingPid())
6724 .setCallingUid(Binder.getCallingUid())
6725 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006726 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006727 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6728 .build());
6729
6730 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6731 LocationAccessPolicy.checkLocationPermission(mApp,
6732 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6733 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006734 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006735 .setCallingPid(Binder.getCallingPid())
6736 .setCallingUid(Binder.getCallingUid())
6737 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006738 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006739 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6740 .build());
6741 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6742 boolean hasFinePermission =
6743 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6744 boolean hasCoarsePermission =
6745 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 final long identity = Binder.clearCallingIdentity();
6748 try {
6749 final Phone phone = getPhone(subId);
6750 if (phone == null) {
6751 return null;
6752 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006753
Hall Liuf19c44f2018-11-27 14:38:17 -08006754 ServiceState ss = phone.getServiceState();
6755
6756 // Scrub out the location info in ServiceState depending on what level of access
6757 // the caller has.
6758 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006759 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6760 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006764 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006765
6766 /**
6767 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6768 *
6769 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6770 * voicemail ringtone.
6771 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6772 * PhoneAccount.
6773 */
6774 @Override
6775 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 final long identity = Binder.clearCallingIdentity();
6777 try {
6778 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6779 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006780 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006787 }
6788
6789 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006790 * Sets the per-account voicemail ringtone.
6791 *
6792 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6793 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6794 *
6795 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6796 * voicemail ringtone.
6797 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6798 * PhoneAccount.
6799 */
6800 @Override
6801 public void setVoicemailRingtoneUri(String callingPackage,
6802 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006803 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006805 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6806 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6808 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6809 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6815 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006816 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 }
6818 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006821 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006822 }
6823
6824 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006825 * Returns whether vibration is set for voicemail notification in Phone settings.
6826 *
6827 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6828 * voicemail vibration setting.
6829 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6830 */
6831 @Override
6832 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6836 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006837 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006844 }
6845
Youhan Wange64578a2016-05-02 15:32:42 -07006846 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006847 * Sets the per-account voicemail vibration.
6848 *
6849 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6850 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6851 *
6852 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6853 * voicemail vibration setting.
6854 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6855 * specific PhoneAccount.
6856 */
6857 @Override
6858 public void setVoicemailVibrationEnabled(String callingPackage,
6859 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006860 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006861 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006862 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6863 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6865 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6866 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006867 }
6868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6872 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006873 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 }
6875 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006878 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006879 }
6880
6881 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006882 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6883 *
6884 * @throws SecurityException if the caller does not have the required permission
6885 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006886 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006887 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006888 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006889 }
6890
6891 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006892 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6893 * permission.
6894 *
6895 * @throws SecurityException if the caller does not have the required permission
6896 */
6897 private void enforceSendSmsPermission() {
6898 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6899 }
6900
6901 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006902 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006903 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006904 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006905 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006906 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 final long identity = Binder.clearCallingIdentity();
6908 try {
6909 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006910 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 if (componentName == null) {
6912 throw new SecurityException(
6913 "Caller not current active visual voicemail package[null]");
6914 }
6915 String vvmPackage = componentName.getPackageName();
6916 if (!callingPackage.equals(vvmPackage)) {
6917 throw new SecurityException("Caller not current active visual voicemail package["
6918 + vvmPackage + "]");
6919 }
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006922 }
6923 }
6924
6925 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006926 * Return the application ID for the app type.
6927 *
6928 * @param subId the subscription ID that this request applies to.
6929 * @param appType the uicc app type.
6930 * @return Application ID for specificied app type, or null if no uicc.
6931 */
6932 @Override
6933 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006934 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006935 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936
6937 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006938 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 if (phone == null) {
6940 return null;
6941 }
6942 String aid = null;
6943 try {
6944 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6945 .getApplicationByType(appType).getAid();
6946 } catch (Exception e) {
6947 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6948 }
6949 return aid;
6950 } finally {
6951 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006952 }
Youhan Wange64578a2016-05-02 15:32:42 -07006953 }
6954
Youhan Wang4001d252016-05-11 10:29:41 -07006955 /**
6956 * Return the Electronic Serial Number.
6957 *
6958 * @param subId the subscription ID that this request applies to.
6959 * @return ESN or null if error.
6960 */
6961 @Override
6962 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006963 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006964 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965
6966 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006967 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 if (phone == null) {
6969 return null;
6970 }
6971 String esn = null;
6972 try {
6973 esn = phone.getEsn();
6974 } catch (Exception e) {
6975 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6976 }
6977 return esn;
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006980 }
Youhan Wang4001d252016-05-11 10:29:41 -07006981 }
6982
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006983 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006984 * Return the Preferred Roaming List Version.
6985 *
6986 * @param subId the subscription ID that this request applies to.
6987 * @return PRLVersion or null if error.
6988 */
6989 @Override
6990 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006991 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006992 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993
6994 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006995 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 if (phone == null) {
6997 return null;
6998 }
6999 String cdmaPrlVersion = null;
7000 try {
7001 cdmaPrlVersion = phone.getCdmaPrlVersion();
7002 } catch (Exception e) {
7003 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7004 }
7005 return cdmaPrlVersion;
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007008 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007009 }
7010
7011 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007012 * Get snapshot of Telephony histograms
7013 * @return List of Telephony histograms
7014 * @hide
7015 */
7016 @Override
7017 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7019 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020
7021 final long identity = Binder.clearCallingIdentity();
7022 try {
7023 return RIL.getTelephonyRILTimingHistograms();
7024 } finally {
7025 Binder.restoreCallingIdentity(identity);
7026 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007027 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007028
7029 /**
7030 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007031 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7032 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007033 * Require system privileges. In the future we may add this to carrier APIs.
7034 *
Michele Berionne482f8202018-11-27 18:57:59 -08007035 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007036 */
7037 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007038 @TelephonyManager.SetCarrierRestrictionResult
7039 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007040 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007041 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007042
Michele Berionne482f8202018-11-27 18:57:59 -08007043 if (carrierRestrictionRules == null) {
7044 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007045 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 final long identity = Binder.clearCallingIdentity();
7048 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007049 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007050 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007054 }
7055
7056 /**
7057 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007058 * Get the allowed carrier list and the excluded carrier list, including the priority between
7059 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007060 * Require system privileges. In the future we may add this to carrier APIs.
7061 *
Michele Berionne482f8202018-11-27 18:57:59 -08007062 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007063 */
7064 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007065 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007066 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007071 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7072 if (response instanceof CarrierRestrictionRules) {
7073 return (CarrierRestrictionRules) response;
7074 }
7075 // Response is an Exception of some kind,
7076 // which is signalled to the user as a NULL retval
7077 return null;
7078 } catch (Exception e) {
7079 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7080 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007084 }
7085
fionaxu59545b42016-05-25 15:53:37 -07007086 /**
7087 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7088 * @param subId the subscription ID that this action applies to.
7089 * @param enabled control enable or disable metered apns.
7090 * {@hide}
7091 */
7092 @Override
7093 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7094 enforceModifyPermission();
7095 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096
7097 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007098 if (phone == null) {
7099 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7100 return;
7101 }
7102 try {
7103 phone.carrierActionSetMeteredApnsEnabled(enabled);
7104 } catch (Exception e) {
7105 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 } finally {
7107 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007108 }
7109 }
7110
7111 /**
7112 * Action set from carrier signalling broadcast receivers to enable/disable radio
7113 * @param subId the subscription ID that this action applies to.
7114 * @param enabled control enable or disable radio.
7115 * {@hide}
7116 */
7117 @Override
7118 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7119 enforceModifyPermission();
7120 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121
7122 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007123 if (phone == null) {
7124 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7125 return;
7126 }
7127 try {
7128 phone.carrierActionSetRadioEnabled(enabled);
7129 } catch (Exception e) {
7130 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 } finally {
7132 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007133 }
7134 }
7135
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007136 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007137 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7138 * network status based on which carrier apps could apply actions accordingly,
7139 * enable/disable default url handler for example.
7140 *
7141 * @param subId the subscription ID that this action applies to.
7142 * @param report control start/stop reporting the default network status.
7143 * {@hide}
7144 */
7145 @Override
7146 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7147 enforceModifyPermission();
7148 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
7150 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007151 if (phone == null) {
7152 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7153 return;
7154 }
7155 try {
7156 phone.carrierActionReportDefaultNetworkStatus(report);
7157 } catch (Exception e) {
7158 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 } finally {
7160 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007161 }
7162 }
7163
7164 /**
fionaxud9622282017-07-17 17:51:30 -07007165 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7166 * @param subId the subscription ID that this action applies to.
7167 * {@hide}
7168 */
7169 @Override
7170 public void carrierActionResetAll(int subId) {
7171 enforceModifyPermission();
7172 final Phone phone = getPhone(subId);
7173 if (phone == null) {
7174 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7175 return;
7176 }
7177 try {
7178 phone.carrierActionResetAll();
7179 } catch (Exception e) {
7180 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7181 }
7182 }
7183
7184 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007185 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7186 * bug report is being generated.
7187 */
7188 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007189 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007190 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7191 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007192 writer.println("Permission Denial: can't dump Phone from pid="
7193 + Binder.getCallingPid()
7194 + ", uid=" + Binder.getCallingUid()
7195 + "without permission "
7196 + android.Manifest.permission.DUMP);
7197 return;
7198 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007199 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007200 }
Jack Yueb89b242016-06-22 13:27:47 -07007201
Brad Ebingerdac2f002018-04-03 15:17:52 -07007202 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007203 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7204 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7205 @NonNull String[] args) {
7206 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7207 this, in.getFileDescriptor(), out.getFileDescriptor(),
7208 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007209 }
7210
Jack Yueb89b242016-06-22 13:27:47 -07007211 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007212 * Policy control of data connection. Usually used when data limit is passed.
7213 * @param enabled True if enabling the data, otherwise disabling.
7214 * @param subId Subscription index
7215 * {@hide}
7216 */
7217 @Override
7218 public void setPolicyDataEnabled(boolean enabled, int subId) {
7219 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
7223 Phone phone = getPhone(subId);
7224 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007225 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 }
7227 } finally {
7228 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007229 }
7230 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007231
7232 /**
7233 * Get Client request stats
7234 * @return List of Client Request Stats
7235 * @hide
7236 */
7237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007238 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7239 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007241 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007242 return null;
7243 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007244 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 if (phone != null) {
7249 return phone.getClientRequestStats();
7250 }
7251
7252 return null;
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007256 }
7257
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007258 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007259 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007260 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007261 }
Jack Yueb4124c2017-02-16 15:32:43 -08007262
7263 /**
Grace Chen70990072017-03-24 17:21:30 -07007264 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007265 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007266 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007267 * @param state State of SIM (power down, power up, pass through)
7268 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7269 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7270 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007271 *
7272 **/
7273 @Override
Grace Chen70990072017-03-24 17:21:30 -07007274 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007275 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007276 Phone phone = PhoneFactory.getPhone(slotIndex);
7277
vagdeviaf9a5b92018-08-15 16:01:53 -07007278 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 final long identity = Binder.clearCallingIdentity();
7281 try {
7282 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007283 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007284 }
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007287 }
7288 }
Shuo Qiandd210312017-04-12 22:11:33 +00007289
Tyler Gunn65d45c22017-06-05 11:22:26 -07007290 private boolean isUssdApiAllowed(int subId) {
7291 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007292 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007293 if (configManager == null) {
7294 return false;
7295 }
7296 PersistableBundle pb = configManager.getConfigForSubId(subId);
7297 if (pb == null) {
7298 return false;
7299 }
7300 return pb.getBoolean(
7301 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7302 }
7303
Shuo Qiandd210312017-04-12 22:11:33 +00007304 /**
7305 * Check if phone is in emergency callback mode
7306 * @return true if phone is in emergency callback mode
7307 * @param subId sub id
7308 */
goneil9c5f4872017-12-05 14:07:56 -08007309 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007310 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007311 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007312 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313
7314 final long identity = Binder.clearCallingIdentity();
7315 try {
7316 if (phone != null) {
7317 return phone.isInEcm();
7318 } else {
7319 return false;
7320 }
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007323 }
7324 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007325
7326 /**
7327 * Get the current signal strength information for the given subscription.
7328 * Because this information is not updated when the device is in a low power state
7329 * it should not be relied-upon to be current.
7330 * @param subId Subscription index
7331 * @return the most recent cached signal strength info from the modem
7332 */
7333 @Override
7334 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 Phone p = getPhone(subId);
7338 if (p == null) {
7339 return null;
7340 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 return p.getSignalStrength();
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007346 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007347
Pengquan Meng77b7f132018-08-22 14:49:57 -07007348 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007349 * Get the current modem radio state for the given slot.
7350 * @param slotIndex slot index.
7351 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007352 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007353 * @return the current radio power state from the modem
7354 */
7355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007356 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007357 Phone phone = PhoneFactory.getPhone(slotIndex);
7358 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7360 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007361 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7362 }
7363
7364 final long identity = Binder.clearCallingIdentity();
7365 try {
7366 return phone.getRadioPowerState();
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
7370 }
7371 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7372 }
7373
7374 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007375 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7376 *
7377 * <p>Requires one of the following permissions:
7378 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7379 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7380 * privileges.
7381 *
7382 * @param subId subscription id
7383 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7384 * {@code false}.
7385 */
7386 @Override
7387 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007388 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7389 null /* message */);
7390
Pengquan Menga1bb6272018-09-06 09:59:22 -07007391 boolean isEnabled = false;
7392 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007393 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007394 Phone phone = getPhone(subId);
7395 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007396 } catch (Exception e) {
7397 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7398 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007399 } finally {
7400 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007401 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007402 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007403 }
7404
7405
7406 /**
7407 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7408 *
7409 * <p> Requires permission:
7410 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7411 * privileges.
7412 *
7413 * @param subId subscription id
7414 * @param isEnabled {@code true} means enable, {@code false} means disable.
7415 */
7416 @Override
7417 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7419 mApp, subId, "setDataRoamingEnabled");
7420
Pengquan Menga1bb6272018-09-06 09:59:22 -07007421 final long identity = Binder.clearCallingIdentity();
7422 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007423 Phone phone = getPhone(subId);
7424 if (phone != null) {
7425 phone.setDataRoamingEnabled(isEnabled);
7426 }
7427 } finally {
7428 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007429 }
7430 }
7431
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007432 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007433 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007434 TelephonyPermissions
7435 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007436 mApp, subId, "isManualNetworkSelectionAllowed");
7437
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007438 boolean isAllowed = true;
7439 final long identity = Binder.clearCallingIdentity();
7440 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007441 Phone phone = getPhone(subId);
7442 if (phone != null) {
7443 isAllowed = phone.isCspPlmnEnabled();
7444 }
7445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
7448 return isAllowed;
7449 }
7450
7451 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007452 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007453 // Verify that tha callingPackage belongs to the calling UID
7454 mApp.getSystemService(AppOpsManager.class)
7455 .checkPackage(Binder.getCallingUid(), callingPackage);
7456
Jordan Liu1e142fc2019-04-22 15:10:43 -07007457 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007458 try {
7459 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007460 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007461 } catch (SecurityException e) {
7462 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7463 // has carrier privileges on an active UICC
7464 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7465 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007466 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007467 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007468 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007469
7470 final long identity = Binder.clearCallingIdentity();
7471 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007472 UiccController uiccController = UiccController.getInstance();
7473 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007474 if (hasReadPermission) {
7475 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007476 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007477
7478 // Remove private info if the caller doesn't have access
7479 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7480 for (UiccCardInfo cardInfo : cardInfos) {
7481 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7482 // is available
7483 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7484 if (card == null || card.getUiccProfile() == null) {
7485 // assume no access if the card or profile is unavailable
7486 filteredInfos.add(cardInfo.getUnprivileged());
7487 continue;
7488 }
7489 UiccProfile profile = card.getUiccProfile();
7490 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7491 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7492 filteredInfos.add(cardInfo);
7493 } else {
7494 filteredInfos.add(cardInfo.getUnprivileged());
7495 }
7496 }
7497 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007498 } finally {
7499 Binder.restoreCallingIdentity(identity);
7500 }
7501 }
7502
7503 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007504 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007505 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 final long identity = Binder.clearCallingIdentity();
7508 try {
7509 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7510 if (slots == null) {
7511 Rlog.i(LOG_TAG, "slots is null.");
7512 return null;
7513 }
7514
7515 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7516 for (int i = 0; i < slots.length; i++) {
7517 UiccSlot slot = slots[i];
7518 if (slot == null) {
7519 continue;
7520 }
7521
Jordan Liu7be7e652019-05-06 18:55:02 +00007522 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 UiccCard card = slot.getUiccCard();
7524 if (card != null) {
7525 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007526 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007527 cardId = slot.getEid();
7528 if (TextUtils.isEmpty(cardId)) {
7529 cardId = slot.getIccId();
7530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 }
7532
Jordan Liu857451f2019-05-09 16:35:35 -07007533 if (cardId != null) {
7534 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7535 // if cardId is an EID, it's all digits so this is fine
7536 cardId = IccUtils.stripTrailingFs(cardId);
7537 }
7538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 int cardState = 0;
7540 switch (slot.getCardState()) {
7541 case CARDSTATE_ABSENT:
7542 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7543 break;
7544 case CARDSTATE_PRESENT:
7545 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7546 break;
7547 case CARDSTATE_ERROR:
7548 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7549 break;
7550 case CARDSTATE_RESTRICTED:
7551 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7552 break;
7553 default:
7554 break;
7555
7556 }
7557
7558 infos[i] = new UiccSlotInfo(
7559 slot.isActive(),
7560 slot.isEuicc(),
7561 cardId,
7562 cardState,
7563 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007564 slot.isExtendedApduSupported(),
7565 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 }
7567 return infos;
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007570 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007571 }
7572
7573 @Override
7574 public boolean switchSlots(int[] physicalSlots) {
7575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576
7577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007583 }
Jack Yu4c988042018-02-27 15:30:01 -08007584
7585 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007586 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 return UiccController.getInstance().getCardIdForDefaultEuicc();
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
7592 }
7593 }
7594
Pengquan Meng85728fb2018-03-12 16:31:21 -07007595 /**
goneil47ffb6e2018-04-06 15:40:58 -07007596 * A test API to reload the UICC profile.
7597 *
7598 * <p>Requires that the calling app has permission
7599 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7600 * @hide
7601 */
7602 @Override
7603 public void refreshUiccProfile(int subId) {
7604 enforceModifyPermission();
7605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 Phone phone = getPhone(subId);
7609 if (phone == null) {
7610 return;
7611 }
7612 UiccCard uiccCard = phone.getUiccCard();
7613 if (uiccCard == null) {
7614 return;
7615 }
7616 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7617 if (uiccProfile == null) {
7618 return;
7619 }
7620 uiccProfile.refresh();
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
7626 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007627 * Returns false if the mobile data is disabled by default, otherwise return true.
7628 */
7629 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007630 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007631 }
7632
7633 /**
7634 * Returns true if the data roaming is enabled by default, i.e the system property
7635 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7636 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7637 */
7638 private boolean getDefaultDataRoamingEnabled(int subId) {
7639 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007641 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007642 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7643 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7644 return isDataRoamingEnabled;
7645 }
7646
7647 /**
7648 * Returns the default network type for the given {@code subId}, if the default network type is
7649 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7650 */
7651 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007652 List<Integer> list = TelephonyProperties.default_network();
7653 int phoneId = mSubscriptionController.getPhoneId(subId);
7654 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7655 return list.get(phoneId);
7656 }
7657 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007658 }
fionaxua13278b2018-03-21 00:08:13 -07007659
7660 @Override
7661 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007662 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007663 enforceModifyPermission();
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("setCarrierTestOverride fails with invalid subId: " + subId);
7670 return;
7671 }
chen xueaba88a2019-03-15 13:15:10 -07007672 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7673 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 } finally {
7675 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007676 }
fionaxua13278b2018-03-21 00:08:13 -07007677 }
7678
7679 @Override
7680 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007681 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682
7683 final long identity = Binder.clearCallingIdentity();
7684 try {
7685 final Phone phone = getPhone(subId);
7686 if (phone == null) {
7687 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7688 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7689 }
7690 return phone.getCarrierIdListVersion();
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007693 }
fionaxua13278b2018-03-21 00:08:13 -07007694 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007695
7696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7698 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007700 mApp, subId, callingPackage, callingFeatureId,
7701 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007702 return -1;
7703 }
7704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
7711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007712
7713 @Override
7714 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007715 TelephonyPermissions
7716 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007717 mApp, subId, "getCdmaRoamingMode");
7718
7719 final long identity = Binder.clearCallingIdentity();
7720 try {
7721 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
7725 }
7726
7727 @Override
7728 public boolean setCdmaRoamingMode(int subId, int mode) {
7729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7730 mApp, subId, "setCdmaRoamingMode");
7731
7732 final long identity = Binder.clearCallingIdentity();
7733 try {
7734 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
7738 }
7739
7740 @Override
7741 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7743 mApp, subId, "setCdmaSubscriptionMode");
7744
7745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
7750 }
7751 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007752
sqianc5eccab2018-10-19 18:46:41 -07007753 @Override
sqian8c685422019-02-22 15:55:18 -08007754 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007755 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007757 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7758 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007759 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7760 }
7761 final long identity = Binder.clearCallingIdentity();
7762 try {
sqian854d44b2018-12-12 16:48:18 -08007763 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7764 for (Phone phone: PhoneFactory.getPhones()) {
7765 if (phone.getEmergencyNumberTracker() != null
7766 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7767 emergencyNumberListInternal.put(
7768 phone.getSubId(),
7769 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7770 }
sqian11b7a0e2018-12-05 18:48:28 -08007771 }
sqian854d44b2018-12-12 16:48:18 -08007772 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007773 } finally {
7774 Binder.restoreCallingIdentity(identity);
7775 }
sqianc5eccab2018-10-19 18:46:41 -07007776 }
7777
7778 @Override
sqian8c685422019-02-22 15:55:18 -08007779 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007780 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007781 if (!exactMatch) {
7782 TelephonyPermissions
7783 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007784 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007785 }
7786 final long identity = Binder.clearCallingIdentity();
7787 try {
sqian854d44b2018-12-12 16:48:18 -08007788 for (Phone phone: PhoneFactory.getPhones()) {
7789 if (phone.getEmergencyNumberTracker() != null
7790 && phone.getEmergencyNumberTracker() != null) {
7791 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7792 number, exactMatch)) {
7793 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007794 }
7795 }
sqian11b7a0e2018-12-05 18:48:28 -08007796 }
7797 return false;
7798 } finally {
7799 Binder.restoreCallingIdentity(identity);
7800 }
7801 }
7802
sqianf4ca7ed2019-01-15 18:32:07 -08007803 /**
7804 * Update emergency number list for test mode.
7805 */
7806 @Override
7807 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7809 "updateEmergencyNumberListTestMode");
7810
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 for (Phone phone: PhoneFactory.getPhones()) {
7814 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7815 if (tracker != null) {
7816 tracker.executeEmergencyNumberTestModeCommand(action, num);
7817 }
7818 }
7819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
7822 }
7823
7824 /**
7825 * Get the full emergency number list for test mode.
7826 */
7827 @Override
7828 public List<String> getEmergencyNumberListTestMode() {
7829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7830 "getEmergencyNumberListTestMode");
7831
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 Set<String> emergencyNumbers = new HashSet<>();
7835 for (Phone phone: PhoneFactory.getPhones()) {
7836 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7837 if (tracker != null) {
7838 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7839 emergencyNumbers.add(num.getNumber());
7840 }
7841 }
7842 }
7843 return new ArrayList<>(emergencyNumbers);
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
7848
chen xud6b45bd2018-10-30 22:27:10 -07007849 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007850 public int getEmergencyNumberDbVersion(int subId) {
7851 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7852
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 final Phone phone = getPhone(subId);
7856 if (phone == null) {
7857 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7858 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7859 }
7860 return phone.getEmergencyNumberDbVersion();
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
7864 }
7865
7866 @Override
7867 public void notifyOtaEmergencyNumberDbInstalled() {
7868 enforceModifyPermission();
7869
7870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 for (Phone phone: PhoneFactory.getPhones()) {
7873 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7874 if (tracker != null) {
7875 tracker.updateOtaEmergencyNumberDatabase();
7876 }
7877 }
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
7881 }
7882
7883 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007884 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007885 enforceActiveEmergencySessionPermission();
7886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 for (Phone phone: PhoneFactory.getPhones()) {
7890 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7891 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007892 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7893 }
7894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
7899
7900 @Override
7901 public void resetOtaEmergencyNumberDbFilePath() {
7902 enforceActiveEmergencySessionPermission();
7903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 for (Phone phone: PhoneFactory.getPhones()) {
7907 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7908 if (tracker != null) {
7909 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007910 }
7911 }
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
7915 }
7916
7917 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007918 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7919 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7920 Phone phone = getPhone(subId);
7921 if (phone == null) {
7922 return null;
7923 }
7924 final long identity = Binder.clearCallingIdentity();
7925 try {
7926 UiccProfile profile = UiccController.getInstance()
7927 .getUiccProfileForPhone(phone.getPhoneId());
7928 if (profile != null) {
7929 return profile.getCertsFromCarrierPrivilegeAccessRules();
7930 }
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
7934 return null;
7935 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007936
7937 /**
7938 * Enable or disable a modem stack.
7939 */
7940 @Override
7941 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7942 enforceModifyPermission();
7943
7944 final long identity = Binder.clearCallingIdentity();
7945 try {
7946 Phone phone = PhoneFactory.getPhone(slotIndex);
7947 if (phone == null) {
7948 return false;
7949 } else {
7950 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7951 }
7952 } finally {
7953 Binder.restoreCallingIdentity(identity);
7954 }
7955 }
Michelecea4cf22018-12-21 15:00:11 -08007956
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007957 /**
7958 * Whether a modem stack is enabled or not.
7959 */
7960 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007961 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7962 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007963 Phone phone = PhoneFactory.getPhone(slotIndex);
7964 if (phone == null) return false;
7965
7966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007967 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7968 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007969 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7970 }
7971
7972 final long identity = Binder.clearCallingIdentity();
7973 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007974 try {
7975 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7976 } catch (NoSuchElementException ex) {
7977 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7978 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007979 } finally {
7980 Binder.restoreCallingIdentity(identity);
7981 }
7982 }
7983
Michelecea4cf22018-12-21 15:00:11 -08007984 @Override
Michele0ea7d782019-03-19 14:58:42 -07007985 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007986 enforceModifyPermission();
7987
7988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007991 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007992 .commit();
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
7995 }
7996 }
7997
7998 @Override
Michele0ea7d782019-03-19 14:58:42 -07007999 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008000 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008002 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8003 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008004 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008005 }
Michelecea4cf22018-12-21 15:00:11 -08008006
8007 final long identity = Binder.clearCallingIdentity();
8008 try {
Michele0ea7d782019-03-19 14:58:42 -07008009 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008010 } finally {
8011 Binder.restoreCallingIdentity(identity);
8012 }
8013 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008014
Michele0ea7d782019-03-19 14:58:42 -07008015 @TelephonyManager.IsMultiSimSupportedResult
8016 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008017 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8018 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8019 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008020 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8021 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008022 }
8023 // Check if the hardware supports multisim functionality. If usage of multisim is not
8024 // supported by the modem, indicate that it is restricted.
8025 PhoneCapability staticCapability =
8026 mPhoneConfigurationManager.getStaticPhoneCapability();
8027 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008028 loge("isMultiSimSupportedInternal: no static configuration available");
8029 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008030 }
Sarah Chin7caee492020-02-18 20:49:02 +00008031 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008032 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8033 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008034 }
8035 // Check if support of multiple SIMs is restricted by carrier
8036 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008037 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008038 }
8039
Michele0ea7d782019-03-19 14:58:42 -07008040 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008041 }
8042
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008043 /**
8044 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008045 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8046 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8047 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008048 * @param numOfSims number of active sims we want to switch to
8049 */
8050 @Override
8051 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008052 if (numOfSims == 1) {
8053 enforceModifyPermission();
8054 } else {
8055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8056 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8057 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008058 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008059
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008060 try {
Michele30b57b22019-03-01 12:01:14 -08008061 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008062 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008063 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8064 return;
8065 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008066 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
8069 }
8070 }
8071
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008072 @Override
8073 public boolean isApplicationOnUicc(int subId, int appType) {
8074 enforceReadPrivilegedPermission("isApplicationOnUicc");
8075 Phone phone = getPhone(subId);
8076 if (phone == null) {
8077 return false;
8078 }
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 UiccCard uiccCard = phone.getUiccCard();
8082 if (uiccCard == null) {
8083 return false;
8084 }
8085 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8086 if (uiccProfile == null) {
8087 return false;
8088 }
8089 if (TelephonyManager.APPTYPE_SIM <= appType
8090 && appType <= TelephonyManager.APPTYPE_ISIM) {
8091 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8092 }
8093 return false;
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
8097 }
8098
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008099 /**
chen xub4baa772019-04-03 10:23:41 -07008100 * Get whether making changes to modem configurations will trigger reboot.
8101 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008102 */
8103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008104 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8105 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008107 mApp, subId, callingPackage, callingFeatureId,
8108 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008109 return false;
8110 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
8117 }
8118
Nathan Harold29f5f052019-02-15 13:41:57 -08008119 private void updateModemStateMetrics() {
8120 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8121 // TODO: check the state for each modem if the api is ready.
8122 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8123 }
8124
Pengquan Meng3889a572019-01-23 11:16:29 -08008125 @Override
8126 public int[] getSlotsMapping() {
8127 enforceReadPrivilegedPermission("getSlotsMapping");
8128
8129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8132 // All logical slots should have a mapping to a physical slot.
8133 int[] logicalSlotsMapping = new int[phoneCount];
8134 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8135 for (int i = 0; i < slotInfos.length; i++) {
8136 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8137 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8138 }
8139 }
8140 return logicalSlotsMapping;
8141 } finally {
8142 Binder.restoreCallingIdentity(identity);
8143 }
8144 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008145
8146 /**
8147 * Get the IRadio HAL Version
8148 */
8149 @Override
8150 public int getRadioHalVersion() {
8151 Phone phone = getDefaultPhone();
8152 if (phone == null) return -1;
8153 HalVersion hv = phone.getHalVersion();
8154 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8155 return hv.major * 100 + hv.minor;
8156 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008157
8158 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008159 * Get the current calling package name.
8160 * @return the current calling package name
8161 */
8162 @Override
8163 public String getCurrentPackageName() {
8164 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8165 }
8166
8167 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008168 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8169 * corresponding network requests on a subId.
8170 *
8171 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008172 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008173 * 2) APN is un-metered for this subscription, or
8174 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008175 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008176 *
8177 * @return whether data is allowed for a apn type.
8178 *
8179 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008180 */
8181 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008182 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008183 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8184 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008185
8186 // Now that all security checks passes, perform the operation as ourselves.
8187 final long identity = Binder.clearCallingIdentity();
8188 try {
8189 Phone phone = getPhone(subId);
8190 if (phone == null) return false;
8191
Jack Yu41407ee2019-05-13 16:54:09 -07008192 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008193 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8194 } finally {
8195 Binder.restoreCallingIdentity(identity);
8196 }
8197 }
8198
8199 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008200 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008201 enforceReadPrivilegedPermission("isApnMetered");
8202
8203 // Now that all security checks passes, perform the operation as ourselves.
8204 final long identity = Binder.clearCallingIdentity();
8205 try {
8206 Phone phone = getPhone(subId);
8207 if (phone == null) return true; // By default return true.
8208
Jack Yu41407ee2019-05-13 16:54:09 -07008209 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
8213 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008214
8215 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008216 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8217 int subscriptionId, IBooleanConsumer resultCallback) {
8218 enforceModifyPermission();
8219 long token = Binder.clearCallingIdentity();
8220 try {
8221 Phone phone = getPhone(subscriptionId);
8222 if (phone == null) {
8223 try {
8224 if (resultCallback != null) {
8225 resultCallback.accept(false);
8226 }
8227 } catch (RemoteException e) {
8228 // ignore
8229 }
8230 return;
8231 }
8232 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8233 Pair.create(specifiers, (x) -> {
8234 try {
8235 if (resultCallback != null) {
8236 resultCallback.accept(x);
8237 }
8238 } catch (RemoteException e) {
8239 // ignore
8240 }
8241 });
8242 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8243 } finally {
8244 Binder.restoreCallingIdentity(token);
8245 }
8246 }
8247
8248 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008249 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008250 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008251 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8252 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8253 if (iccRecords == null) {
8254 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8255 return false;
8256 }
8257 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8258 }
8259
8260 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008261 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8262 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008263 if (callingPackage == null) {
8264 callingPackage = getCurrentPackageName();
8265 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008266 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8267 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008268 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8269 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008270 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8271 }
8272 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8273 Intent intent = new Intent();
8274 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8275 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8276 // Bring up choose default SMS subscription dialog right now
8277 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8278 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8279 mApp.startActivity(intent);
8280 }
chen xud5ca2d52019-05-28 15:20:57 -07008281
8282 @Override
8283 public String getMmsUAProfUrl(int subId) {
8284 //TODO investigate if this API should require proper permission check in R b/133791609
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008287 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8288 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
8293
8294 @Override
8295 public String getMmsUserAgent(int subId) {
8296 //TODO investigate if this API should require proper permission check in R b/133791609
8297 final long identity = Binder.clearCallingIdentity();
8298 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008299 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8300 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 }
Jack Yub07d4972019-05-28 16:12:25 -07008305
8306 @Override
8307 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8308 enforceModifyPermission();
8309
8310 // Now that all security checks passes, perform the operation as ourselves.
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
8313 Phone phone = getPhone(subId);
8314 if (phone == null) return false;
8315
8316 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
8321
8322 @Override
8323 public boolean isDataAllowedInVoiceCall(int subId) {
8324 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8325
8326 // Now that all security checks passes, perform the operation as ourselves.
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 Phone phone = getPhone(subId);
8330 if (phone == null) return false;
8331
8332 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
8336 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008337
changbettyd5c246e2019-12-24 15:40:37 +08008338 @Override
8339 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8340 enforceModifyPermission();
8341
8342 // Now that all security checks passes, perform the operation as ourselves.
8343 final long identity = Binder.clearCallingIdentity();
8344 try {
8345 Phone phone = getPhone(subId);
8346 if (phone == null) return false;
8347
8348 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
8352 }
8353
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008354 /**
8355 * Updates whether conference event pacakge handling is enabled.
8356 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8357 * otherwise.
8358 */
8359 @Override
8360 public void setCepEnabled(boolean isCepEnabled) {
8361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8362
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8366 for (Phone phone : PhoneFactory.getPhones()) {
8367 Phone defaultPhone = phone.getImsPhone();
8368 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8369 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8370 ImsPhoneCallTracker imsPhoneCallTracker =
8371 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8372 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8373 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8374 + imsPhone.getMsisdn());
8375 }
8376 }
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
8380 }
allenwtsu46dcc572020-01-08 18:24:03 +08008381
8382 /**
8383 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8384 *
8385 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8386 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8387 * before being read.
8388 */
8389 @Override
8390 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8391 isCompressed) {
8392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8393 mApp, subId, "notifyRcsAutoConfigurationReceived");
8394 try {
8395 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8396 if (configBinder == null) {
8397 Rlog.e(LOG_TAG, "null result for getImsConfig");
8398 } else {
8399 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8400 }
8401 } catch (RemoteException e) {
8402 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8403 }
8404 }
zoey chene02881a2019-12-30 16:11:23 +08008405
8406 @Override
8407 public boolean isIccLockEnabled(int subId) {
8408 enforceReadPrivilegedPermission("isIccLockEnabled");
8409
8410 // Now that all security checks passes, perform the operation as ourselves.
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
8413 Phone phone = getPhone(subId);
8414 if (phone != null && phone.getIccCard() != null) {
8415 return phone.getIccCard().getIccLockEnabled();
8416 } else {
8417 return false;
8418 }
8419 } finally {
8420 Binder.restoreCallingIdentity(identity);
8421 }
8422 }
8423
8424 /**
8425 * Set the ICC pin lock enabled or disabled.
8426 *
8427 * @return an integer representing the status of IccLock enabled or disabled in the following
8428 * three cases:
8429 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8430 * successfully.
8431 * - Positive number and zero for remaining password attempts.
8432 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8433 *
8434 */
8435 @Override
8436 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8437 enforceModifyPermission();
8438
8439 Phone phone = getPhone(subId);
8440 if (phone == null) {
8441 return 0;
8442 }
8443 // Now that all security checks passes, perform the operation as ourselves.
8444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8447 new Pair<Boolean, String>(enabled, password), phone, null);
8448 return attemptsRemaining;
8449
8450 } catch (Exception e) {
8451 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 return 0;
8456 }
8457
8458 /**
8459 * Change the ICC password used in ICC pin lock.
8460 *
8461 * @return an integer representing the status of IccLock changed in the following three cases:
8462 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8463 * - Positive number and zero for remaining password attempts.
8464 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8465 *
8466 */
8467 @Override
8468 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8469 enforceModifyPermission();
8470
8471 Phone phone = getPhone(subId);
8472 if (phone == null) {
8473 return 0;
8474 }
8475 // Now that all security checks passes, perform the operation as ourselves.
8476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8479 new Pair<String, String>(oldPassword, newPassword), phone, null);
8480 return attemptsRemaining;
8481
8482 } catch (Exception e) {
8483 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
8486 }
8487 return 0;
8488 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008489
8490 /**
8491 * Request for receiving user activity notification
8492 */
8493 @Override
8494 public void requestUserActivityNotification() {
8495 if (!mNotifyUserActivity.get()
8496 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8497 mNotifyUserActivity.set(true);
8498 }
8499 }
8500
8501 /**
8502 * Called when userActivity is signalled in the power manager.
8503 * This is safe to call from any thread, with any window manager locks held or not.
8504 */
8505 @Override
8506 public void userActivity() {
8507 // ***************************************
8508 // * Inherited from PhoneWindowManager *
8509 // ***************************************
8510 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8511 // WITH ITS LOCKS HELD.
8512 //
8513 // This code must be VERY careful about the locks
8514 // it acquires.
8515 // In fact, the current code acquires way too many,
8516 // and probably has lurking deadlocks.
8517
8518 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8519 throw new SecurityException("Only the OS may call notifyUserActivity()");
8520 }
8521
8522 if (mNotifyUserActivity.getAndSet(false)) {
8523 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8524 USER_ACTIVITY_NOTIFICATION_DELAY);
8525 }
8526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008527}