blob: 72702432d130bc93595414110b55cfd1edb1499f [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
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700315 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
316
Derek Tan97ebb422014-09-05 16:55:38 -0700317 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
318 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800319 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800320 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700321
Michelecea4cf22018-12-21 15:00:11 -0800322 // String to store multi SIM allowed
323 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
324
Derek Tan740e1672017-06-27 14:56:27 -0700325 // The AID of ISD-R.
326 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
327
yinxub1bed742017-04-17 11:45:04 -0700328 private NetworkScanRequestTracker mNetworkScanRequestTracker;
329
David Kelly5e06a7f2018-03-12 14:10:59 +0000330 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
331 private static final int MANUFACTURER_CODE_LENGTH = 8;
332
Derek Tan89e89d42014-07-08 17:00:10 -0700333 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700334 * Experiment flag to enable erase modem config on reset network, default value is false
335 */
336 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
337 "reset_network_erase_modem_config_enabled";
338
339 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700340 * A request object to use for transmitting data to an ICC.
341 */
342 private static final class IccAPDUArgument {
343 public int channel, cla, command, p1, p2, p3;
344 public String data;
345
346 public IccAPDUArgument(int channel, int cla, int command,
347 int p1, int p2, int p3, String data) {
348 this.channel = channel;
349 this.cla = cla;
350 this.command = command;
351 this.p1 = p1;
352 this.p2 = p2;
353 this.p3 = p3;
354 this.data = data;
355 }
356 }
357
358 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700359 * A request object to use for transmitting data to an ICC.
360 */
361 private static final class ManualNetworkSelectionArgument {
362 public OperatorInfo operatorInfo;
363 public boolean persistSelection;
364
365 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
366 this.operatorInfo = operatorInfo;
367 this.persistSelection = persistSelection;
368 }
369 }
370
371 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
373 * request after sending. The main thread will notify the request when it is complete.
374 */
375 private static final class MainThreadRequest {
376 /** The argument to use for the request */
377 public Object argument;
378 /** The result of the request that is run on the main thread */
379 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800380 // The subscriber id that this request applies to. Defaults to
381 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
382 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Nathan Harold92bed182018-10-12 18:16:49 -0700384 // In cases where subId is unavailable, the caller needs to specify the phone.
385 public Phone phone;
386
vagdeviaf9a5b92018-08-15 16:01:53 -0700387 public WorkSource workSource;
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 public MainThreadRequest(Object argument) {
390 this.argument = argument;
391 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392
Nathan Harold92bed182018-10-12 18:16:49 -0700393 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
394 this.argument = argument;
395 if (phone != null) {
396 this.phone = phone;
397 }
398 this.workSource = workSource;
399 }
400
vagdeviaf9a5b92018-08-15 16:01:53 -0700401 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800402 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800403 if (subId != null) {
404 this.subId = subId;
405 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700406 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 }
409
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800410 private static final class IncomingThirdPartyCallArgs {
411 public final ComponentName component;
412 public final String callId;
413 public final String callerDisplayName;
414
415 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
416 String callerDisplayName) {
417 this.component = component;
418 this.callId = callId;
419 this.callerDisplayName = callerDisplayName;
420 }
421 }
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 /**
424 * A handler that processes messages on the main thread in the phone process. Since many
425 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
426 * inbound binder threads to the main thread in the phone process. The Binder thread
427 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
428 * on, which will be notified when the operation completes and will contain the result of the
429 * request.
430 *
431 * <p>If a MainThreadRequest object is provided in the msg.obj field,
432 * note that request.result must be set to something non-null for the calling thread to
433 * unblock.
434 */
435 private final class MainThreadHandler extends Handler {
436 @Override
437 public void handleMessage(Message msg) {
438 MainThreadRequest request;
439 Message onCompleted;
440 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800443 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
445 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 case CMD_HANDLE_USSD_REQUEST: {
447 request = (MainThreadRequest) msg.obj;
448 final Phone phone = getPhoneFromRequest(request);
449 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
450 String ussdRequest = ussdObject.first;
451 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 if (!isUssdApiAllowed(request.subId)) {
454 // Carrier does not support use of this API, return failure.
455 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
456 UssdResponse response = new UssdResponse(ussdRequest, null);
457 Bundle returnData = new Bundle();
458 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
459 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700460
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 request.result = true;
462 notifyRequester(request);
463 return;
464 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700465
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 try {
467 request.result = phone != null
468 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
469 } catch (CallStateException cse) {
470 request.result = false;
471 }
472 // Wake up the requesting thread
473 notifyRequester(request);
474 break;
pkanwar32d516d2016-10-14 19:37:38 -0700475 }
476
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700479 final Phone phone = getPhoneFromRequest(request);
480 request.result = phone != null ?
481 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
482 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800491 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 if (uiccCard == null) {
493 loge("iccTransmitApduLogicalChannel: No UICC");
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700496 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
498 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700499 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 iccArgument.channel, iccArgument.cla, iccArgument.command,
501 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 break;
505
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6F, 0, (byte[])null);
513 if (ar.result == null) {
514 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800515 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800517 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700518 } else {
519 loge("iccTransmitApduLogicalChannel: Unknown exception");
520 }
521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 break;
524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
526 request = (MainThreadRequest) msg.obj;
527 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 if (uiccCard == null) {
530 loge("iccTransmitApduBasicChannel: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 } else {
534 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
535 request);
536 uiccCard.iccTransmitApduBasicChannel(
537 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
538 iccArgument.p3, iccArgument.data, onCompleted);
539 }
540 break;
541
542 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
547 } else {
548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("iccTransmitApduBasicChannel: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("iccTransmitApduBasicChannel: CommandException: " +
553 ar.exception);
554 } else {
555 loge("iccTransmitApduBasicChannel: Unknown exception");
556 }
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 break;
560
561 case CMD_EXCHANGE_SIM_IO:
562 request = (MainThreadRequest) msg.obj;
563 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 if (uiccCard == null) {
566 loge("iccExchangeSimIO: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
571 request);
572 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
573 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
574 iccArgument.data, onCompleted);
575 }
576 break;
577
578 case EVENT_EXCHANGE_SIM_IO_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
581 if (ar.exception == null && ar.result != null) {
582 request.result = ar.result;
583 } else {
584 request.result = new IccIoResult(0x6f, 0, (byte[])null);
585 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 break;
588
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 case CMD_SEND_ENVELOPE:
590 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800591 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 if (uiccCard == null) {
593 loge("sendEnvelopeWithStatus: No UICC");
594 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 } else {
597 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
598 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
599 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800600 break;
601
602 case EVENT_SEND_ENVELOPE_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("sendEnvelopeWithStatus: Empty response");
611 } else if (ar.exception instanceof CommandException) {
612 loge("sendEnvelopeWithStatus: CommandException: " +
613 ar.exception);
614 } else {
615 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
616 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800619 break;
620
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 case CMD_OPEN_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800624 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800627 request.result = new IccOpenLogicalChannelResponse(-1,
628 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800632 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
633 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case EVENT_OPEN_CHANNEL_DONE:
638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 int[] result = (int[]) ar.result;
643 int channelId = result[0];
644 byte[] selectResponse = null;
645 if (result.length > 1) {
646 selectResponse = new byte[result.length - 1];
647 for (int i = 1; i < result.length; ++i) {
648 selectResponse[i - 1] = (byte) result[i];
649 }
650 }
651 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700652 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 if (ar.result == null) {
655 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 if (ar.exception != null) {
658 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
659 }
660
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700661 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700662 if (ar.exception instanceof CommandException) {
663 CommandException.Error error =
664 ((CommandException) (ar.exception)).getCommandError();
665 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700667 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700668 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 }
670 }
671 openChannelResp = new IccOpenLogicalChannelResponse(
672 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700674 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case CMD_CLOSE_CHANNEL:
679 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800680 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 if (uiccCard == null) {
682 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900683 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 } else {
686 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
687 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
688 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
691 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800692 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
693 break;
694
695 case CMD_NV_READ_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800705 if (ar.exception == null && ar.result != null) {
706 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800708 request.result = "";
709 if (ar.result == null) {
710 loge("nvReadItem: Empty response");
711 } else if (ar.exception instanceof CommandException) {
712 loge("nvReadItem: CommandException: " +
713 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800715 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 }
717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
Jake Hambye994d462014-02-03 13:10:13 -0800721 case CMD_NV_WRITE_ITEM:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
724 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800725 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700726 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_WRITE_ITEM_DONE:
730 handleNullReturnEvent(msg, "nvWriteItem");
731 break;
732
733 case CMD_NV_WRITE_CDMA_PRL:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
739 case EVENT_NV_WRITE_CDMA_PRL_DONE:
740 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
741 break;
742
chen xu6dac5ab2018-10-26 17:39:23 -0700743 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800744 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700745 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800747 break;
748
chen xu6dac5ab2018-10-26 17:39:23 -0700749 case EVENT_RESET_MODEM_CONFIG_DONE:
750 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800751 break;
752
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 case CMD_GET_PREFERRED_NETWORK_TYPE:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 if (ar.exception == null && ar.result != null) {
763 request.result = ar.result; // Integer
764 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800765 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800766 if (ar.result == null) {
767 loge("getPreferredNetworkType: Empty response");
768 } else if (ar.exception instanceof CommandException) {
769 loge("getPreferredNetworkType: CommandException: " +
770 ar.exception);
771 } else {
772 loge("getPreferredNetworkType: Unknown exception");
773 }
774 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800776 break;
777
778 case CMD_SET_PREFERRED_NETWORK_TYPE:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
781 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700782 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800783 break;
784
785 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
786 handleNullReturnEvent(msg, "setPreferredNetworkType");
787 break;
788
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000789 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
790 request = (MainThreadRequest)msg.obj;
791 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000793 break;
794
795 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
796 ar = (AsyncResult)msg.obj;
797 request = (MainThreadRequest)ar.userObj;
798 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700799 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000800 break;
801
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800802 case CMD_SET_VOICEMAIL_NUMBER:
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
805 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800806 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
807 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800808 break;
809
810 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
811 handleNullReturnEvent(msg, "setVoicemailNumber");
812 break;
813
Stuart Scott54788802015-03-30 13:18:01 -0700814 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
817 request);
818 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
819 break;
820
821 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
822 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
823 break;
824
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 case CMD_PERFORM_NETWORK_SCAN:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
828 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
829 break;
830
Shuo Qian4a594052020-01-23 11:59:30 -0800831 case CMD_GET_CALL_FORWARDING:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
834 int callForwardingReason = (Integer) request.argument;
835 getPhoneFromRequest(request).getCallForwardingOption(
836 callForwardingReason, onCompleted);
837 break;
838
839 case EVENT_GET_CALL_FORWARDING_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 CallForwardingInfo callForwardingInfo = null;
843 if (ar.exception == null && ar.result != null) {
844 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
845 for (CallForwardInfo callForwardInfo : callForwardInfos) {
846 // Service Class is a bit mask per 3gpp 27.007. Search for
847 // any service for voice call.
848 if ((callForwardInfo.serviceClass
849 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
850 callForwardingInfo = new CallForwardingInfo(
851 callForwardInfo.serviceClass, callForwardInfo.reason,
852 callForwardInfo.number,
853 callForwardInfo.timeSeconds);
854 break;
855 }
856 }
857 // Didn't find a call forward info for voice call.
858 if (callForwardingInfo == null) {
859 callForwardingInfo = new CallForwardingInfo(
860 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
861 0 /* reason */, null /* number */, 0 /* timeout */);
862 }
863 } else {
864 if (ar.result == null) {
865 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
866 }
867 if (ar.exception != null) {
868 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
869 }
870 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
871 if (ar.exception instanceof CommandException) {
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
874 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
875 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
876 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
877 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
878 }
879 }
880 callForwardingInfo = new CallForwardingInfo(
881 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
882 }
883 request.result = callForwardingInfo;
884 notifyRequester(request);
885 break;
886
887 case CMD_SET_CALL_FORWARDING:
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
890 CallForwardingInfo callForwardingInfoToSet =
891 (CallForwardingInfo) request.argument;
892 getPhoneFromRequest(request).setCallForwardingOption(
893 callForwardingInfoToSet.getStatus(),
894 callForwardingInfoToSet.getReason(),
895 callForwardingInfoToSet.getNumber(),
896 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
897 break;
898
899 case EVENT_SET_CALL_FORWARDING_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null) {
903 request.result = true;
904 } else {
905 request.result = false;
906 loge("setCallForwarding exception: " + ar.exception);
907 }
908 notifyRequester(request);
909 break;
910
911 case CMD_GET_CALL_WAITING:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
914 getPhoneFromRequest(request).getCallWaiting(onCompleted);
915 break;
916
917 case EVENT_GET_CALL_WAITING_DONE:
918 ar = (AsyncResult) msg.obj;
919 request = (MainThreadRequest) ar.userObj;
920 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
921 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800922 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800923 // Service Class is a bit mask per 3gpp 27.007.
924 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800925 if (callForwardResults.length > 1
926 && ((callForwardResults[1]
927 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
928 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800929 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
930 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
931 } else {
932 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
933 }
934 } else {
935 if (ar.result == null) {
936 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
937 }
938 if (ar.exception != null) {
939 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
940 }
941 if (ar.exception instanceof CommandException) {
942 CommandException.Error error =
943 ((CommandException) (ar.exception)).getCommandError();
944 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
945 callForwardingStatus =
946 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
947 }
948 }
949 }
950 request.result = callForwardingStatus;
951 notifyRequester(request);
952 break;
953
954 case CMD_SET_CALL_WAITING:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
957 boolean isEnable = (Boolean) request.argument;
958 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
959 break;
960
961 case EVENT_SET_CALL_WAITING_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception == null) {
965 request.result = true;
966 } else {
967 request.result = false;
968 loge("setCallWaiting exception: " + ar.exception);
969 }
970 notifyRequester(request);
971 break;
972
Shishir Agrawal302c8692015-06-19 13:49:39 -0700973 case EVENT_PERFORM_NETWORK_SCAN_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 CellNetworkScanResult cellScanResult;
977 if (ar.exception == null && ar.result != null) {
978 cellScanResult = new CellNetworkScanResult(
979 CellNetworkScanResult.STATUS_SUCCESS,
980 (List<OperatorInfo>) ar.result);
981 } else {
982 if (ar.result == null) {
983 loge("getCellNetworkScanResults: Empty response");
984 }
985 if (ar.exception != null) {
986 loge("getCellNetworkScanResults: Exception: " + ar.exception);
987 }
988 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
994 } else if (error == CommandException.Error.GENERIC_FAILURE) {
995 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
996 }
997 }
998 cellScanResult = new CellNetworkScanResult(errorCode, null);
999 }
1000 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001001 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001002 break;
1003
1004 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1005 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001006 ManualNetworkSelectionArgument selArg =
1007 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001008 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1009 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001010 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1011 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001012 break;
1013
1014 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null) {
1018 request.result = true;
1019 } else {
1020 request.result = false;
1021 loge("setNetworkSelectionModeManual " + ar.exception);
1022 }
1023 notifyRequester(request);
1024 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001025 break;
1026
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001027 case CMD_GET_MODEM_ACTIVITY_INFO:
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001030 if (defaultPhone != null) {
1031 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001032 } else {
1033 ResultReceiver result = (ResultReceiver) request.argument;
1034 Bundle bundle = new Bundle();
1035 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1036 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1037 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001038 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001039 break;
1040
1041 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001044 ResultReceiver result = (ResultReceiver) request.argument;
1045
1046 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001047 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001048 // Update the last modem activity info and the result of the request.
1049 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1050 if (isModemActivityInfoValid(info)) {
1051 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1052 int[] txTimeMs = info.getTransmitTimeMillis();
1053 int[] lastModemTxTimeMs = mLastModemActivityInfo
1054 .getTransmitTimeMillis();
1055 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1056 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1057 }
1058 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1059 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1060 + mLastModemActivityInfo.getSleepTimeMillis());
1061 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1062 + mLastModemActivityInfo.getIdleTimeMillis());
1063 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1064 mLastModemActivityInfo.setReceiveTimeMillis(
1065 info.getReceiveTimeMillis()
1066 + mLastModemActivityInfo.getReceiveTimeMillis());
1067 }
1068 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1069 mLastModemActivityInfo.getSleepTimeMillis(),
1070 mLastModemActivityInfo.getIdleTimeMillis(),
1071 mLastModemActivityInfo.getTransmitTimeMillis(),
1072 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001073 } else {
1074 if (ar.result == null) {
1075 loge("queryModemActivityInfo: Empty response");
1076 } else if (ar.exception instanceof CommandException) {
1077 loge("queryModemActivityInfo: CommandException: " +
1078 ar.exception);
1079 } else {
1080 loge("queryModemActivityInfo: Unknown exception");
1081 }
1082 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001083 Bundle bundle = new Bundle();
1084 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1085 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001086 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001087 break;
1088
Meng Wang1a7c35a2016-05-05 20:56:15 -07001089 case CMD_SET_ALLOWED_CARRIERS:
1090 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001091 CarrierRestrictionRules argument =
1092 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001093 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001094 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001095 break;
1096
1097 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null && ar.result != null) {
1101 request.result = ar.result;
1102 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001103 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1104 if (ar.exception instanceof CommandException) {
1105 loge("setAllowedCarriers: CommandException: " + ar.exception);
1106 CommandException.Error error =
1107 ((CommandException) (ar.exception)).getCommandError();
1108 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1109 request.result =
1110 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1111 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001112 } else {
1113 loge("setAllowedCarriers: Unknown exception");
1114 }
1115 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001116 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001117 break;
1118
1119 case CMD_GET_ALLOWED_CARRIERS:
1120 request = (MainThreadRequest) msg.obj;
1121 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001122 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001123 break;
1124
1125 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
1128 if (ar.exception == null && ar.result != null) {
1129 request.result = ar.result;
1130 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001131 request.result = new IllegalStateException(
1132 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001133 if (ar.result == null) {
1134 loge("getAllowedCarriers: Empty response");
1135 } else if (ar.exception instanceof CommandException) {
1136 loge("getAllowedCarriers: CommandException: " +
1137 ar.exception);
1138 } else {
1139 loge("getAllowedCarriers: Unknown exception");
1140 }
1141 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001142 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001143 break;
1144
Nathan Haroldb3014052017-01-25 15:57:32 -08001145 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 } else {
1151 request.result = new IllegalArgumentException(
1152 "Failed to retrieve Forbidden Plmns");
1153 if (ar.result == null) {
1154 loge("getForbiddenPlmns: Empty response");
1155 } else {
1156 loge("getForbiddenPlmns: Unknown exception");
1157 }
1158 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001159 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001160 break;
1161
1162 case CMD_GET_FORBIDDEN_PLMNS:
1163 request = (MainThreadRequest) msg.obj;
1164 uiccCard = getUiccCardFromRequest(request);
1165 if (uiccCard == null) {
1166 loge("getForbiddenPlmns() UiccCard is null");
1167 request.result = new IllegalArgumentException(
1168 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001170 break;
1171 }
1172 Integer appType = (Integer) request.argument;
1173 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1174 if (uiccApp == null) {
1175 loge("getForbiddenPlmns() no app with specified type -- "
1176 + appType);
1177 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001178 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001179 break;
1180 } else {
1181 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1182 + " specified type -- " + appType);
1183 }
1184 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1185 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1186 onCompleted);
1187 break;
1188
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001189 case CMD_SWITCH_SLOTS:
1190 request = (MainThreadRequest) msg.obj;
1191 int[] physicalSlots = (int[]) request.argument;
1192 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1193 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1194 break;
1195
1196 case EVENT_SWITCH_SLOTS_DONE:
1197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
1199 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001200 notifyRequester(request);
1201 break;
1202 case CMD_GET_NETWORK_SELECTION_MODE:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1205 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1206 break;
1207
1208 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1209 ar = (AsyncResult) msg.obj;
1210 request = (MainThreadRequest) ar.userObj;
1211 if (ar.exception != null) {
1212 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1213 } else {
1214 int mode = ((int[]) ar.result)[0];
1215 if (mode == 0) {
1216 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1217 } else {
1218 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1219 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001220 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001221 notifyRequester(request);
1222 break;
1223 case CMD_GET_CDMA_ROAMING_MODE:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1226 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1227 break;
1228 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1229 ar = (AsyncResult) msg.obj;
1230 request = (MainThreadRequest) ar.userObj;
1231 if (ar.exception != null) {
1232 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1233 } else {
1234 request.result = ((int[]) ar.result)[0];
1235 }
1236 notifyRequester(request);
1237 break;
1238 case CMD_SET_CDMA_ROAMING_MODE:
1239 request = (MainThreadRequest) msg.obj;
1240 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1241 int mode = (int) request.argument;
1242 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1243 break;
1244 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1245 ar = (AsyncResult) msg.obj;
1246 request = (MainThreadRequest) ar.userObj;
1247 request.result = ar.exception == null;
1248 notifyRequester(request);
1249 break;
1250 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1251 request = (MainThreadRequest) msg.obj;
1252 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1253 int subscriptionMode = (int) request.argument;
1254 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1255 break;
1256 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
1259 request.result = ar.exception == null;
1260 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001261 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001262 case CMD_GET_ALL_CELL_INFO:
1263 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001265 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001267 case EVENT_GET_ALL_CELL_INFO_DONE:
1268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001270 // If a timeout occurs, the response will be null
1271 request.result = (ar.exception == null && ar.result != null)
1272 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001273 synchronized (request) {
1274 request.notifyAll();
1275 }
1276 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001277 case CMD_REQUEST_CELL_INFO_UPDATE:
1278 request = (MainThreadRequest) msg.obj;
1279 request.phone.requestCellInfoUpdate(request.workSource,
1280 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1281 break;
1282 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1283 ar = (AsyncResult) msg.obj;
1284 request = (MainThreadRequest) ar.userObj;
1285 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1286 try {
1287 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001288 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001289 cb.onError(
1290 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1291 ar.exception.getClass().getName(),
1292 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001295 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001296 } else {
1297 // use the result as returned
1298 cb.onCellInfo((List<CellInfo>) ar.result);
1299 }
1300 } catch (RemoteException re) {
1301 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1302 }
1303 break;
1304 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001305 request = (MainThreadRequest) msg.obj;
1306 WorkSource ws = (WorkSource) request.argument;
1307 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001308 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001310 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
1313 if (ar.exception == null) {
1314 request.result = ar.result;
1315 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001316 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001317 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001318 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001319 }
1320
1321 synchronized (request) {
1322 request.notifyAll();
1323 }
1324 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001325 case CMD_MODEM_REBOOT:
1326 request = (MainThreadRequest) msg.obj;
1327 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001328 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001329 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001330 case EVENT_CMD_MODEM_REBOOT_DONE:
1331 handleNullReturnEvent(msg, "rebootModem");
1332 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001333 case CMD_REQUEST_ENABLE_MODEM:
1334 request = (MainThreadRequest) msg.obj;
1335 boolean enable = (boolean) request.argument;
1336 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001337 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001338 PhoneConfigurationManager.getInstance()
1339 .enablePhone(request.phone, enable, onCompleted);
1340 break;
1341 case EVENT_ENABLE_MODEM_DONE:
1342 ar = (AsyncResult) msg.obj;
1343 request = (MainThreadRequest) ar.userObj;
1344 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001345 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001346 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001347 if ((boolean) request.result) {
1348 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1349 updateModemStateMetrics();
1350 } else {
1351 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1352 + ar.exception);
1353 }
1354 notifyRequester(request);
1355 break;
1356 case CMD_GET_MODEM_STATUS:
1357 request = (MainThreadRequest) msg.obj;
1358 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1359 PhoneConfigurationManager.getInstance()
1360 .getPhoneStatusFromModem(request.phone, onCompleted);
1361 break;
1362 case EVENT_GET_MODEM_STATUS_DONE:
1363 ar = (AsyncResult) msg.obj;
1364 request = (MainThreadRequest) ar.userObj;
1365 int id = request.phone.getPhoneId();
1366 if (ar.exception == null && ar.result != null) {
1367 request.result = ar.result;
1368 //update the cache as modem status has changed
1369 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1370 (boolean) request.result);
1371 } else {
1372 // Return true if modem status cannot be retrieved. For most cases,
1373 // modem status is on. And for older version modems, GET_MODEM_STATUS
1374 // and disable modem are not supported. Modem is always on.
1375 // TODO: this should be fixed in R to support a third
1376 // status UNKNOWN b/131631629
1377 request.result = true;
1378 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1379 + ar.exception);
1380 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001381 notifyRequester(request);
1382 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001383 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1384 request = (MainThreadRequest) msg.obj;
1385 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1386 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1387 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1388 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1389 break;
1390 }
1391 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1392 ar = (AsyncResult) msg.obj;
1393 request = (MainThreadRequest) ar.userObj;
1394 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1395 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1396 args.second.accept(ar.exception == null);
1397 notifyRequester(request);
1398 break;
1399 }
yincheng zhao2737e882019-09-06 17:06:54 -07001400 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 if (ar.exception == null && ar.result != null) {
1404 request.result = ar.result;
1405 } else {
1406 request.result = -1;
1407 loge("Failed to set Forbidden Plmns");
1408 if (ar.result == null) {
1409 loge("setForbidenPlmns: Empty response");
1410 } else if (ar.exception != null) {
1411 loge("setForbiddenPlmns: Exception: " + ar.exception);
1412 request.result = -1;
1413 } else {
1414 loge("setForbiddenPlmns: Unknown exception");
1415 }
1416 }
1417 notifyRequester(request);
1418 break;
1419 case CMD_SET_FORBIDDEN_PLMNS:
1420 request = (MainThreadRequest) msg.obj;
1421 uiccCard = getUiccCardFromRequest(request);
1422 if (uiccCard == null) {
1423 loge("setForbiddenPlmns: UiccCard is null");
1424 request.result = -1;
1425 notifyRequester(request);
1426 break;
1427 }
1428 Pair<Integer, List<String>> setFplmnsArgs =
1429 (Pair<Integer, List<String>>) request.argument;
1430 appType = setFplmnsArgs.first;
1431 List<String> fplmns = setFplmnsArgs.second;
1432 uiccApp = uiccCard.getApplicationByType(appType);
1433 if (uiccApp == null) {
1434 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1435 request.result = -1;
1436 loge("Failed to get UICC App");
1437 notifyRequester(request);
1438 } else {
1439 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1440 ((SIMRecords) uiccApp.getIccRecords())
1441 .setForbiddenPlmns(onCompleted, fplmns);
1442 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001443 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001444 case CMD_ERASE_MODEM_CONFIG:
1445 request = (MainThreadRequest) msg.obj;
1446 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1447 defaultPhone.eraseModemConfig(onCompleted);
1448 break;
1449 case EVENT_ERASE_MODEM_CONFIG_DONE:
1450 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001451 break;
zoey chene02881a2019-12-30 16:11:23 +08001452
1453 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1456 Pair<String, String> changed = (Pair<String, String>) request.argument;
1457 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1458 changed.first, changed.second, onCompleted);
1459 break;
1460 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
1463 if (ar.exception == null) {
1464 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1465 } else {
1466 request.result = msg.arg1;
1467 }
1468 notifyRequester(request);
1469 break;
1470
1471 case CMD_SET_ICC_LOCK_ENABLED:
1472 request = (MainThreadRequest) msg.obj;
1473 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1474 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1475 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1476 enabled.first, enabled.second, onCompleted);
1477 break;
1478 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 if (ar.exception == null) {
1482 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1483 } else {
1484 request.result = msg.arg1;
1485 }
1486 notifyRequester(request);
1487 break;
1488
Peter Wangdafb9ac2020-01-15 14:13:38 -08001489 case MSG_NOTIFY_USER_ACTIVITY:
1490 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001491 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001492 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1493 getDefaultPhone().getContext().sendBroadcastAsUser(
1494 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1495 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 default:
1497 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1498 break;
1499 }
1500 }
Jake Hambye994d462014-02-03 13:10:13 -08001501
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 private void notifyRequester(MainThreadRequest request) {
1503 synchronized (request) {
1504 request.notifyAll();
1505 }
1506 }
1507
Jake Hambye994d462014-02-03 13:10:13 -08001508 private void handleNullReturnEvent(Message msg, String command) {
1509 AsyncResult ar = (AsyncResult) msg.obj;
1510 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception == null) {
1512 request.result = true;
1513 } else {
1514 request.result = false;
1515 if (ar.exception instanceof CommandException) {
1516 loge(command + ": CommandException: " + ar.exception);
1517 } else {
1518 loge(command + ": Unknown exception");
1519 }
1520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 }
1524
1525 /**
1526 * Posts the specified command to be executed on the main thread,
1527 * waits for the request to complete, and returns the result.
1528 * @see #sendRequestAsync
1529 */
1530 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001531 return sendRequest(
1532 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001533 }
1534
1535 /**
1536 * Posts the specified command to be executed on the main thread,
1537 * waits for the request to complete, and returns the result.
1538 * @see #sendRequestAsync
1539 */
1540 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1541 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001542 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
1545 /**
1546 * Posts the specified command to be executed on the main thread,
1547 * waits for the request to complete, and returns the result.
1548 * @see #sendRequestAsync
1549 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001550 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001551 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001552 }
1553
1554 /**
1555 * Posts the specified command to be executed on the main thread,
1556 * waits for the request to complete, and returns the result.
1557 * @see #sendRequestAsync
1558 */
Nathan Harold92bed182018-10-12 18:16:49 -07001559 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1560 return sendRequest(command, argument, subId, null, workSource);
1561 }
1562
1563 /**
1564 * Posts the specified command to be executed on the main thread,
1565 * waits for the request to complete, and returns the result.
1566 * @see #sendRequestAsync
1567 */
1568 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1569 return sendRequest(
1570 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1571 }
1572
1573 /**
1574 * Posts the specified command to be executed on the main thread,
1575 * waits for the request to complete, and returns the result.
1576 * @see #sendRequestAsync
1577 */
1578 private Object sendRequest(
1579 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1581 throw new RuntimeException("This method will deadlock if called from the main thread.");
1582 }
1583
Nathan Harold92bed182018-10-12 18:16:49 -07001584 MainThreadRequest request = null;
1585 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1586 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1587 } else if (phone != null) {
1588 request = new MainThreadRequest(argument, phone, workSource);
1589 } else {
1590 request = new MainThreadRequest(argument, subId, workSource);
1591 }
1592
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 Message msg = mMainThreadHandler.obtainMessage(command, request);
1594 msg.sendToTarget();
1595
1596 // Wait for the request to complete
1597 synchronized (request) {
1598 while (request.result == null) {
1599 try {
1600 request.wait();
1601 } catch (InterruptedException e) {
1602 // Do nothing, go back and wait until the request is complete
1603 }
1604 }
1605 }
1606 return request.result;
1607 }
1608
1609 /**
1610 * Asynchronous ("fire and forget") version of sendRequest():
1611 * Posts the specified command to be executed on the main thread, and
1612 * returns immediately.
1613 * @see #sendRequest
1614 */
1615 private void sendRequestAsync(int command) {
1616 mMainThreadHandler.sendEmptyMessage(command);
1617 }
1618
1619 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001620 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001621 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001622 */
1623 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001624 sendRequestAsync(command, argument, null, null);
1625 }
1626
1627 /**
1628 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1629 * @see {@link #sendRequest(int,Object)}
1630 */
1631 private void sendRequestAsync(
1632 int command, Object argument, Phone phone, WorkSource workSource) {
1633 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001634 Message msg = mMainThreadHandler.obtainMessage(command, request);
1635 msg.sendToTarget();
1636 }
1637
1638 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 * Initialize the singleton PhoneInterfaceManager instance.
1640 * This is only done once, at startup, from PhoneApp.onCreate().
1641 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001642 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 synchronized (PhoneInterfaceManager.class) {
1644 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001645 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 } else {
1647 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1648 }
1649 return sInstance;
1650 }
1651 }
1652
1653 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001654 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001657 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001658 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1660 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001661 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001662 mTelephonySharedPreferences =
1663 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001664 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001665 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001666 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 publish();
1669 }
1670
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001671 private Phone getDefaultPhone() {
1672 Phone thePhone = getPhone(getDefaultSubscription());
1673 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 private void publish() {
1677 if (DBG) log("publish: " + this);
1678
Peter Wangc035ce42020-01-08 21:00:22 -08001679 TelephonyFrameworkInitializer
1680 .getTelephonyServiceManager()
1681 .getTelephonyServiceRegisterer()
1682 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
Stuart Scott584921c2015-01-15 17:10:34 -08001685 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001686 if (request.phone != null) {
1687 return request.phone;
1688 } else {
1689 return getPhoneFromSubId(request.subId);
1690 }
1691 }
1692
1693 private Phone getPhoneFromSubId(int subId) {
1694 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1695 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001696 }
1697
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001698 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1699 Phone phone = getPhoneFromRequest(request);
1700 return phone == null ? null :
1701 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1702 }
1703
Wink Saville36469e72014-06-11 15:17:00 -07001704 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001705 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001706 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708
Naina Nallurid63128d2019-09-17 14:10:30 -07001709 private void sendEraseModemConfig(Phone phone) {
1710 if (phone != null) {
1711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1712 mApp, phone.getSubId(), "eraseModemConfig");
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1716 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
1720 }
1721 }
1722
Peter Wang44b186e2020-01-13 23:33:09 -08001723 private boolean isImsAvailableOnDevice() {
1724 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1725 if (pm == null) {
1726 // For some reason package manger is not available.. This will fail internally anyway,
1727 // so do not throw error and allow.
1728 return true;
1729 }
1730 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1731 }
1732
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001734 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001735 }
1736
Wink Savilleb564aae2014-10-23 10:18:09 -07001737 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 if (DBG) log("dial: " + number);
1739 // No permission check needed here: This is just a wrapper around the
1740 // ACTION_DIAL intent, which is available to any app since it puts up
1741 // the UI before it does anything.
1742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 String url = createTelUrl(number);
1746 if (url == null) {
1747 return;
1748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 // PENDING: should we just silently fail if phone is offhook or ringing?
1751 PhoneConstants.State state = mCM.getState(subId);
1752 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1753 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1754 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1755 mApp.startActivity(intent);
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760 }
1761
1762 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001763 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001764 }
1765
Wink Savilleb564aae2014-10-23 10:18:09 -07001766 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 if (DBG) log("call: " + number);
1768
1769 // This is just a wrapper around the ACTION_CALL intent, but we still
1770 // need to do a permission check since we're calling startActivity()
1771 // from the context of the phone app.
1772 enforceCallPermission();
1773
Jordan Liu1617b712019-07-10 15:06:26 -07001774 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 != AppOpsManager.MODE_ALLOWED) {
1776 return;
1777 }
1778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 String url = createTelUrl(number);
1782 if (url == null) {
1783 return;
1784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 boolean isValid = false;
1787 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1788 if (slist != null) {
1789 for (SubscriptionInfo subInfoRecord : slist) {
1790 if (subInfoRecord.getSubscriptionId() == subId) {
1791 isValid = true;
1792 break;
1793 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001794 }
Wink Saville08874612014-08-31 19:19:58 -07001795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 if (!isValid) {
1797 return;
1798 }
Wink Saville08874612014-08-31 19:19:58 -07001799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1801 intent.putExtra(SUBSCRIPTION_KEY, subId);
1802 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1803 mApp.startActivity(intent);
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
1806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Wink Savilleb564aae2014-10-23 10:18:09 -07001809 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001811 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1812 }
1813
Wink Savilleb564aae2014-10-23 10:18:09 -07001814 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001815 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001816 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1817 }
1818
Wink Savilleb564aae2014-10-23 10:18:09 -07001819 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1825 checkSimPin.start();
1826 return checkSimPin.unlockSim(null, pin);
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
1829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1838 checkSimPuk.start();
1839 return checkSimPuk.unlockSim(puk, pin);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001846 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 * a synchronous one.
1848 */
1849 private static class UnlockSim extends Thread {
1850
1851 private final IccCard mSimCard;
1852
1853 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001854 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1855 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856
1857 // For replies from SimCard interface
1858 private Handler mHandler;
1859
1860 // For async handler to identify request type
1861 private static final int SUPPLY_PIN_COMPLETE = 100;
1862
1863 public UnlockSim(IccCard simCard) {
1864 mSimCard = simCard;
1865 }
1866
1867 @Override
1868 public void run() {
1869 Looper.prepare();
1870 synchronized (UnlockSim.this) {
1871 mHandler = new Handler() {
1872 @Override
1873 public void handleMessage(Message msg) {
1874 AsyncResult ar = (AsyncResult) msg.obj;
1875 switch (msg.what) {
1876 case SUPPLY_PIN_COMPLETE:
1877 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1878 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001879 mRetryCount = msg.arg1;
1880 if (ar.exception != null) {
1881 if (ar.exception instanceof CommandException &&
1882 ((CommandException)(ar.exception)).getCommandError()
1883 == CommandException.Error.PASSWORD_INCORRECT) {
1884 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1885 } else {
1886 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1887 }
1888 } else {
1889 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mDone = true;
1892 UnlockSim.this.notifyAll();
1893 }
1894 break;
1895 }
1896 }
1897 };
1898 UnlockSim.this.notifyAll();
1899 }
1900 Looper.loop();
1901 }
1902
1903 /*
1904 * Use PIN or PUK to unlock SIM card
1905 *
1906 * If PUK is null, unlock SIM card with PIN
1907 *
1908 * If PUK is not null, unlock SIM card with PUK and set PIN code
1909 */
Wink Saville9de0f752013-10-22 19:04:03 -07001910 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911
1912 while (mHandler == null) {
1913 try {
1914 wait();
1915 } catch (InterruptedException e) {
1916 Thread.currentThread().interrupt();
1917 }
1918 }
1919 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1920
1921 if (puk == null) {
1922 mSimCard.supplyPin(pin, callback);
1923 } else {
1924 mSimCard.supplyPuk(puk, pin, callback);
1925 }
1926
1927 while (!mDone) {
1928 try {
1929 Log.d(LOG_TAG, "wait for done");
1930 wait();
1931 } catch (InterruptedException e) {
1932 // Restore the interrupted status
1933 Thread.currentThread().interrupt();
1934 }
1935 }
1936 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001937 int[] resultArray = new int[2];
1938 resultArray[0] = mResult;
1939 resultArray[1] = mRetryCount;
1940 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942 }
1943
1944 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001945 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001946
1947 }
1948
Wink Savilleb564aae2014-10-23 10:18:09 -07001949 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 // No permission check needed here: this call is harmless, and it's
1951 // needed for the ServiceState.requestStateUpdate() call (which is
1952 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 final long identity = Binder.clearCallingIdentity();
1954 try {
1955 final Phone phone = getPhone(subId);
1956 if (phone != null) {
1957 phone.updateServiceLocation();
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001964 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 @Override
1966 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001967 return isRadioOnWithFeature(callingPackage, null);
1968 }
1969
1970
1971 @Override
1972 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1973 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1974 callingFeatureId);
1975 }
1976
1977 @Deprecated
1978 @Override
1979 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1980 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001981 }
1982
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001984 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1985 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001987 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 return false;
1989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990
1991 final long identity = Binder.clearCallingIdentity();
1992 try {
1993 return isRadioOnForSubscriber(subId);
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001997 }
1998
1999 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2005 } else {
2006 return false;
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002014 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
Wink Saville36469e72014-06-11 15:17:00 -07002016
Wink Savilleb564aae2014-10-23 10:18:09 -07002017 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 final Phone phone = getPhone(subId);
2023 if (phone != null) {
2024 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2025 }
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002028 }
Wink Saville36469e72014-06-11 15:17:00 -07002029 }
2030
2031 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002032 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002033 }
2034
Wink Savilleb564aae2014-10-23 10:18:09 -07002035 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002036 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037
2038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 final Phone phone = getPhone(subId);
2041 if (phone == null) {
2042 return false;
2043 }
2044 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2045 toggleRadioOnOffForSubscriber(subId);
2046 }
2047 return true;
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
Wink Saville36469e72014-06-11 15:17:00 -07002052
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002053 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002054 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002055 /*
2056 * If any of the Radios are available, it will need to be
2057 * shutdown. So return true if any Radio is available.
2058 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2062 Phone phone = PhoneFactory.getPhone(i);
2063 if (phone != null && phone.isRadioAvailable()) return true;
2064 }
2065 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2066 return false;
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002069 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002070 }
2071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002073 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 enforceModifyPermission();
2075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2079 logv("Shutting down Phone " + i);
2080 shutdownRadioUsingPhoneId(i);
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002084 }
2085 }
2086
2087 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002088 Phone phone = PhoneFactory.getPhone(phoneId);
2089 if (phone != null && phone.isRadioAvailable()) {
2090 phone.shutdownRadio();
2091 }
2092 }
2093
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002095 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2100 if (defaultPhone != null) {
2101 defaultPhone.setRadioPower(turnOn);
2102 return true;
2103 } else {
2104 loge("There's no default phone.");
2105 return false;
2106 }
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002109 }
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
Wink Savilleb564aae2014-10-23 10:18:09 -07002112 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 final Phone phone = getPhone(subId);
2118 if (phone != null) {
2119 phone.setRadioPower(turnOn);
2120 return true;
2121 } else {
2122 return false;
2123 }
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Wink Saville36469e72014-06-11 15:17:00 -07002129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 public boolean enableDataConnectivity() {
2132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 int subId = mSubscriptionController.getDefaultDataSubId();
2137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002139 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 return true;
2141 } else {
2142 return false;
2143 }
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 }
2148
Wink Saville36469e72014-06-11 15:17:00 -07002149 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002150 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 public boolean disableDataConnectivity() {
2152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
2156 int subId = mSubscriptionController.getDefaultDataSubId();
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002159 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 return true;
2161 } else {
2162 return false;
2163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002170 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002175 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 } else {
2177 return false;
2178 }
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
2184 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002185 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
pkanwarae03a6b2016-11-06 20:37:09 -08002188 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 enforceCallPermission();
2190
2191 final long identity = Binder.clearCallingIdentity();
2192 try {
2193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2194 return;
2195 }
2196 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2197 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
pkanwar32d516d2016-10-14 19:37:38 -07002201 };
2202
Wink Savilleb564aae2014-10-23 10:18:09 -07002203 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2209 return false;
2210 }
2211 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002218 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002221 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 Phone phone = PhoneFactory.getPhone(slotIndex);
2225 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2226 PhoneConstantConversions.convertCallState(phone.getState());
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002233 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002234 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2235 }
2236
2237 @Override
2238 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002241 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 if (phone != null) {
2243 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2244 } else {
2245 return PhoneConstantConversions.convertDataState(
2246 PhoneConstants.DataState.DISCONNECTED);
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002254 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002255 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2256 }
2257
2258 @Override
2259 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002262 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 if (phone != null) {
2264 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2265 } else {
2266 return TelephonyManager.DATA_ACTIVITY_NONE;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002274 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002276 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002277
2278 LocationAccessPolicy.LocationPermissionResult locationResult =
2279 LocationAccessPolicy.checkLocationPermission(mApp,
2280 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2281 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002282 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002283 .setCallingPid(Binder.getCallingPid())
2284 .setCallingUid(Binder.getCallingUid())
2285 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002286 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002287 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2288 .build());
2289 switch (locationResult) {
2290 case DENIED_HARD:
2291 throw new SecurityException("Not allowed to access cell location");
2292 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002293 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2294 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002301 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002302 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Svetoslav64fad262015-04-14 14:35:21 -07002306 }
2307
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002309 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002310 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2311 // registered cell info, so return a NULL country instead.
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002314 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2315 // Get default phone in this case.
2316 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2317 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002319 // Todo: fix this when we can get the actual cellular network info when the device
2320 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002321 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002322 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08002323 mApp.getAttributionTag())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002324 return "";
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 Phone phone = PhoneFactory.getPhone(phoneId);
2327 if (phone != null) {
2328 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002329 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330 if (sst != null) {
2331 LocaleTracker lt = sst.getLocaleTracker();
2332 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002333 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2334 return lt.getCurrentCountry();
2335 } else if (emergencyNumberTracker != null) {
2336 return emergencyNumberTracker.getEmergencyCountryIso();
2337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 }
2339 }
2340 }
2341 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002345 }
2346
2347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002349 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002350 }
2351
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 mApp.enforceCallingOrSelfPermission(
2355 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 phone.enableLocationUpdates();
2362 }
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
2368 @Override
2369 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002370 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002371 }
2372
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002374 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 mApp.enforceCallingOrSelfPermission(
2376 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 if (phone != null) {
2382 phone.disableLocationUpdates();
2383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
Nathan Harold31d7ff32018-10-15 20:20:30 -07002389 /**
2390 * Returns the target SDK version number for a given package name.
2391 *
Nathan Haroldec184742019-07-10 17:04:16 -07002392 * This call MUST be invoked before clearing the calling UID.
2393 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002394 * @return target SDK if the package is found or INT_MAX.
2395 */
2396 private int getTargetSdk(String packageName) {
2397 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002398 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002399 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002400 if (ai != null) return ai.targetSdkVersion;
2401 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002402 loge("Failed to get package info for pkg="
2403 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002404 }
2405 return Integer.MAX_VALUE;
2406 }
2407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 @Override
2409 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002410 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2411 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002412 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002413 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2414 throw new SecurityException(
2415 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2416 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002417
Jordan Liu1617b712019-07-10 15:06:26 -07002418 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2420 return null;
2421 }
Svetoslav64fad262015-04-14 14:35:21 -07002422
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002423 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002425 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002426 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427
Nathan Haroldf180aac2018-06-01 18:43:55 -07002428 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2429 for (CellInfo ci : info) {
2430 if (ci instanceof CellInfoGsm) {
2431 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2432 } else if (ci instanceof CellInfoWcdma) {
2433 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002436 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 private List<CellInfo> getCachedCellInfo() {
2440 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2441 for (Phone phone : PhoneFactory.getPhones()) {
2442 List<CellInfo> info = phone.getAllCellInfo();
2443 if (info != null) cellInfos.addAll(info);
2444 }
2445 return cellInfos;
2446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447
2448 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002449 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002450 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002451 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002452
2453 LocationAccessPolicy.LocationPermissionResult locationResult =
2454 LocationAccessPolicy.checkLocationPermission(mApp,
2455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2456 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002457 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002458 .setCallingPid(Binder.getCallingPid())
2459 .setCallingUid(Binder.getCallingUid())
2460 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002462 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2463 .build());
2464 switch (locationResult) {
2465 case DENIED_HARD:
2466 throw new SecurityException("Not allowed to access cell info");
2467 case DENIED_SOFT:
2468 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002471 final int targetSdk = getTargetSdk(callingPackage);
2472 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2473 return getCachedCellInfo();
2474 }
2475
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002476 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2481 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002482 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002483 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 if (info != null) cellInfos.addAll(info);
2485 }
2486 return cellInfos;
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490 }
2491
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002492 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002493 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2494 String callingFeatureId) {
2495 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2496 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 }
2498
2499 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2501 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002502 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002503 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002504 }
2505
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002506 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2507 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002508 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002509 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002510
2511 LocationAccessPolicy.LocationPermissionResult locationResult =
2512 LocationAccessPolicy.checkLocationPermission(mApp,
2513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2514 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002515 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 .setCallingPid(Binder.getCallingPid())
2517 .setCallingUid(Binder.getCallingUid())
2518 .setMethod("requestCellInfoUpdate")
2519 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2520 .build());
2521 switch (locationResult) {
2522 case DENIED_HARD:
2523 throw new SecurityException("Not allowed to access cell info");
2524 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002525 try {
2526 cb.onCellInfo(new ArrayList<CellInfo>());
2527 } catch (RemoteException re) {
2528 // Drop without consequences
2529 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002530 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002531 }
2532
Nathan Harolda939a962019-05-09 10:13:47 -07002533
2534 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002535 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2536
2537 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2538 }
2539
2540 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002542 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002547 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552
Shishir Agrawala9f32182016-04-12 12:00:16 -07002553 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002554 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002555 Phone phone = PhoneFactory.getPhone(slotIndex);
2556 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 return null;
2558 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002560 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 return null;
2563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 return phone.getImei();
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002571 }
2572
2573 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002574 public String getTypeAllocationCodeForSlot(int slotIndex) {
2575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 String tac = null;
2577 if (phone != null) {
2578 String imei = phone.getImei();
2579 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2580 }
2581 return tac;
2582 }
2583
2584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002585 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002586 Phone phone = PhoneFactory.getPhone(slotIndex);
2587 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002588 return null;
2589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002590
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002592 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002593 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 return null;
2595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 return phone.getMeid();
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Jack Yu2af8d712017-03-15 17:14:14 -07002603 }
2604
2605 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002606 public String getManufacturerCodeForSlot(int slotIndex) {
2607 Phone phone = PhoneFactory.getPhone(slotIndex);
2608 String manufacturerCode = null;
2609 if (phone != null) {
2610 String meid = phone.getMeid();
2611 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2612 }
2613 return manufacturerCode;
2614 }
2615
2616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002617 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2618 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002619 Phone phone = PhoneFactory.getPhone(slotIndex);
2620 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 return null;
2622 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002623 int subId = phone.getSubId();
2624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002625 mApp, subId, callingPackage, callingFeatureId,
2626 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002627 return null;
2628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 return phone.getDeviceSvn();
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002636 }
2637
fionaxu43304da2017-11-27 22:51:16 -08002638 @Override
2639 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
fionaxu43304da2017-11-27 22:51:16 -08002647 }
2648
2649 @Override
2650 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 return phone == null ? null : phone.getCarrierName();
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
fionaxu43304da2017-11-27 22:51:16 -08002658 }
2659
calvinpanffe225e2018-11-01 19:43:06 +08002660 @Override
chen xu0026ca62019-03-06 15:28:50 -08002661 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002666 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
2670 }
2671
2672 @Override
chen xu0026ca62019-03-06 15:28:50 -08002673 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002677 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
2681 }
2682
chen xu651eec72018-11-11 19:03:44 -08002683 @Override
chen xu864e11c2018-12-06 22:10:03 -08002684 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2685 if (!isSubscriptionMccMnc) {
2686 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2687 }
chen xu651eec72018-11-11 19:03:44 -08002688 final Phone phone = PhoneFactory.getPhone(slotIndex);
2689 if (phone == null) {
2690 return TelephonyManager.UNKNOWN_CARRIER_ID;
2691 }
2692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
2698 }
2699
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 //
2701 // Internal helper methods.
2702 //
2703
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002704 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceModifyPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2711 }
2712
Shuo Qiancd19c462020-01-16 20:51:11 -08002713 /**
2714 * Make sure the caller is system.
2715 *
2716 * @throws SecurityException if the caller is not system.
2717 */
2718 private void enforceSystemCaller() {
2719 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2720 throw new SecurityException("Caller must be system");
2721 }
2722 }
2723
Shuo Qian3b6ee772019-11-13 17:43:31 -08002724 private void enforceActiveEmergencySessionPermission() {
2725 mApp.enforceCallingOrSelfPermission(
2726 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2727 }
2728
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 /**
2730 * Make sure the caller has the CALL_PHONE permission.
2731 *
2732 * @throws SecurityException if the caller does not have the required permission
2733 */
2734 private void enforceCallPermission() {
2735 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2736 }
2737
paulhu5a773602019-08-23 19:17:33 +08002738 private void enforceSettingsPermission() {
2739 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002740 }
2741
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 private String createTelUrl(String number) {
2743 if (TextUtils.isEmpty(number)) {
2744 return null;
2745 }
2746
Jake Hambye994d462014-02-03 13:10:13 -08002747 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
2749
Ihab Awadf9e92732013-12-05 18:02:52 -08002750 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2752 }
2753
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002754 private static void logv(String msg) {
2755 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2756 }
2757
Ihab Awadf9e92732013-12-05 18:02:52 -08002758 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2760 }
2761
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002764 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002768 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 final Phone phone = PhoneFactory.getPhone(slotIndex);
2772 if (phone == null) {
2773 return PhoneConstants.PHONE_TYPE_NONE;
2774 } else {
2775 return phone.getPhoneType();
2776 }
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
2782 /**
2783 * Returns the CDMA ERI icon index to display
2784 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002786 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2787 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2788 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002792 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 mApp, subId, callingPackage, callingFeatureId,
2796 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002797 return -1;
2798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
2804 return phone.getCdmaEriIconIndex();
2805 } else {
2806 return -1;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
2813 /**
2814 * Returns the CDMA ERI icon mode,
2815 * 0 - ON
2816 * 1 - FLASHING
2817 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2820 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2821 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2826 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002828 mApp, subId, callingPackage, callingFeatureId,
2829 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002830 return -1;
2831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 return phone.getCdmaEriIconMode();
2838 } else {
2839 return -1;
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
2846 /**
2847 * Returns the CDMA ERI text,
2848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002850 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2851 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002853 }
2854
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 mApp, subId, callingPackage, callingFeatureId,
2860 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002861 return null;
2862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 final Phone phone = getPhone(subId);
2867 if (phone != null) {
2868 return phone.getCdmaEriText();
2869 } else {
2870 return null;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
2876
2877 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002878 * Returns the CDMA MDN.
2879 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002880 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002881 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2883 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002888 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 return phone.getLine1Number();
2890 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 return null;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002896 }
2897 }
2898
2899 /**
2900 * Returns the CDMA MIN.
2901 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002902 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002903 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2905 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2911 return phone.getCdmaMin();
2912 } else {
2913 return null;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002917 }
2918 }
2919
Hall Liud892bec2018-11-30 14:51:45 -08002920 @Override
2921 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2922 INumberVerificationCallback callback, String callingPackage) {
2923 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2924 != PERMISSION_GRANTED) {
2925 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2926 }
2927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2928
2929 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2930 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2931 throw new SecurityException("Calling package must be configured in the device config");
2932 }
2933
2934 if (range == null) {
2935 throw new NullPointerException("Range must be non-null");
2936 }
2937
2938 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002939 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002940
2941 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2942 }
2943
Junda Liuca05d5d2014-08-14 22:36:34 -07002944 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 * Returns true if CDMA provisioning needs to run.
2946 */
2947 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 final long identity = Binder.clearCallingIdentity();
2949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 }
2955
2956 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002957 * Sets the voice mail number of a given subId.
2958 */
2959 @Override
2960 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002961 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2962 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2967 new Pair<String, String>(alphaTag, number), new Integer(subId));
2968 return success;
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002972 }
2973
Ta-wei Yen87c49842016-05-13 21:19:52 -07002974 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002975 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002977 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2978 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002979 if (!TextUtils.equals(callingPackage, systemDialer)) {
2980 throw new SecurityException("caller must be system dialer");
2981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2986 if (phoneAccountHandle == null) {
2987 return null;
2988 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002992 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002993 }
2994
2995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002996 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2997 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003000 mApp, subId, callingPackage, callingFeatureId,
3001 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003002 return null;
3003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003005 final long identity = Binder.clearCallingIdentity();
3006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003011 }
3012
3013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003014 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3015 VisualVoicemailSmsFilterSettings settings) {
3016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003021 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003025 }
3026
3027 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003028 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003038 }
3039
3040 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003041 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3042 String callingPackage, int subId) {
3043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003052 }
3053
3054 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003055 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003065 }
3066
3067 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003068 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3069 String callingAttributionTag, int subId, String number, int port, String text,
3070 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003071 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003072 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003073 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003074 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003075 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3076 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003077 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003078
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003079 /**
fionaxu0152e512016-11-14 13:36:14 -08003080 * Sets the voice activation state of a given subId.
3081 */
3082 @Override
3083 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3085 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003086
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 final Phone phone = getPhone(subId);
3090 if (phone != null) {
3091 phone.setVoiceActivationState(activationState);
3092 } else {
3093 loge("setVoiceActivationState fails with invalid subId: " + subId);
3094 }
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003097 }
3098 }
3099
3100 /**
3101 * Sets the data activation state of a given subId.
3102 */
3103 @Override
3104 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3106 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 final Phone phone = getPhone(subId);
3111 if (phone != null) {
3112 phone.setDataActivationState(activationState);
3113 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003114 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 }
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003118 }
3119 }
3120
3121 /**
3122 * Returns the voice activation state of a given subId.
3123 */
3124 @Override
3125 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127
fionaxu0152e512016-11-14 13:36:14 -08003128 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 if (phone != null) {
3132 return phone.getVoiceActivationState();
3133 } else {
3134 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3135 }
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003138 }
3139 }
3140
3141 /**
3142 * Returns the data activation state of a given subId.
3143 */
3144 @Override
3145 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003146 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147
fionaxu0152e512016-11-14 13:36:14 -08003148 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 if (phone != null) {
3152 return phone.getDataActivationState();
3153 } else {
3154 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003158 }
3159 }
3160
3161 /**
Wink Saville36469e72014-06-11 15:17:00 -07003162 * Returns the unread count of voicemails for a subId
3163 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003165 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3166 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003168 mApp, subId, callingPackage, callingFeatureId,
3169 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003170 return 0;
3171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 final long identity = Binder.clearCallingIdentity();
3173 try {
3174 final Phone phone = getPhone(subId);
3175 if (phone != null) {
3176 return phone.getVoiceMessageCount();
3177 } else {
3178 return 0;
3179 }
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 }
3184
3185 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003186 * returns true, if the device is in a state where both voice and data
3187 * are supported simultaneously. This can change based on location or network condition.
3188 */
3189 @Override
3190 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 final Phone phone = getPhone(subId);
3194 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003198 }
3199
3200 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003201 * Send the dialer code if called from the current default dialer or the caller has
3202 * carrier privilege.
3203 * @param inputCode The dialer code to send
3204 */
3205 @Override
3206 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003208 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003209 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3210 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003211 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003212 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003213 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
fionaxu235cc5e2017-03-06 22:25:57 -08003222 }
3223
Pengquan Menga1bb6272018-09-06 09:59:22 -07003224 @Override
3225 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003226 TelephonyPermissions
3227 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3228 mApp, subId, "getNetworkSelectionMode");
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 if (!isActiveSubscription(subId)) {
3232 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3233 }
3234 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003237 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003238 }
3239
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003241 public boolean isInEmergencySmsMode() {
3242 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 for (Phone phone : PhoneFactory.getPhones()) {
3246 if (phone.isInEmergencySmsMode()) {
3247 return true;
3248 }
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
3253 return false;
3254 }
3255
shilu366312e2019-12-17 09:28:10 -08003256 /**
3257 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3258 * @param subId The subscription to use to check the configuration.
3259 * @param c The callback that will be used to send the result.
3260 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003261 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003262 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3263 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003264 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3265 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003266
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003267 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3268 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3269 "IMS not available on device.");
3270 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 final long token = Binder.clearCallingIdentity();
3272 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (ImsException e) {
3277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 } finally {
3279 Binder.restoreCallingIdentity(token);
3280 }
3281 }
3282
shilu366312e2019-12-17 09:28:10 -08003283 /**
3284 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3285 * @param subId The subscription to use to check the configuration.
3286 * @param c The callback that will be used to send the result.
3287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003289 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003290 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3291 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003292 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3293 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3294 }
Meng Wangafbc5852019-09-19 17:37:13 -07003295 final long token = Binder.clearCallingIdentity();
3296 try {
3297 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3298 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3299 .removeRegistrationCallbackForSubscription(c, subId);
3300 } catch (ImsException e) {
3301 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3302 + "is inactive, ignoring unregister.");
3303 // If the subscription is no longer active, just return, since the callback
3304 // will already have been removed internally.
3305 } finally {
3306 Binder.restoreCallingIdentity(token);
3307 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 }
3309
Brad Ebingera34a6c22019-10-22 17:36:18 -07003310 /**
3311 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3312 */
3313 @Override
3314 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3315 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3316 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3317 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3318 "IMS not available on device.");
3319 }
3320 final long token = Binder.clearCallingIdentity();
3321 try {
3322 Phone phone = getPhone(subId);
3323 if (phone == null) {
3324 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3325 + subId + "'");
3326 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3327 }
3328 phone.getImsRegistrationState(regState -> {
3329 try {
3330 consumer.accept((regState == null)
3331 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3332 } catch (RemoteException e) {
3333 // Ignore if the remote process is no longer available to call back.
3334 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3335 }
3336 });
3337 } finally {
3338 Binder.restoreCallingIdentity(token);
3339 }
3340 }
3341
3342 /**
3343 * Get the transport type for the IMS service registration state.
3344 */
3345 @Override
3346 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003347 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3348 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003349 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3351 "IMS not available on device.");
3352 }
3353 final long token = Binder.clearCallingIdentity();
3354 try {
3355 Phone phone = getPhone(subId);
3356 if (phone == null) {
3357 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3358 + subId + "'");
3359 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3360 }
3361 phone.getImsRegistrationTech(regTech -> {
3362 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3363 int regTechConverted = (regTech == null)
3364 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3365 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3366 regTechConverted);
3367 try {
3368 consumer.accept(regTechConverted);
3369 } catch (RemoteException e) {
3370 // Ignore if the remote process is no longer available to call back.
3371 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3372 }
3373 });
3374 } finally {
3375 Binder.restoreCallingIdentity(token);
3376 }
3377 }
3378
shilu366312e2019-12-17 09:28:10 -08003379 /**
3380 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3381 * @param subId The subscription to use to check the configuration.
3382 * @param c The callback that will be used to send the result.
3383 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003385 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3386 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003387 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3388 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003389 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3390 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3391 "IMS not available on device.");
3392 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3394 final long token = Binder.clearCallingIdentity();
3395 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003398 } catch (ImsException e) {
3399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 } finally {
3401 Binder.restoreCallingIdentity(token);
3402 }
3403 }
3404
shilu366312e2019-12-17 09:28:10 -08003405 /**
3406 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3407 * @param subId The subscription to use to check the configuration.
3408 * @param c The callback that will be used to send the result.
3409 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003411 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003412 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3413 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003414 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3415 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3416 }
Meng Wangafbc5852019-09-19 17:37:13 -07003417
3418 final long token = Binder.clearCallingIdentity();
3419 try {
3420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3421 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003422 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003423 } catch (ImsException e) {
3424 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3425 + "is inactive, ignoring unregister.");
3426 // If the subscription is no longer active, just return, since the callback
3427 // will already have been removed internally.
3428 } finally {
3429 Binder.restoreCallingIdentity(token);
3430 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 }
3432
3433 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003434 public boolean isCapable(int subId, int capability, int regTech) {
3435 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3437 final long token = Binder.clearCallingIdentity();
3438 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003441 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3443 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003445 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3446 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 } finally {
3448 Binder.restoreCallingIdentity(token);
3449 }
3450 }
3451
3452 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003453 public boolean isAvailable(int subId, int capability, int regTech) {
3454 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 final long token = Binder.clearCallingIdentity();
3456 try {
3457 Phone phone = getPhone(subId);
3458 if (phone == null) return false;
3459 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003460 } catch (com.android.ims.ImsException e) {
3461 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3462 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003463 } finally {
3464 Binder.restoreCallingIdentity(token);
3465 }
3466 }
3467
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003468 /**
3469 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3470 * subscription.
3471 * @param subId The subscription to use to check the configuration.
3472 * @param callback The callback that will be used to send the result.
3473 * @param capability The MmTelFeature capability that will be used to send the result.
3474 * @param transportType The transport type of the MmTelFeature capability.
3475 */
3476 @Override
3477 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3478 int transportType) {
3479 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3480 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3481 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3482 "IMS not available on device.");
3483 }
3484 final long token = Binder.clearCallingIdentity();
3485 try {
3486 int slotId = getSlotIndex(subId);
3487 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3488 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3489 + subId + "'");
3490 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3491 }
3492 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3493 transportType, aBoolean -> {
3494 try {
3495 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3496 } catch (RemoteException e) {
3497 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3498 + "running. Ignore");
3499 }
3500 });
3501 } finally {
3502 Binder.restoreCallingIdentity(token);
3503 }
3504 }
3505
shilu366312e2019-12-17 09:28:10 -08003506 /**
3507 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3508 * @param subId The subscription to use to check the configuration.
3509 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 @Override
3511 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003512 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3513 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003514
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3516 final long token = Binder.clearCallingIdentity();
3517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (ImsException e) {
3521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 } finally {
3523 Binder.restoreCallingIdentity(token);
3524 }
3525 }
3526
3527 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003528 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003530 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003536 } catch (ImsException e) {
3537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
shilu366312e2019-12-17 09:28:10 -08003543 /**
3544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3545 * @param subId The subscription to use to check the configuration.
3546 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003548 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003549 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3550 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003554 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3555 } catch (ImsException e) {
3556 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 } finally {
3558 Binder.restoreCallingIdentity(identity);
3559 }
3560 }
3561
3562 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003563 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003565 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003569 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003570 } catch (ImsException e) {
3571 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
shilu366312e2019-12-17 09:28:10 -08003577 /**
3578 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3579 * @param subId The subscription to use to check the configuration.
3580 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 @Override
3582 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003583 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3584 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003590 } catch (ImsException e) {
3591 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 } finally {
3593 Binder.restoreCallingIdentity(identity);
3594 }
3595 }
3596
3597 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003598 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003600 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003604 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003605 } catch (ImsException e) {
3606 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
3610 }
3611
shilu366312e2019-12-17 09:28:10 -08003612 /**
3613 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3614 * @param subId The subscription to use to check the configuration.
3615 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 @Override
3617 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003618 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3619 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003625 } catch (ImsException e) {
3626 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631
3632 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003633 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003635 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003641 } catch (ImsException e) {
3642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
3646 }
3647
3648 @Override
3649 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3651 "setVoWiFiNonPersistent");
3652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003656 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003657 } catch (ImsException e) {
3658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
3663
shilu366312e2019-12-17 09:28:10 -08003664 /**
3665 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3666 * @param subId The subscription to use to check the configuration.
3667 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 @Override
3669 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003670 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3671 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003675 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003677 } catch (ImsException e) {
3678 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
3682 }
3683
3684 @Override
3685 public void setVoWiFiModeSetting(int subId, int mode) {
3686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3687 "setVoWiFiModeSetting");
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003693 } catch (ImsException e) {
3694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
3700 @Override
3701 public int getVoWiFiRoamingModeSetting(int subId) {
3702 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3718 "setVoWiFiRoamingModeSetting");
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
3731 @Override
3732 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3734 "setRttCapabilityEnabled");
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003738 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3739 } catch (ImsException e) {
3740 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
3744 }
3745
shilu366312e2019-12-17 09:28:10 -08003746 /**
3747 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3748 * @param subId The subscription to use to check the configuration.
3749 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 @Override
3751 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003752 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3753 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 } catch (ImsException e) {
3760 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
3764 }
3765
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003766 @Override
3767 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3768 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3769 final long identity = Binder.clearCallingIdentity();
3770 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003771 if (!isImsAvailableOnDevice()) {
3772 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3773 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003774 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003776 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003777 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003778 } catch (ImsException e) {
3779 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
3783 }
3784
3785 @Override
3786 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3787 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3788 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3791 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003792 try {
3793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003794 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003795 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003796 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003797 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3798 + "is inactive, ignoring unregister.");
3799 // If the subscription is no longer active, just return, since the callback will already
3800 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
3804 }
3805
allenwtsu99c623b2020-01-03 18:24:23 +08003806
3807 private void checkModifyPhoneStatePermission(int subId, String message) {
3808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3809 message);
3810 }
3811
3812 private boolean isImsProvisioningRequired(int subId, int capability,
3813 boolean isMmtelCapability) {
3814 Phone phone = getPhone(subId);
3815 if (phone == null) {
3816 loge("phone instance null for subid " + subId);
3817 return false;
3818 }
3819 if (isMmtelCapability) {
3820 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3821 return false;
3822 }
3823 } else {
3824 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3825 return false;
3826 }
3827 }
3828 return true;
3829 }
3830
3831 @Override
3832 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3833 boolean isProvisioned) {
3834 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3835
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3839 if (!isImsProvisioningRequired(subId, capability, false)) {
3840 return;
3841 }
3842
3843 // this capability requires provisioning, route to the correct API.
3844 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3845 switch (capability) {
3846 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3847 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3848 ims.setEabProvisioned(isProvisioned);
3849 break;
3850 default: {
3851 throw new IllegalArgumentException("Tried to set provisioning for "
3852 + "rcs capability '" + capability + "', which does not require "
3853 + "provisioning.");
3854 }
3855 }
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
3858 }
3859
3860 }
3861
3862
3863 @Override
3864 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3865 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3869 if (!isImsProvisioningRequired(subId, capability, false)) {
3870 return true;
3871 }
3872
3873 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3874 switch (capability) {
3875 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3876 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3877 return ims.isEabProvisionedOnDevice();
3878
3879 default: {
3880 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3881 + "capability '" + capability + "', which does not require "
3882 + "provisioning.");
3883 }
3884 }
3885
3886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
3889 }
3890
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003891 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003892 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3893 boolean isProvisioned) {
3894 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3895 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3896 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3897 }
allenwtsu99c623b2020-01-03 18:24:23 +08003898 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003902 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003903 return;
3904 }
3905
3906 // this capability requires provisioning, route to the correct API.
3907 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3908 switch (capability) {
3909 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3910 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3911 ims.setVolteProvisioned(isProvisioned);
3912 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3913 ims.setWfcProvisioned(isProvisioned);
3914 }
3915 break;
3916 }
3917 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3918 // There is currently no difference in VT provisioning type.
3919 ims.setVtProvisioned(isProvisioned);
3920 break;
3921 }
3922 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3923 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3924 // change the capability of the feature instead if needed.
3925 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3926 == isProvisioned) {
3927 // No change in provisioning.
3928 return;
3929 }
3930 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3931 try {
3932 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003933 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003934 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3935 + ", Exception" + e.getMessage());
3936 }
3937 break;
3938 }
3939 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003940 throw new IllegalArgumentException("Tried to set provisioning for "
3941 + "MmTel capability '" + capability + "', which does not require "
3942 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003943 }
3944 }
3945
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
3949 }
3950
3951 @Override
3952 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3953 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3954 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3955 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3956 }
3957 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003961 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003962 return true;
3963 }
3964
3965 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3966 switch (capability) {
3967 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3968 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3969 return ims.isVolteProvisionedOnDevice();
3970 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3971 return ims.isWfcProvisionedOnDevice();
3972 }
3973 // This should never happen, since we are checking tech above to make sure it
3974 // is either LTE or IWLAN.
3975 throw new IllegalArgumentException("Invalid radio technology for voice "
3976 + "capability.");
3977 }
3978 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3979 // There is currently no difference in VT provisioning type.
3980 return ims.isVtProvisionedOnDevice();
3981 }
3982 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3983 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3984 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3985 }
3986 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003987 throw new IllegalArgumentException(
3988 "Tried to get provisioning for MmTel capability '" + capability
3989 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003990 }
3991 }
3992
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
3996 }
3997
3998 @Override
3999 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4000 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4001 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4002 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4003 }
4004 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4005 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4006 return (provisionedBits & capability) > 0;
4007 }
4008
4009 @Override
4010 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4011 boolean isProvisioned) {
4012 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4013 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4014 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4015 }
4016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4017 "setProvisioningStatusForCapability");
4018 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4019 // If the current provisioning status for capability already matches isProvisioned,
4020 // do nothing.
4021 if (((provisionedBits & capability) > 0) == isProvisioned) {
4022 return;
4023 }
4024 if (isProvisioned) {
4025 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4026 } else {
4027 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4028 }
4029 }
4030
4031 /**
4032 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4033 * technology. The bitfield should mirror the bitfield defined by
4034 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4035 */
4036 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4037 String key = getMmTelProvisioningKey(subId, tech);
4038 // Default is no capabilities are provisioned.
4039 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4040 }
4041
4042 /**
4043 * Sets the MmTel capability provisioning bitfield (defined by
4044 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4045 * technology specified.
4046 *
4047 * Note: This is a synchronous command and should not be called on UI thread.
4048 */
4049 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4050 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4051 String key = getMmTelProvisioningKey(subId, tech);
4052 editor.putInt(key, newField);
4053 editor.commit();
4054 }
4055
4056 private static String getMmTelProvisioningKey(int subId, int tech) {
4057 // resulting key is provision_ims_mmtel_{subId}_{tech}
4058 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4059 }
4060
4061 /**
4062 * Query CarrierConfig to see if the specified capability requires provisioning for the
4063 * carrier associated with the subscription id.
4064 */
4065 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4066 int capability) {
4067 CarrierConfigManager configManager = new CarrierConfigManager(context);
4068 PersistableBundle c = configManager.getConfigForSubId(subId);
4069 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004070 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004071 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4072 false);
4073 boolean requireVoiceVtProvisioning = c.getBoolean(
4074 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4075
4076 // First check to make sure that the capability requires provisioning.
4077 switch (capability) {
4078 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4079 // intentional fallthrough
4080 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4081 if (requireVoiceVtProvisioning) {
4082 // Voice and Video requires provisioning
4083 return true;
4084 }
4085 break;
4086 }
4087 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4088 if (requireUtProvisioning) {
4089 // UT requires provisioning
4090 return true;
4091 }
4092 break;
4093 }
4094 }
4095 return false;
4096 }
4097
allenwtsu99c623b2020-01-03 18:24:23 +08004098 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4099 int capability) {
4100 CarrierConfigManager configManager = new CarrierConfigManager(context);
4101 PersistableBundle c = configManager.getConfigForSubId(subId);
4102
4103 boolean requireRcsProvisioning = c.getBoolean(
4104 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4105
4106 // First check to make sure that the capability requires provisioning.
4107 switch (capability) {
4108 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4109 // intentional fallthrough
4110 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4111 if (requireRcsProvisioning) {
4112 // OPTION or PRESENCE requires provisioning
4113 return true;
4114 }
4115 break;
4116 }
4117 }
4118 return false;
4119 }
4120
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004123 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4124 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4125 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004126 enforceReadPrivilegedPermission("getImsProvisioningInt");
4127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004130 int slotId = getSlotIndex(subId);
4131 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4132 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4133 + subId + "' for key:" + key);
4134 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4135 }
4136 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004138 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4139 + subId + "' for key:" + key);
4140 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004141 } finally {
4142 Binder.restoreCallingIdentity(identity);
4143 }
4144 }
4145
4146 @Override
4147 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004148 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4149 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4150 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004151 enforceReadPrivilegedPermission("getImsProvisioningString");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004155 int slotId = getSlotIndex(subId);
4156 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4157 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4158 + subId + "' for key:" + key);
4159 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4160 }
4161 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004163 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4164 + subId + "' for key:" + key);
4165 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 }
4170
4171 @Override
4172 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004173 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4174 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4175 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4177 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004181 int slotId = getSlotIndex(subId);
4182 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4183 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4184 + subId + "' for key:" + key);
4185 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4186 }
4187 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004189 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4190 + "' for key:" + key);
4191 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
4195 }
4196
4197 @Override
4198 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4200 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4201 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4203 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 final long identity = Binder.clearCallingIdentity();
4205 try {
4206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004207 int slotId = getSlotIndex(subId);
4208 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4209 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4210 + subId + "' for key:" + key);
4211 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4212 }
4213 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004214 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004215 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4216 + "' for key:" + key);
4217 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
4221 }
4222
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 int slotId = SubscriptionManager.getSlotIndex(subId);
4225 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4227 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 }
4229 return slotId;
4230 }
4231
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004232 private int getSlotIndex(int subId) {
4233 int slotId = SubscriptionManager.getSlotIndex(subId);
4234 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4235 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4236 }
4237 return slotId;
4238 }
4239
Wink Saville36469e72014-06-11 15:17:00 -07004240 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004241 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004242 */
4243 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004244 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4245 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004246 final int targetSdk = getTargetSdk(callingPackage);
4247 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004248 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004249 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004250 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004251 mApp, subId, callingPackage, callingFeatureId,
4252 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004253 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4254 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 final Phone phone = getPhone(subId);
4259 if (phone != null) {
4260 return phone.getServiceState().getDataNetworkType();
4261 } else {
4262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4263 }
4264 } finally {
4265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004267 }
4268
4269 /**
4270 * Returns the data network type
4271 */
4272 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004273 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4274 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4275 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004276 }
4277
4278 /**
4279 * Returns the data network type for a subId
4280 */
4281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004282 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4283 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004285 mApp, subId, callingPackage, callingFeatureId,
4286 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4288 }
4289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 final Phone phone = getPhone(subId);
4293 if (phone != null) {
4294 return phone.getServiceState().getDataNetworkType();
4295 } else {
4296 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4297 }
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004301 }
4302
4303 /**
Wink Saville36469e72014-06-11 15:17:00 -07004304 * Returns the Voice network type for a subId
4305 */
4306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004307 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4308 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004310 mApp, subId, callingPackage, callingFeatureId,
4311 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004312 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4313 }
4314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 final Phone phone = getPhone(subId);
4318 if (phone != null) {
4319 return phone.getServiceState().getVoiceNetworkType();
4320 } else {
4321 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4322 }
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004326 }
4327
4328 /**
4329 * @return true if a ICC card is present
4330 */
4331 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004332 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004333 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4334 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004335 }
4336
4337 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004338 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004339 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004340 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004341 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 final Phone phone = PhoneFactory.getPhone(slotIndex);
4345 if (phone != null) {
4346 return phone.getIccCard().hasIccCard();
4347 } else {
4348 return false;
4349 }
4350 } finally {
4351 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004353 }
4354
4355 /**
4356 * Return if the current radio is LTE on CDMA. This
4357 * is a tri-state return value as for a period of time
4358 * the mode may be unknown.
4359 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004360 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004361 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004362 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004363 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004365 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4366 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4367 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004368 }
4369
Sanket Padawe356d7632015-06-22 14:03:32 -07004370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004371 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4372 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004373 try {
4374 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4375 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004376 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4377 }
4378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 final long identity = Binder.clearCallingIdentity();
4380 try {
4381 final Phone phone = getPhone(subId);
4382 if (phone == null) {
4383 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4384 } else {
4385 return phone.getLteOnCdmaMode();
4386 }
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004389 }
Wink Saville36469e72014-06-11 15:17:00 -07004390 }
4391
Wink Saville36469e72014-06-11 15:17:00 -07004392 /**
4393 * {@hide}
4394 * Returns Default subId, 0 in the case of single standby.
4395 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004396 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004397 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004398 }
4399
Shishir Agrawala9f32182016-04-12 12:00:16 -07004400 private int getSlotForDefaultSubscription() {
4401 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4402 }
4403
Wink Savilleb564aae2014-10-23 10:18:09 -07004404 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004405 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004406 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004407
Pengquan Menge92a50d2018-09-21 15:54:48 -07004408 private boolean isActiveSubscription(int subId) {
4409 return mSubscriptionController.isActiveSubId(subId);
4410 }
4411
Ihab Awadf2177b72013-11-25 13:33:23 -08004412 /**
4413 * @see android.telephony.TelephonyManager.WifiCallingChoices
4414 */
4415 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004418 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4420 getWhenToMakeWifiCallsDefaultPreference());
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004424 }
4425
4426 /**
4427 * @see android.telephony.TelephonyManager.WifiCallingChoices
4428 */
4429 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004433 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004438 }
4439
Sailesh Nepald1e68152013-12-12 19:08:02 -08004440 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004441 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004442 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004443 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004444
Jordan Liu4c733742019-02-28 12:03:40 -08004445 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4446 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4447 if (phoneId == -1) {
4448 throw new IllegalArgumentException("Given slot index: " + slotIndex
4449 + " does not correspond to an active phone");
4450 }
4451 return PhoneFactory.getPhone(phoneId);
4452 }
4453
Shishir Agrawal566b7612013-10-28 14:41:00 -07004454 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004455 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4456 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4458 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004460 if (DBG) {
4461 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4462 }
4463 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4464 p2);
4465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004466
Jordan Liu4c733742019-02-28 12:03:40 -08004467
4468 @Override
4469 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4470 int slotIndex, String callingPackage, String aid, int p2) {
4471 enforceModifyPermission();
4472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4473 if (DBG) {
4474 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4475 }
4476 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4477 callingPackage, aid, p2);
4478 }
4479
4480 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4481 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 if (TextUtils.equals(ISDR_AID, aid)) {
4485 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004486 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4487 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 if (bestComponent == null
4489 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4490 loge("The calling package is not allowed to access ISD-R.");
4491 throw new SecurityException(
4492 "The calling package is not allowed to access ISD-R.");
4493 }
Derek Tan740e1672017-06-27 14:56:27 -07004494 }
Derek Tan740e1672017-06-27 14:56:27 -07004495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004497 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4498 null /* workSource */);
4499 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 return response;
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004504 }
4505
4506 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004507 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4509 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004510 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4511 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4512 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004513
Jordan Liu4c733742019-02-28 12:03:40 -08004514 @Override
4515 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4516 enforceModifyPermission();
4517 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4518 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4519 channel);
4520 }
4521
4522 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 if (channel < 0) {
4526 return false;
4527 }
Jordan Liu4c733742019-02-28 12:03:40 -08004528 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4529 null /* workSource */);
4530 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 return success;
4532 } finally {
4533 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004535 }
4536
4537 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004538 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004539 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4541 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004542 if (DBG) {
4543 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4544 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4545 + p3 + " data=" + data);
4546 }
4547 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4548 command, p1, p2, p3, data);
4549 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004550
Jordan Liu4c733742019-02-28 12:03:40 -08004551 @Override
4552 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4553 int command, int p1, int p2, int p3, String data) {
4554 enforceModifyPermission();
4555 if (DBG) {
4556 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4557 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4558 + p3 + " data=" + data);
4559 }
4560 return iccTransmitApduLogicalChannelWithPermission(
4561 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4562 data);
4563 }
4564
4565 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4566 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 final long identity = Binder.clearCallingIdentity();
4568 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004569 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 return "";
4571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004574 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4575 null /* workSource */);
4576 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 // Append the returned status code to the end of the response payload.
4579 String s = Integer.toHexString(
4580 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4581 if (response.payload != null) {
4582 s = IccUtils.bytesToHexString(response.payload) + s;
4583 }
4584 return s;
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004588 }
Jake Hambye994d462014-02-03 13:10:13 -08004589
Evan Charltonc66da362014-05-16 14:06:40 -07004590 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004591 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4592 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4594 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004596 if (DBG) {
4597 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4598 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4599 }
4600 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4601 cla, command, p1, p2, p3, data);
4602 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004603
Jordan Liu4c733742019-02-28 12:03:40 -08004604 @Override
4605 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4606 int command, int p1, int p2, int p3, String data) {
4607 enforceModifyPermission();
4608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4609 if (DBG) {
4610 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4611 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4612 + " data=" + data);
4613 }
4614
4615 return iccTransmitApduBasicChannelWithPermission(
4616 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4617 p2, p3, data);
4618 }
4619
4620 // open APDU basic channel assuming the caller has sufficient permissions
4621 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4622 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4626 && TextUtils.equals(ISDR_AID, data)) {
4627 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004628 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4629 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 if (bestComponent == null
4631 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4632 loge("The calling package is not allowed to select ISD-R.");
4633 throw new SecurityException(
4634 "The calling package is not allowed to select ISD-R.");
4635 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004636 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004639 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4640 null /* workSource */);
4641 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 // Append the returned status code to the end of the response payload.
4644 String s = Integer.toHexString(
4645 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4646 if (response.payload != null) {
4647 s = IccUtils.bytesToHexString(response.payload) + s;
4648 }
4649 return s;
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004652 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004653 }
4654
4655 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004656 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004657 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4659 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 if (DBG) {
4664 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4665 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4666 }
4667
4668 IccIoResult response =
4669 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4670 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4671 subId);
4672
4673 if (DBG) {
4674 log("Exchange SIM_IO [R]" + response);
4675 }
4676
4677 byte[] result = null;
4678 int length = 2;
4679 if (response.payload != null) {
4680 length = 2 + response.payload.length;
4681 result = new byte[length];
4682 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4683 } else {
4684 result = new byte[length];
4685 }
4686
4687 result[length - 1] = (byte) response.sw2;
4688 result[length - 2] = (byte) response.sw1;
4689 return result;
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004692 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004693 }
4694
Nathan Haroldb3014052017-01-25 15:57:32 -08004695 /**
4696 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4697 * on a particular subscription
4698 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004699 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4700 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004702 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004703 return null;
4704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705
4706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 if (appType != TelephonyManager.APPTYPE_USIM
4709 && appType != TelephonyManager.APPTYPE_SIM) {
4710 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4711 return null;
4712 }
4713 Object response = sendRequest(
4714 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4715 if (response instanceof String[]) {
4716 return (String[]) response;
4717 }
yincheng zhao2737e882019-09-06 17:06:54 -07004718 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004720 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 } finally {
4722 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004723 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004724 }
4725
yincheng zhao2737e882019-09-06 17:06:54 -07004726 /**
4727 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4728 * subscription.
4729 *
4730 * @param subId the id of the subscription.
4731 * @param appType the uicc app type, must be USIM or SIM.
4732 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4733 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004734 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004735 * @return number of fplmns that is successfully written to the SIM.
4736 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004737 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4738 String callingFeatureId) {
4739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4740 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004741 if (DBG) logv("no permissions for setForbiddenplmns");
4742 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4743 }
4744 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4745 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4746 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4747 }
4748 if (fplmns == null) {
4749 throw new IllegalArgumentException("Fplmn List provided is null");
4750 }
4751 for (String fplmn : fplmns) {
4752 if (!CellIdentity.isValidPlmn(fplmn)) {
4753 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4754 }
4755 }
4756 final long identity = Binder.clearCallingIdentity();
4757 try {
4758 Object response = sendRequest(
4759 CMD_SET_FORBIDDEN_PLMNS,
4760 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4761 subId);
4762 return (int) response;
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004768 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004769 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4771 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 final long identity = Binder.clearCallingIdentity();
4774 try {
4775 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4776 if (response.payload == null) {
4777 return "";
4778 }
Evan Charltonc66da362014-05-16 14:06:40 -07004779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 // Append the returned status code to the end of the response payload.
4781 String s = Integer.toHexString(
4782 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4783 s = IccUtils.bytesToHexString(response.payload) + s;
4784 return s;
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Evan Charltonc66da362014-05-16 14:06:40 -07004788 }
4789
Jake Hambye994d462014-02-03 13:10:13 -08004790 /**
4791 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4792 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4793 *
4794 * @param itemID the ID of the item to read
4795 * @return the NV item as a String, or null on error.
4796 */
4797 @Override
4798 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004799 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4801 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802
4803 final long identity = Binder.clearCallingIdentity();
4804 try {
4805 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004806 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4808 return value;
4809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
Jake Hambye994d462014-02-03 13:10:13 -08004812 }
4813
4814 /**
4815 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4816 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4817 *
4818 * @param itemID the ID of the item to read
4819 * @param itemValue the value to write, as a String
4820 * @return true on success; false on any failure
4821 */
4822 @Override
4823 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4826 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827
4828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4831 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004832 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4834 return success;
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
Jake Hambye994d462014-02-03 13:10:13 -08004838 }
4839
4840 /**
4841 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4842 * Used for device configuration by some CDMA operators.
4843 *
4844 * @param preferredRoamingList byte array containing the new PRL
4845 * @return true on success; false on any failure
4846 */
4847 @Override
4848 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4850 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851
4852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4855 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4856 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4857 return success;
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
Jake Hambye994d462014-02-03 13:10:13 -08004861 }
4862
4863 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004864 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004865 * Used for device configuration by some CDMA operators.
4866 *
chen xu6dac5ab2018-10-26 17:39:23 -07004867 * @param slotIndex - device slot.
4868 *
Jake Hambye994d462014-02-03 13:10:13 -08004869 * @return true on success; false on any failure
4870 */
4871 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004872 public boolean resetModemConfig(int slotIndex) {
4873 Phone phone = PhoneFactory.getPhone(slotIndex);
4874 if (phone != null) {
4875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4876 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004877
chen xu6dac5ab2018-10-26 17:39:23 -07004878 final long identity = Binder.clearCallingIdentity();
4879 try {
4880 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4881 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4882 return success;
4883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 }
chen xu6dac5ab2018-10-26 17:39:23 -07004887 return false;
4888 }
4889
4890 /**
4891 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4892 *
4893 * @param slotIndex - device slot.
4894 *
4895 * @return true on success; false on any failure
4896 */
4897 @Override
4898 public boolean rebootModem(int slotIndex) {
4899 Phone phone = PhoneFactory.getPhone(slotIndex);
4900 if (phone != null) {
4901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4902 mApp, phone.getSubId(), "rebootModem");
4903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4907 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4908 return success;
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
4912 }
4913 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004914 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004915
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004916 public String[] getPcscfAddress(String apnType, String callingPackage,
4917 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004918 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4920 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004921 return new String[0];
4922 }
4923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004926 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
Wink Saville36469e72014-06-11 15:17:00 -07004930 }
4931
Brad Ebinger51f743a2017-01-23 13:50:20 -08004932 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004933 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4934 * {@link #disableIms(int)}.
4935 * @param slotIndex device slot.
4936 */
4937 public void resetIms(int slotIndex) {
4938 enforceModifyPermission();
4939
4940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 if (mImsResolver == null) {
4943 // may happen if the does not support IMS.
4944 return;
4945 }
4946 mImsResolver.disableIms(slotIndex);
4947 mImsResolver.enableIms(slotIndex);
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
4953 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004954 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4955 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004956 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004957 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004958 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959
4960 final long identity = Binder.clearCallingIdentity();
4961 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004962 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004963 // may happen if the device does not support IMS.
4964 return;
4965 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004966 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004970 }
4971
4972 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004973 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4974 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004975 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004976 public void disableIms(int slotId) {
4977 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978
4979 final long identity = Binder.clearCallingIdentity();
4980 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004981 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004982 // may happen if the device does not support IMS.
4983 return;
4984 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004985 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 } finally {
4987 Binder.restoreCallingIdentity(identity);
4988 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004989 }
4990
4991 /**
4992 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4993 * feature or {@link null} if the service is not available. If the feature is available, the
4994 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4995 */
4996 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004997 IImsServiceFeatureCallback callback) {
4998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999
5000 final long identity = Binder.clearCallingIdentity();
5001 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005002 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005003 // may happen if the device does not support IMS.
5004 return null;
5005 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005006 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005010 }
5011
5012 /**
5013 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5014 * feature during emergency calling or {@link null} if the service is not available. If the
5015 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5016 * listener for feature updates.
5017 */
5018 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005023 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005024 // may happen if the device does not support IMS.
5025 return null;
5026 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005027 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005031 }
5032
Brad Ebinger5f64b052017-12-14 14:26:15 -08005033 /**
5034 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005035 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005036 */
5037 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039
5040 final long identity = Binder.clearCallingIdentity();
5041 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005042 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005043 // may happen if the device does not support IMS.
5044 return null;
5045 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005046 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005050 }
5051
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005052 /**
5053 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005054 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005055 */
5056 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5057 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005062 // may happen if the device does not support IMS.
5063 return null;
5064 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005065 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005069 }
5070
Brad Ebinger884c07b2018-02-15 16:17:40 -08005071 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005072 * Sets the ImsService Package Name that Telephony will bind to.
5073 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005074 * @param slotIndex the slot ID that the ImsService should bind for.
5075 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005077 * @param featureTypes An integer array of feature types associated with a packageName.
5078 * @param packageName The name of the package that the current configuration will be replaced
5079 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005081 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005082 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5083 int[] featureTypes, String packageName) {
5084 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5087 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005088 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005092 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005093 // may happen if the device does not support IMS.
5094 return false;
5095 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005096 Map<Integer, String> featureConfig = new HashMap<>();
5097 for (int featureType : featureTypes) {
5098 featureConfig.put(featureType, packageName);
5099 }
5100 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5101 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005105 }
5106
5107 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005108 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005109 *
5110 * @param slotId The slot that the ImsService is associated with.
5111 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5112 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005113 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005114 * @return the package name of the ImsService configuration.
5115 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005116 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5117 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005118 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005119 TelephonyPermissions
5120 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5121 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5122 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 final long identity = Binder.clearCallingIdentity();
5125 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005126 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005127 // may happen if the device does not support IMS.
5128 return "";
5129 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005130 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005131 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5132 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005136 }
5137
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005138 /**
5139 * Get the MmTelFeature state associated with the requested subscription id.
5140 * @param subId The subscription that the MmTelFeature is associated with.
5141 * @param callback A callback with an integer containing the
5142 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5143 */
5144 @Override
5145 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5146 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5147 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5148 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5149 "IMS not available on device.");
5150 }
5151 final long token = Binder.clearCallingIdentity();
5152 try {
5153 int slotId = getSlotIndex(subId);
5154 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5155 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5156 + subId + "'");
5157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5158 }
5159 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5160 try {
5161 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5162 } catch (RemoteException e) {
5163 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5164 + "Ignore");
5165 }
5166 });
5167 } finally {
5168 Binder.restoreCallingIdentity(token);
5169 }
5170 }
5171
Wink Saville36469e72014-06-11 15:17:00 -07005172 public void setImsRegistrationState(boolean registered) {
5173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174
5175 final long identity = Binder.clearCallingIdentity();
5176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005177 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
Wink Saville36469e72014-06-11 15:17:00 -07005181 }
5182
5183 /**
Stuart Scott54788802015-03-30 13:18:01 -07005184 * Set the network selection mode to automatic.
5185 *
5186 */
5187 @Override
5188 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
shilufc958392020-01-20 11:36:01 -08005194 if (!isActiveSubscription(subId)) {
5195 return;
5196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5198 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Stuart Scott54788802015-03-30 13:18:01 -07005202 }
5203
Pengquan Mengea84e042018-09-20 14:57:26 -07005204 /**
5205 * Ask the radio to connect to the input network and change selection mode to manual.
5206 *
5207 * @param subId the id of the subscription.
5208 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5209 * the operator to attach to.
5210 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5211 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5212 * normal network selection next time.
5213 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005214 */
5215 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005216 public boolean setNetworkSelectionModeManual(
5217 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005220
5221 if (!isActiveSubscription(subId)) {
5222 return false;
5223 }
5224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005227 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005229 if (DBG) {
5230 log("setNetworkSelectionModeManual: subId: " + subId
5231 + " operator: " + operatorInfo);
5232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005237 }
shilu84f6e8b2019-12-19 13:58:01 -08005238 /**
5239 * Get the manual network selection
5240 *
5241 * @param subId the id of the subscription.
5242 *
5243 * @return the previously saved user selected PLMN
5244 */
5245 @Override
5246 public String getManualNetworkSelectionPlmn(int subId) {
5247 TelephonyPermissions
5248 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5249 mApp, subId, "getManualNetworkSelectionPlmn");
5250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005254 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005255 }
5256
5257 final Phone phone = getPhone(subId);
5258 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005259 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005260 }
5261 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5262 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5263 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
5266 }
5267 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005268
5269 /**
5270 * Scans for available networks.
5271 */
5272 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005273 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005277 LocationAccessPolicy.LocationPermissionResult locationResult =
5278 LocationAccessPolicy.checkLocationPermission(mApp,
5279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5280 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005281 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005282 .setCallingPid(Binder.getCallingPid())
5283 .setCallingUid(Binder.getCallingUid())
5284 .setMethod("getCellNetworkScanResults")
5285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5286 .build());
5287 switch (locationResult) {
5288 case DENIED_HARD:
5289 throw new SecurityException("Not allowed to access scan results -- location");
5290 case DENIED_SOFT:
5291 return null;
5292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293
Pengquan Menga1bb6272018-09-06 09:59:22 -07005294 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 try {
5296 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005297 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005302 }
5303
5304 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005305 * Get the call forwarding info, given the call forwarding reason.
5306 */
5307 @Override
5308 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5309 enforceReadPrivilegedPermission("getCallForwarding");
5310 long identity = Binder.clearCallingIdentity();
5311 try {
5312 if (DBG) {
5313 log("getCallForwarding: subId " + subId
5314 + " callForwardingReason" + callForwardingReason);
5315 }
5316 return (CallForwardingInfo) sendRequest(
5317 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
5321 }
5322
5323 /**
5324 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5325 * reason, the number to forward, and the timeout before the forwarding is attempted.
5326 */
5327 @Override
5328 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5329 enforceModifyPermission();
5330 long identity = Binder.clearCallingIdentity();
5331 try {
5332 if (DBG) {
5333 log("setCallForwarding: subId " + subId
5334 + " callForwardingInfo" + callForwardingInfo);
5335 }
5336 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
5340 }
5341
5342 /**
5343 * Get the call forwarding info, given the call forwarding reason.
5344 */
5345 @Override
5346 public int getCallWaitingStatus(int subId) {
5347 enforceReadPrivilegedPermission("getCallForwarding");
5348 long identity = Binder.clearCallingIdentity();
5349 try {
5350 if (DBG) log("getCallWaitingStatus: subId " + subId);
5351 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356
5357 /**
5358 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5359 * reason, the number to forward, and the timeout before the forwarding is attempted.
5360 */
5361 @Override
5362 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5363 enforceModifyPermission();
5364 long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5367 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
5371 }
5372
5373 /**
yinxub1bed742017-04-17 11:45:04 -07005374 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005375 *
yinxub1bed742017-04-17 11:45:04 -07005376 * @param subId id of the subscription
5377 * @param request contains the radio access networks with bands/channels to scan
5378 * @param messenger callback messenger for scan results or errors
5379 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005380 * @return the id of the requested scan which can be used to stop the scan.
5381 */
5382 @Override
5383 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005384 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5386 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005387 LocationAccessPolicy.LocationPermissionResult locationResult =
5388 LocationAccessPolicy.checkLocationPermission(mApp,
5389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5390 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005392 .setCallingPid(Binder.getCallingPid())
5393 .setCallingUid(Binder.getCallingUid())
5394 .setMethod("requestNetworkScan")
5395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5396 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005397 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005398 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005399 if (e != null) {
5400 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5401 throw e;
5402 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005403 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005404 return TelephonyScanManager.INVALID_SCAN_ID;
5405 }
5406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 }
Hall Liu912dfd32019-04-25 14:02:26 -07005408 int callingUid = Binder.getCallingUid();
5409 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 return mNetworkScanRequestTracker.startNetworkScan(
5413 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005414 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
5417 }
yinxu504e1392017-04-12 16:03:22 -07005418 }
5419
Hall Liub2ac8ef2019-02-28 15:56:23 -08005420 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005421 NetworkScanRequest request, int subId) {
5422 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5423 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5424 boolean hasNetworkScanPermission =
5425 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5426 == PERMISSION_GRANTED;
5427
5428 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5429 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5430 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005431 }
5432
5433 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5434 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005435 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5436 return new SecurityException("Specific channels must not be"
5437 + " scanned without location access.");
5438 }
5439 }
5440 }
5441
Hall Liub2ac8ef2019-02-28 15:56:23 -08005442 return null;
5443 }
5444
yinxu504e1392017-04-12 16:03:22 -07005445 /**
5446 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005447 *
5448 * @param subId id of the subscription
5449 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005450 */
5451 @Override
5452 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455
Hall Liu912dfd32019-04-25 14:02:26 -07005456 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005459 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
yinxu504e1392017-04-12 16:03:22 -07005463 }
5464
5465 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005466 * Get the calculated preferred network type.
5467 * Used for debugging incorrect network type.
5468 *
5469 * @return the preferred network type, defined in RILConstants.java.
5470 */
5471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005472 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005473 final Phone defaultPhone = getDefaultPhone();
5474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005475 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005476 return RILConstants.PREFERRED_NETWORK_MODE;
5477 }
5478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005482 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Junda Liu84d15a22014-07-02 11:21:04 -07005486 }
5487
5488 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005489 * Get the preferred network type.
5490 * Used for device configuration by some CDMA operators.
5491 *
5492 * @return the preferred network type, defined in RILConstants.java.
5493 */
5494 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005495 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005496 TelephonyPermissions
5497 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5498 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 if (DBG) log("getPreferredNetworkType");
5503 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5504 int networkType = (result != null ? result[0] : -1);
5505 if (DBG) log("getPreferredNetworkType: " + networkType);
5506 return networkType;
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005510 }
5511
5512 /**
5513 * Set the preferred network type.
5514 * Used for device configuration by some CDMA operators.
5515 *
5516 * @param networkType the preferred network type, defined in RILConstants.java.
5517 * @return true on success; false on any failure.
5518 */
5519 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005520 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5522 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005526 Settings.Global.putInt(mApp.getContentResolver(),
5527 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5528 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 } finally {
5530 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005531 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005532 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005533
5534 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005535 * Get the allowed network types that store in the telephony provider.
5536 *
5537 * @param subId the id of the subscription.
5538 * @return allowedNetworkTypes the allowed network types.
5539 */
5540 @Override
5541 public long getAllowedNetworkTypes(int subId) {
5542 TelephonyPermissions
5543 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5544 mApp, subId, "getAllowedNetworkTypes");
5545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 return SubscriptionManager.getLongSubscriptionProperty(
5549 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
5553 }
5554
5555 /**
5556 * Set the allowed network types.
5557 *
5558 * @param subId the id of the subscription.
5559 * @param allowedNetworkTypes the allowed network types.
5560 * @return true on success; false on any failure.
5561 */
5562 @Override
5563 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5565 mApp, subId, "setAllowedNetworkTypes");
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 SubscriptionManager.setSubscriptionProperty(subId,
5569 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5570 String.valueOf(allowedNetworkTypes));
5571 return setPreferredNetworkTypesInternal(subId);
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
5575 }
5576
5577 private boolean setPreferredNetworkTypesInternal(int subId) {
5578 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5579 Settings.Global.getInt(mApp.getContentResolver(),
5580 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5581 RILConstants.PREFERRED_NETWORK_MODE));
5582 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5583 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5584 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5585 (int) (networkTypeBitMask & allowedNetworkTypes));
5586
5587 if (DBG) {
5588 log("setPreferredNetworkTypesInternal: subId " + subId
5589 + " networkTypes " + networkTypeBitMask
5590 + " allowedNetworkTypes " + allowedNetworkTypes
5591 + " networkMode " + networkMode);
5592 }
5593
5594 Boolean success = (Boolean) sendRequest(
5595 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5596 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5597 return success;
5598 }
5599
5600 /**
Miaoa84611c2019-03-15 09:21:10 +08005601 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005602 *
Miaoa84611c2019-03-15 09:21:10 +08005603 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005604 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005605 * @hide
5606 */
5607 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005608 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005611 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 try {
Miaoa84611c2019-03-15 09:21:10 +08005613 if (phone != null) {
5614 return phone.hasMatchedTetherApnSetting();
5615 } else {
5616 return false;
5617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 } finally {
5619 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005620 }
Junda Liu475951f2014-11-07 16:45:03 -08005621 }
5622
5623 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005624 * Set mobile data enabled
5625 * Used by the user through settings etc to turn on/off mobile data
5626 *
5627 * @param enable {@code true} turn turn data on, else {@code false}
5628 */
5629 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005630 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 int phoneId = mSubscriptionController.getPhoneId(subId);
5637 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5638 Phone phone = PhoneFactory.getPhone(phoneId);
5639 if (phone != null) {
5640 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005641 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 }
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005647 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005648 }
5649
5650 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005651 * Enable or disable always reporting signal strength changes from radio.
5652 *
5653 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5654 */
5655 @Override
5656 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5657 enforceModifyPermission();
5658 enforceSystemCaller();
5659
5660 final long identity = Binder.clearCallingIdentity();
5661 final Phone phone = getPhone(subId);
5662 try {
5663 if (phone != null) {
5664 if (DBG) {
5665 log("setAlwaysReportSignalStrength: subId=" + subId
5666 + " isEnable=" + isEnable);
5667 }
5668 phone.setAlwaysReportSignalStrength(isEnable);
5669 } else {
5670 loge("setAlwaysReportSignalStrength: no phone found for subId="
5671 + subId);
5672 }
5673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
5676 }
5677
5678 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005679 * Get the user enabled state of Mobile Data.
5680 *
5681 * TODO: remove and use isUserDataEnabled.
5682 * This can't be removed now because some vendor codes
5683 * calls through ITelephony directly while they should
5684 * use TelephonyManager.
5685 *
5686 * @return true on enabled
5687 */
5688 @Override
5689 public boolean getDataEnabled(int subId) {
5690 return isUserDataEnabled(subId);
5691 }
5692
5693 /**
5694 * Get whether mobile data is enabled per user setting.
5695 *
5696 * There are other factors deciding whether mobile data is actually enabled, but they are
5697 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005698 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005699 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005700 *
5701 * @return {@code true} if data is enabled else {@code false}
5702 */
5703 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005704 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005705 try {
5706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5707 null);
5708 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5710 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 int phoneId = mSubscriptionController.getPhoneId(subId);
5716 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5717 Phone phone = PhoneFactory.getPhone(phoneId);
5718 if (phone != null) {
5719 boolean retVal = phone.isUserDataEnabled();
5720 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5721 return retVal;
5722 } else {
5723 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5724 return false;
5725 }
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005728 }
5729 }
5730
5731 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005732 * Checks if the device is capable of mobile data by considering whether whether the
5733 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5734 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005735 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005736 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005737 */
5738 @Override
5739 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005740 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 int phoneId = mSubscriptionController.getPhoneId(subId);
5745 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5746 Phone phone = PhoneFactory.getPhone(phoneId);
5747 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005748 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5750 return retVal;
5751 } else {
5752 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5753 return false;
5754 }
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005757 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005758 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005759
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005760 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005761 Phone phone) {
5762 //load access rules from carrier configs, and check those as well: b/139133814
5763 SubscriptionController subController = SubscriptionController.getInstance();
5764 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5765 || subController == null) return privilegeFromSim;
5766
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005767 PackageManager pkgMgr = phone.getContext().getPackageManager();
5768 String[] packages = pkgMgr.getPackagesForUid(uid);
5769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005772 int subId = phone.getSubId();
5773 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5774 // A test override is in place for the privileges for this subId, so don't try to
5775 // read the subscription privileges.
5776 return privilegeFromSim;
5777 }
5778 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005779 SubscriptionManager subManager = (SubscriptionManager)
5780 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5781 for (String pkg : packages) {
5782 if (subManager.canManageSubscription(subInfo, pkg)) {
5783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5784 }
5785 }
5786 return privilegeFromSim;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
5790 }
5791
5792 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5793 String pkgName) {
5794 //load access rules from carrier configs, and check those as well: b/139133814
5795 SubscriptionController subController = SubscriptionController.getInstance();
5796 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5797 || subController == null) return privilegeFromSim;
5798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005801 int subId = phone.getSubId();
5802 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5803 // A test override is in place for the privileges for this subId, so don't try to
5804 // read the subscription privileges.
5805 return privilegeFromSim;
5806 }
5807 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005808 SubscriptionManager subManager = (SubscriptionManager)
5809 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5810 return subManager.canManageSubscription(subInfo, pkgName)
5811 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
5815 }
5816
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005817 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005818 public int getCarrierPrivilegeStatus(int subId) {
5819 final Phone phone = getPhone(subId);
5820 if (phone == null) {
5821 loge("getCarrierPrivilegeStatus: Invalid subId");
5822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5823 }
5824 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005825 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005826 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5828 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005829
5830 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5831 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005832 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005833 }
Junda Liu29340342014-07-10 15:23:27 -07005834
5835 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005836 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005837 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005838 final Phone phone = getPhone(subId);
5839 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005840 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005841 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5842 }
5843 UiccProfile profile =
5844 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5845 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005846 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005847 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5848 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005849 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005850 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005851 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005852 }
5853
5854 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005855 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5856 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005857 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005858 }
5859
5860 int phoneId = SubscriptionManager.getPhoneId(subId);
5861 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005862 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005863 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5865 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005866 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5867 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5868 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005869 }
5870
5871 @Override
5872 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005873 if (TextUtils.isEmpty(pkgName))
5874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005875 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5876 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5877 UiccCard card = UiccController.getInstance().getUiccCard(i);
5878 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005879 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005880 continue;
5881 }
5882
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005883 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5884 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5885 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005886 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5887 break;
5888 }
5889 }
5890
5891 return result;
Junda Liu29340342014-07-10 15:23:27 -07005892 }
Derek Tan89e89d42014-07-08 17:00:10 -07005893
5894 @Override
Junda Liue64de782015-04-16 17:19:16 -07005895 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5896 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5897 loge("phoneId " + phoneId + " is not valid.");
5898 return null;
5899 }
5900 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005901 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005902 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005903 return null ;
5904 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005905 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005906 }
5907
Amith Yamasani6e118872016-02-19 12:53:51 -08005908 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005909 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005910 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005911 List<String> privilegedPackages = new ArrayList<>();
5912 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005913 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5914 // has UICC in that slot.
5915 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005916 if (card.hasCarrierPrivilegeRules()) {
5917 if (packages == null) {
5918 // Only check packages in user 0 for now
5919 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005920 PackageManager.MATCH_DISABLED_COMPONENTS
5921 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005922 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005923 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005924 }
5925 for (int p = packages.size() - 1; p >= 0; p--) {
5926 PackageInfo pkgInfo = packages.get(p);
5927 if (pkgInfo != null && pkgInfo.packageName != null
5928 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005929 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005930 privilegedPackages.add(pkgInfo.packageName);
5931 }
5932 }
5933 }
5934 }
5935 return privilegedPackages;
5936 }
5937
chen xuf7e9fe82019-05-09 19:31:02 -07005938 @Override
5939 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005940 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5941
5942 final long identity = Binder.clearCallingIdentity();
5943
chen xuf7e9fe82019-05-09 19:31:02 -07005944 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005945 try {
5946 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5947 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5948 }
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005951 }
5952 return privilegedPackages;
5953 }
5954
Wink Savilleb564aae2014-10-23 10:18:09 -07005955 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005956 final Phone phone = getPhone(subId);
5957 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005958 if (card == null) {
5959 loge("getIccId: No UICC");
5960 return null;
5961 }
5962 String iccId = card.getIccId();
5963 if (TextUtils.isEmpty(iccId)) {
5964 loge("getIccId: ICC ID is null or empty.");
5965 return null;
5966 }
5967 return iccId;
5968 }
5969
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005970 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005971 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5972 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005973 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005974 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
5978 final String iccId = getIccId(subId);
5979 final Phone phone = getPhone(subId);
5980 if (phone == null) {
5981 return false;
5982 }
5983 final String subscriberId = phone.getSubscriberId();
5984
5985 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005986 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 + subscriberId + " to " + number);
5988 }
5989
5990 if (TextUtils.isEmpty(iccId)) {
5991 return false;
5992 }
5993
5994 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5995
5996 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5997 if (alphaTag == null) {
5998 editor.remove(alphaTagPrefKey);
5999 } else {
6000 editor.putString(alphaTagPrefKey, alphaTag);
6001 }
6002
6003 // Record both the line number and IMSI for this ICCID, since we need to
6004 // track all merged IMSIs based on line number
6005 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6006 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6007 if (number == null) {
6008 editor.remove(numberPrefKey);
6009 editor.remove(subscriberPrefKey);
6010 } else {
6011 editor.putString(numberPrefKey, number);
6012 editor.putString(subscriberPrefKey, subscriberId);
6013 }
6014
6015 editor.commit();
6016 return true;
6017 } finally {
6018 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006019 }
Derek Tan7226c842014-07-02 17:42:23 -07006020 }
6021
6022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006023 public String getLine1NumberForDisplay(int subId, String callingPackage,
6024 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006025 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006027 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006028 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006029 return null;
6030 }
Derek Tan97ebb422014-09-05 16:55:38 -07006031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 String iccId = getIccId(subId);
6035 if (iccId != null) {
6036 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6037 if (DBG_MERGE) {
6038 log("getLine1NumberForDisplay returning "
6039 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6040 }
6041 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6044 return null;
6045 } finally {
6046 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006047 }
Derek Tan7226c842014-07-02 17:42:23 -07006048 }
6049
6050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006051 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6052 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006054 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006055 return null;
6056 }
Derek Tan97ebb422014-09-05 16:55:38 -07006057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 final long identity = Binder.clearCallingIdentity();
6059 try {
6060 String iccId = getIccId(subId);
6061 if (iccId != null) {
6062 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6063 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6064 }
6065 return null;
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006068 }
Derek Tan7226c842014-07-02 17:42:23 -07006069 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006070
6071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006072 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6073 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006074 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6075 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006077 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006078 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006079 return null;
6080 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006081
Jordan Liub49b04b2019-05-06 14:45:15 -07006082 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6083 // the process, where TelephonyManager was instantiated.
6084 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006085 final long identity = Binder.clearCallingIdentity();
6086 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006087 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 final TelephonyManager tele = TelephonyManager.from(context);
6089 final SubscriptionManager sub = SubscriptionManager.from(context);
6090
6091 // Figure out what subscribers are currently active
6092 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093
Jordan Liub49b04b2019-05-06 14:45:15 -07006094 // Only consider subs which match the current subId
6095 // This logic can be simplified. See b/131189269 for progress.
6096 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006097 activeSubscriberIds.add(tele.getSubscriberId(subId));
6098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099
6100 // First pass, find a number override for an active subscriber
6101 String mergeNumber = null;
6102 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6103 for (String key : prefs.keySet()) {
6104 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6105 final String subscriberId = (String) prefs.get(key);
6106 if (activeSubscriberIds.contains(subscriberId)) {
6107 final String iccId = key.substring(
6108 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6109 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6110 mergeNumber = (String) prefs.get(numberKey);
6111 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006112 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 + " for active subscriber " + subscriberId);
6114 }
6115 if (!TextUtils.isEmpty(mergeNumber)) {
6116 break;
6117 }
6118 }
6119 }
6120 }
6121
6122 // Shortcut when no active merged subscribers
6123 if (TextUtils.isEmpty(mergeNumber)) {
6124 return null;
6125 }
6126
6127 // Second pass, find all subscribers under that line override
6128 final ArraySet<String> result = new ArraySet<>();
6129 for (String key : prefs.keySet()) {
6130 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6131 final String number = (String) prefs.get(key);
6132 if (mergeNumber.equals(number)) {
6133 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6134 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6135 final String subscriberId = (String) prefs.get(subscriberKey);
6136 if (!TextUtils.isEmpty(subscriberId)) {
6137 result.add(subscriberId);
6138 }
6139 }
6140 }
6141 }
6142
6143 final String[] resultArray = result.toArray(new String[result.size()]);
6144 Arrays.sort(resultArray);
6145 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006146 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6148 }
6149 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006150 } finally {
6151 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006152 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006153 }
6154
6155 @Override
zoey chen38003472019-12-13 17:16:31 +08006156 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6157 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006158
6159 final long identity = Binder.clearCallingIdentity();
6160 try {
6161 final TelephonyManager telephonyManager = mApp.getSystemService(
6162 TelephonyManager.class);
6163 String subscriberId = telephonyManager.getSubscriberId(subId);
6164 if (subscriberId == null) {
6165 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006166 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006167 + subId);
6168 }
6169 return null;
6170 }
6171
6172 final SubscriptionInfo info = SubscriptionController.getInstance()
6173 .getSubscriptionInfo(subId);
6174 final ParcelUuid groupUuid = info.getGroupUuid();
6175 // If it doesn't belong to any group, return just subscriberId of itself.
6176 if (groupUuid == null) {
6177 return new String[]{subscriberId};
6178 }
6179
6180 // Get all subscriberIds from the group.
6181 final List<String> mergedSubscriberIds = new ArrayList<>();
6182 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006183 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006184 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006185 for (SubscriptionInfo subInfo : groupInfos) {
6186 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6187 if (subscriberId != null) {
6188 mergedSubscriberIds.add(subscriberId);
6189 }
6190 }
6191
6192 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195
6196 }
6197 }
6198
6199 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006200 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006201 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006202 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
6206 final Phone phone = getPhone(subId);
6207 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006211 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006212
6213 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006214 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006215 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6216 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006217 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6218 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219
6220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 final Phone phone = getPhone(subId);
6223 if (phone == null) {
6224 return false;
6225 }
6226 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6227 cdmaNonRoamingList);
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006230 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006231 }
6232
6233 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006234 @Deprecated
6235 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6236 enforceModifyPermission();
6237
6238 int returnValue = 0;
6239 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006240 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006241 if(result.exception == null) {
6242 if (result.result != null) {
6243 byte[] responseData = (byte[])(result.result);
6244 if(responseData.length > oemResp.length) {
6245 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6246 responseData.length + "bytes. Buffer Size is " +
6247 oemResp.length + "bytes.");
6248 }
6249 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6250 returnValue = responseData.length;
6251 }
6252 } else {
6253 CommandException ex = (CommandException) result.exception;
6254 returnValue = ex.getCommandError().ordinal();
6255 if(returnValue > 0) returnValue *= -1;
6256 }
6257 } catch (RuntimeException e) {
6258 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6259 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6260 if(returnValue > 0) returnValue *= -1;
6261 }
6262
6263 return returnValue;
6264 }
6265
6266 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006267 public void setRadioCapability(RadioAccessFamily[] rafs) {
6268 try {
6269 ProxyController.getInstance().setRadioCapability(rafs);
6270 } catch (RuntimeException e) {
6271 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6272 }
6273 }
6274
6275 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006276 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006277 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006278 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006279 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006280 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 final long identity = Binder.clearCallingIdentity();
6283 try {
chen xub97461a2018-10-26 14:17:57 -07006284 TelephonyPermissions
6285 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6286 mApp, phone.getSubId(), "getRadioAccessFamily");
6287 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
chen xub97461a2018-10-26 14:17:57 -07006291 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006292 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006293
6294 @Override
6295 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006296 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006297 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298
6299 final long identity = Binder.clearCallingIdentity();
6300 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006301 ImsManager.getInstance(defaultPhone.getContext(),
6302 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006306 }
6307
6308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006309 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6312 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006313 return false;
6314 }
Svet Ganovb320e182015-04-16 12:30:10 -07006315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 final long identity = Binder.clearCallingIdentity();
6317 try {
6318 // Check the user preference and the system-level IMS setting. Even if the user has
6319 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6320 // In the long run, we may instead need to check if there exists a connection service
6321 // which can support video calling.
6322 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006323 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 return imsManager.isVtEnabledByPlatform()
6325 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6326 && imsManager.isVtEnabledByUser();
6327 } finally {
6328 Binder.restoreCallingIdentity(identity);
6329 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006330 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006331
Andrew Leea1239f22015-03-02 17:44:07 -08006332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006333 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6334 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006336 mApp, subId, callingPackage, callingFeatureId,
6337 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 return false;
6339 }
6340
6341 final long identity = Binder.clearCallingIdentity();
6342 try {
6343 CarrierConfigManager configManager =
6344 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006345 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
Andrew Leea1239f22015-03-02 17:44:07 -08006350 }
6351
6352 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006353 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006355 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 return false;
6357 }
6358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 CarrierConfigManager configManager =
6362 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006363 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
Andrew Leea1239f22015-03-02 17:44:07 -08006368 }
6369
Andrew Lee9431b832015-03-09 18:46:45 -07006370 @Override
6371 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006372 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006373 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006374 }
6375
6376 @Override
6377 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 final long identity = Binder.clearCallingIdentity();
6379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006380 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
Andrew Lee9431b832015-03-09 18:46:45 -07006384 }
6385
Hall Liuf6668912018-10-31 17:05:23 -07006386 /**
6387 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6388 * support for the feature and device firmware support.
6389 *
6390 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6391 */
6392 @Override
6393 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006395 final Phone phone = getPhone(subscriptionId);
6396 if (phone == null) {
6397 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6398 return false;
6399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006401 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6403 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006404 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 return isCarrierSupported && isDeviceSupported;
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
Hall Liu98187582018-01-22 19:15:32 -08006409 }
6410
Hall Liuf6668912018-10-31 17:05:23 -07006411 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006412 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6413 * RTT setting, will return true if the device and carrier both support RTT.
6414 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006415 */
6416 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 final long identity = Binder.clearCallingIdentity();
6418 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006419 boolean isRttSupported = isRttSupported(subscriptionId);
6420 boolean isUserRttSettingOn = Settings.Secure.getInt(
6421 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6422 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6423 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6424 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006428 }
6429
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006430 @Deprecated
6431 @Override
6432 public String getDeviceId(String callingPackage) {
6433 return getDeviceIdWithFeature(callingPackage, null);
6434 }
6435
Sanket Padawe7310cc72015-01-14 09:53:20 -08006436 /**
6437 * Returns the unique device ID of phone, for example, the IMEI for
6438 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6439 *
6440 * <p>Requires Permission:
6441 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6442 */
6443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006444 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006445 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006446 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006447 return null;
6448 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006449 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006450 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006451 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006452 return null;
6453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006454
6455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 return phone.getDeviceId();
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006461 }
6462
Ping Sunc67b7c22016-03-02 19:16:45 +08006463 /**
6464 * {@hide}
6465 * Returns the IMS Registration Status on a particular subid
6466 *
6467 * @param subId
6468 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006469 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006470 Phone phone = getPhone(subId);
6471 if (phone != null) {
6472 return phone.isImsRegistered();
6473 } else {
6474 return false;
6475 }
6476 }
6477
Santos Cordon7a1885b2015-02-03 11:15:19 -08006478 @Override
6479 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006486 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006487
Tyler Gunnf70ed162019-04-03 15:28:53 -07006488 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006489 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006490 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006492 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006493 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6494 }
6495 final long identity = Binder.clearCallingIdentity();
6496 try {
6497 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
6501 }
6502
6503 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006504 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 Phone phone = getPhone(subscriptionId);
6508 if (phone == null) {
6509 return null;
6510 }
6511 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
6515 }
6516
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006517 /**
6518 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006519 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006520 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521 final long identity = Binder.clearCallingIdentity();
6522 try {
6523 Phone phone = getPhone(subId);
6524 if (phone != null) {
6525 return phone.isWifiCallingEnabled();
6526 } else {
6527 return false;
6528 }
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006531 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006532 }
6533
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006534 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006535 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006536 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006537 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 Phone phone = getPhone(subId);
6541 if (phone != null) {
6542 return phone.isVideoEnabled();
6543 } else {
6544 return false;
6545 }
6546 } finally {
6547 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006548 }
6549 }
6550
6551 /**
6552 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6553 * defined in {@link ImsRegistrationImplBase}.
6554 */
6555 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 Phone phone = getPhone(subId);
6559 if (phone != null) {
6560 return phone.getImsRegistrationTech();
6561 } else {
6562 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6563 }
6564 } finally {
6565 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006566 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006567 }
6568
Stuart Scott8eef64f2015-04-08 15:13:54 -07006569 @Override
6570 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006571 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006572 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6573 return;
6574 }
6575
Svet Ganovcc087f82015-05-12 20:35:54 -07006576 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006577
Svet Ganovcc087f82015-05-12 20:35:54 -07006578 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006579 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6580 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006581 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006582 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006583 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006584 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6585 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006586 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006587 // There has been issues when Sms raw table somehow stores orphan
6588 // fragments. They lead to garbled message when new fragments come
6589 // in and combined with those stale ones. In case this happens again,
6590 // user can reset all network settings which will clean up this table.
6591 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006592 // Clean up IMS settings as well here.
6593 int slotId = getSlotIndex(subId);
6594 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6595 ImsManager.getInstance(mApp, slotId).factoryReset();
6596 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006597
6598 // Erase modem config if erase modem on network setting is enabled.
6599 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6600 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6601 if (configValue != null && Boolean.parseBoolean(configValue)) {
6602 sendEraseModemConfig(getDefaultPhone());
6603 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006604 } finally {
6605 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006606 }
6607 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006608
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006609 private void cleanUpSmsRawTable(Context context) {
6610 ContentResolver resolver = context.getContentResolver();
6611 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6612 resolver.delete(uri, null, null);
6613 }
6614
Narayan Kamath1c496c22015-04-16 14:40:19 +01006615 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006616 public String getSimLocaleForSubscriber(int subId) {
6617 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6618 final Phone phone = getPhone(subId);
6619 if (phone == null) {
6620 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006621 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
chen xu5d3637b2019-01-21 23:31:38 -08006625 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006626 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006627 if (info == null) {
6628 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6629 return null;
6630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 // Try and fetch the locale from the carrier properties or from the SIM language
6632 // preferences (EF-PL and EF-LI)...
6633 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006635 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6636 if (localeFromDefaultSim != null) {
6637 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6638 if (DBG) log("Using locale from subId: " + subId + " locale: "
6639 + localeFromDefaultSim);
6640 return localeFromDefaultSim.toLanguageTag();
6641 } else {
6642 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 }
6644 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 // The SIM language preferences only store a language (e.g. fr = French), not an
6647 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6648 // the SIM and carrier preferences does not include a country we add the country
6649 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006650 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006652 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 return mccLocale.toLanguageTag();
6654 }
6655
6656 if (DBG) log("No locale found - returning null");
6657 return null;
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006661 }
6662
6663 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006664 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006665 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006666 }
6667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 /**
6669 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6670 */
6671 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006672 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006673 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006674 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006675
Chenjie Yu1ba97252018-01-11 18:16:20 -08006676 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006677 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006678
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006679 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006680 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6681 * representing the state of the modem.
6682 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006683 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6684 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006685 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006686 */
6687 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006688 public void requestModemActivityInfo(ResultReceiver result) {
6689 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006694 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 } finally {
6696 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006697 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006698 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006699
Siddharth Rayb8114062018-06-17 15:02:38 -07006700 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6701 // less than total activity duration.
6702 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6703 if (info == null) {
6704 return false;
6705 }
6706 int activityDurationMs =
6707 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6708 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006709 int[] txTimeMs = info.getTransmitTimeMillis();
6710 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6711 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006712 }
6713 return (info.isValid()
6714 && (info.getSleepTimeMillis() <= activityDurationMs)
6715 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006716 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006717 && (totalTxTimeMs <= activityDurationMs));
6718 }
6719
Jack Yu85bd38a2015-11-09 11:34:32 -08006720 /**
6721 * {@hide}
6722 * Returns the service state information on specified subscription.
6723 */
6724 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006725 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6726 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006728 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006729 return null;
6730 }
6731
Hall Liuf19c44f2018-11-27 14:38:17 -08006732 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6733 LocationAccessPolicy.checkLocationPermission(mApp,
6734 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6735 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006736 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006737 .setCallingPid(Binder.getCallingPid())
6738 .setCallingUid(Binder.getCallingUid())
6739 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006740 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006741 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6742 .build());
6743
6744 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6745 LocationAccessPolicy.checkLocationPermission(mApp,
6746 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6747 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006748 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006749 .setCallingPid(Binder.getCallingPid())
6750 .setCallingUid(Binder.getCallingUid())
6751 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006752 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006753 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6754 .build());
6755 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6756 boolean hasFinePermission =
6757 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6758 boolean hasCoarsePermission =
6759 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 final Phone phone = getPhone(subId);
6764 if (phone == null) {
6765 return null;
6766 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006767
Hall Liuf19c44f2018-11-27 14:38:17 -08006768 ServiceState ss = phone.getServiceState();
6769
6770 // Scrub out the location info in ServiceState depending on what level of access
6771 // the caller has.
6772 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006773 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6774 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006778 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006779
6780 /**
6781 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6782 *
6783 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6784 * voicemail ringtone.
6785 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6786 * PhoneAccount.
6787 */
6788 @Override
6789 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6793 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006794 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006801 }
6802
6803 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006804 * Sets the per-account voicemail ringtone.
6805 *
6806 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6807 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6808 *
6809 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6810 * voicemail ringtone.
6811 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6812 * PhoneAccount.
6813 */
6814 @Override
6815 public void setVoicemailRingtoneUri(String callingPackage,
6816 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006817 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006819 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6820 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6822 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6823 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825
6826 final long identity = Binder.clearCallingIdentity();
6827 try {
6828 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6829 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006830 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 }
6832 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6833 } finally {
6834 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006835 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006836 }
6837
6838 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006839 * Returns whether vibration is set for voicemail notification in Phone settings.
6840 *
6841 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6842 * voicemail vibration setting.
6843 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6844 */
6845 @Override
6846 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
6849 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6850 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006851 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006858 }
6859
Youhan Wange64578a2016-05-02 15:32:42 -07006860 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006861 * Sets the per-account voicemail vibration.
6862 *
6863 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6864 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6865 *
6866 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6867 * voicemail vibration setting.
6868 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6869 * specific PhoneAccount.
6870 */
6871 @Override
6872 public void setVoicemailVibrationEnabled(String callingPackage,
6873 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006874 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006876 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6877 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6879 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6880 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006881 }
6882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6886 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006887 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 }
6889 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006892 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006893 }
6894
6895 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006896 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6897 *
6898 * @throws SecurityException if the caller does not have the required permission
6899 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006900 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006902 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006903 }
6904
6905 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006906 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6907 * permission.
6908 *
6909 * @throws SecurityException if the caller does not have the required permission
6910 */
6911 private void enforceSendSmsPermission() {
6912 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6913 }
6914
6915 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006916 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006917 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006918 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006919 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006920 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006924 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 if (componentName == null) {
6926 throw new SecurityException(
6927 "Caller not current active visual voicemail package[null]");
6928 }
6929 String vvmPackage = componentName.getPackageName();
6930 if (!callingPackage.equals(vvmPackage)) {
6931 throw new SecurityException("Caller not current active visual voicemail package["
6932 + vvmPackage + "]");
6933 }
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006936 }
6937 }
6938
6939 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006940 * Return the application ID for the app type.
6941 *
6942 * @param subId the subscription ID that this request applies to.
6943 * @param appType the uicc app type.
6944 * @return Application ID for specificied app type, or null if no uicc.
6945 */
6946 @Override
6947 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006948 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006949 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006952 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 if (phone == null) {
6954 return null;
6955 }
6956 String aid = null;
6957 try {
6958 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6959 .getApplicationByType(appType).getAid();
6960 } catch (Exception e) {
6961 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6962 }
6963 return aid;
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006966 }
Youhan Wange64578a2016-05-02 15:32:42 -07006967 }
6968
Youhan Wang4001d252016-05-11 10:29:41 -07006969 /**
6970 * Return the Electronic Serial Number.
6971 *
6972 * @param subId the subscription ID that this request applies to.
6973 * @return ESN or null if error.
6974 */
6975 @Override
6976 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006977 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006978 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979
6980 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006981 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 if (phone == null) {
6983 return null;
6984 }
6985 String esn = null;
6986 try {
6987 esn = phone.getEsn();
6988 } catch (Exception e) {
6989 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6990 }
6991 return esn;
6992 } finally {
6993 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006994 }
Youhan Wang4001d252016-05-11 10:29:41 -07006995 }
6996
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006997 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006998 * Return the Preferred Roaming List Version.
6999 *
7000 * @param subId the subscription ID that this request applies to.
7001 * @return PRLVersion or null if error.
7002 */
7003 @Override
7004 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007005 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007006 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007
7008 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007009 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 if (phone == null) {
7011 return null;
7012 }
7013 String cdmaPrlVersion = null;
7014 try {
7015 cdmaPrlVersion = phone.getCdmaPrlVersion();
7016 } catch (Exception e) {
7017 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7018 }
7019 return cdmaPrlVersion;
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007022 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007023 }
7024
7025 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007026 * Get snapshot of Telephony histograms
7027 * @return List of Telephony histograms
7028 * @hide
7029 */
7030 @Override
7031 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7033 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034
7035 final long identity = Binder.clearCallingIdentity();
7036 try {
7037 return RIL.getTelephonyRILTimingHistograms();
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
7040 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007041 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007042
7043 /**
7044 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007045 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7046 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007047 * Require system privileges. In the future we may add this to carrier APIs.
7048 *
Michele Berionne482f8202018-11-27 18:57:59 -08007049 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007050 */
7051 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007052 @TelephonyManager.SetCarrierRestrictionResult
7053 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007054 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007056
Michele Berionne482f8202018-11-27 18:57:59 -08007057 if (carrierRestrictionRules == null) {
7058 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007059 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 final long identity = Binder.clearCallingIdentity();
7062 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007063 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007064 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007068 }
7069
7070 /**
7071 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007072 * Get the allowed carrier list and the excluded carrier list, including the priority between
7073 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007074 * Require system privileges. In the future we may add this to carrier APIs.
7075 *
Michele Berionne482f8202018-11-27 18:57:59 -08007076 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007077 */
7078 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007079 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007080 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082
7083 final long identity = Binder.clearCallingIdentity();
7084 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007085 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7086 if (response instanceof CarrierRestrictionRules) {
7087 return (CarrierRestrictionRules) response;
7088 }
7089 // Response is an Exception of some kind,
7090 // which is signalled to the user as a NULL retval
7091 return null;
7092 } catch (Exception e) {
7093 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7094 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007098 }
7099
fionaxu59545b42016-05-25 15:53:37 -07007100 /**
7101 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7102 * @param subId the subscription ID that this action applies to.
7103 * @param enabled control enable or disable metered apns.
7104 * {@hide}
7105 */
7106 @Override
7107 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7108 enforceModifyPermission();
7109 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110
7111 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007112 if (phone == null) {
7113 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7114 return;
7115 }
7116 try {
7117 phone.carrierActionSetMeteredApnsEnabled(enabled);
7118 } catch (Exception e) {
7119 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 } finally {
7121 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007122 }
7123 }
7124
7125 /**
7126 * Action set from carrier signalling broadcast receivers to enable/disable radio
7127 * @param subId the subscription ID that this action applies to.
7128 * @param enabled control enable or disable radio.
7129 * {@hide}
7130 */
7131 @Override
7132 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7133 enforceModifyPermission();
7134 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135
7136 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007137 if (phone == null) {
7138 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7139 return;
7140 }
7141 try {
7142 phone.carrierActionSetRadioEnabled(enabled);
7143 } catch (Exception e) {
7144 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 } finally {
7146 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007147 }
7148 }
7149
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007150 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007151 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7152 * network status based on which carrier apps could apply actions accordingly,
7153 * enable/disable default url handler for example.
7154 *
7155 * @param subId the subscription ID that this action applies to.
7156 * @param report control start/stop reporting the default network status.
7157 * {@hide}
7158 */
7159 @Override
7160 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7161 enforceModifyPermission();
7162 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163
7164 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007165 if (phone == null) {
7166 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7167 return;
7168 }
7169 try {
7170 phone.carrierActionReportDefaultNetworkStatus(report);
7171 } catch (Exception e) {
7172 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 } finally {
7174 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007175 }
7176 }
7177
7178 /**
fionaxud9622282017-07-17 17:51:30 -07007179 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7180 * @param subId the subscription ID that this action applies to.
7181 * {@hide}
7182 */
7183 @Override
7184 public void carrierActionResetAll(int subId) {
7185 enforceModifyPermission();
7186 final Phone phone = getPhone(subId);
7187 if (phone == null) {
7188 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7189 return;
7190 }
7191 try {
7192 phone.carrierActionResetAll();
7193 } catch (Exception e) {
7194 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7195 }
7196 }
7197
7198 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007199 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7200 * bug report is being generated.
7201 */
7202 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007203 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007204 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7205 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007206 writer.println("Permission Denial: can't dump Phone from pid="
7207 + Binder.getCallingPid()
7208 + ", uid=" + Binder.getCallingUid()
7209 + "without permission "
7210 + android.Manifest.permission.DUMP);
7211 return;
7212 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007213 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007214 }
Jack Yueb89b242016-06-22 13:27:47 -07007215
Brad Ebingerdac2f002018-04-03 15:17:52 -07007216 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007217 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7218 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7219 @NonNull String[] args) {
7220 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7221 this, in.getFileDescriptor(), out.getFileDescriptor(),
7222 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007223 }
7224
Jack Yueb89b242016-06-22 13:27:47 -07007225 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007226 * Policy control of data connection. Usually used when data limit is passed.
7227 * @param enabled True if enabling the data, otherwise disabling.
7228 * @param subId Subscription index
7229 * {@hide}
7230 */
7231 @Override
7232 public void setPolicyDataEnabled(boolean enabled, int subId) {
7233 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 Phone phone = getPhone(subId);
7238 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007239 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 }
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007243 }
7244 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007245
7246 /**
7247 * Get Client request stats
7248 * @return List of Client Request Stats
7249 * @hide
7250 */
7251 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007252 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7253 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007255 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007256 return null;
7257 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007258 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 if (phone != null) {
7263 return phone.getClientRequestStats();
7264 }
7265
7266 return null;
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007270 }
7271
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007272 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007273 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007274 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007275 }
Jack Yueb4124c2017-02-16 15:32:43 -08007276
7277 /**
Grace Chen70990072017-03-24 17:21:30 -07007278 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007279 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007280 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007281 * @param state State of SIM (power down, power up, pass through)
7282 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7283 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7284 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007285 *
7286 **/
7287 @Override
Grace Chen70990072017-03-24 17:21:30 -07007288 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007289 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007290 Phone phone = PhoneFactory.getPhone(slotIndex);
7291
vagdeviaf9a5b92018-08-15 16:01:53 -07007292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007297 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 }
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007301 }
7302 }
Shuo Qiandd210312017-04-12 22:11:33 +00007303
Tyler Gunn65d45c22017-06-05 11:22:26 -07007304 private boolean isUssdApiAllowed(int subId) {
7305 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007306 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007307 if (configManager == null) {
7308 return false;
7309 }
7310 PersistableBundle pb = configManager.getConfigForSubId(subId);
7311 if (pb == null) {
7312 return false;
7313 }
7314 return pb.getBoolean(
7315 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7316 }
7317
Shuo Qiandd210312017-04-12 22:11:33 +00007318 /**
7319 * Check if phone is in emergency callback mode
7320 * @return true if phone is in emergency callback mode
7321 * @param subId sub id
7322 */
goneil9c5f4872017-12-05 14:07:56 -08007323 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007324 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007325 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007326 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 if (phone != null) {
7331 return phone.isInEcm();
7332 } else {
7333 return false;
7334 }
7335 } finally {
7336 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007337 }
7338 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007339
7340 /**
7341 * Get the current signal strength information for the given subscription.
7342 * Because this information is not updated when the device is in a low power state
7343 * it should not be relied-upon to be current.
7344 * @param subId Subscription index
7345 * @return the most recent cached signal strength info from the modem
7346 */
7347 @Override
7348 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 final long identity = Binder.clearCallingIdentity();
7350 try {
7351 Phone p = getPhone(subId);
7352 if (p == null) {
7353 return null;
7354 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 return p.getSignalStrength();
7357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007360 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007361
Pengquan Meng77b7f132018-08-22 14:49:57 -07007362 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007363 * Get the current modem radio state for the given slot.
7364 * @param slotIndex slot index.
7365 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007366 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007367 * @return the current radio power state from the modem
7368 */
7369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007370 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007371 Phone phone = PhoneFactory.getPhone(slotIndex);
7372 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7374 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007375 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7376 }
7377
7378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 return phone.getRadioPowerState();
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
7384 }
7385 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7386 }
7387
7388 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007389 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7390 *
7391 * <p>Requires one of the following permissions:
7392 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7393 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7394 * privileges.
7395 *
7396 * @param subId subscription id
7397 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7398 * {@code false}.
7399 */
7400 @Override
7401 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7403 null /* message */);
7404
Pengquan Menga1bb6272018-09-06 09:59:22 -07007405 boolean isEnabled = false;
7406 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007407 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007408 Phone phone = getPhone(subId);
7409 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007410 } catch (Exception e) {
7411 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7412 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007416 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007417 }
7418
7419
7420 /**
7421 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7422 *
7423 * <p> Requires permission:
7424 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7425 * privileges.
7426 *
7427 * @param subId subscription id
7428 * @param isEnabled {@code true} means enable, {@code false} means disable.
7429 */
7430 @Override
7431 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7433 mApp, subId, "setDataRoamingEnabled");
7434
Pengquan Menga1bb6272018-09-06 09:59:22 -07007435 final long identity = Binder.clearCallingIdentity();
7436 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007437 Phone phone = getPhone(subId);
7438 if (phone != null) {
7439 phone.setDataRoamingEnabled(isEnabled);
7440 }
7441 } finally {
7442 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007443 }
7444 }
7445
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007446 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007447 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007448 TelephonyPermissions
7449 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007450 mApp, subId, "isManualNetworkSelectionAllowed");
7451
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007452 boolean isAllowed = true;
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007455 Phone phone = getPhone(subId);
7456 if (phone != null) {
7457 isAllowed = phone.isCspPlmnEnabled();
7458 }
7459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
7462 return isAllowed;
7463 }
7464
7465 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007466 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007467 // Verify that tha callingPackage belongs to the calling UID
7468 mApp.getSystemService(AppOpsManager.class)
7469 .checkPackage(Binder.getCallingUid(), callingPackage);
7470
Jordan Liu1e142fc2019-04-22 15:10:43 -07007471 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007472 try {
7473 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007474 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007475 } catch (SecurityException e) {
7476 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7477 // has carrier privileges on an active UICC
7478 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7479 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007480 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007481 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007482 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007486 UiccController uiccController = UiccController.getInstance();
7487 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007488 if (hasReadPermission) {
7489 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007490 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007491
7492 // Remove private info if the caller doesn't have access
7493 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7494 for (UiccCardInfo cardInfo : cardInfos) {
7495 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7496 // is available
7497 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7498 if (card == null || card.getUiccProfile() == null) {
7499 // assume no access if the card or profile is unavailable
7500 filteredInfos.add(cardInfo.getUnprivileged());
7501 continue;
7502 }
7503 UiccProfile profile = card.getUiccProfile();
7504 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7505 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7506 filteredInfos.add(cardInfo);
7507 } else {
7508 filteredInfos.add(cardInfo.getUnprivileged());
7509 }
7510 }
7511 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
7515 }
7516
7517 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007518 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007519 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7524 if (slots == null) {
7525 Rlog.i(LOG_TAG, "slots is null.");
7526 return null;
7527 }
7528
7529 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7530 for (int i = 0; i < slots.length; i++) {
7531 UiccSlot slot = slots[i];
7532 if (slot == null) {
7533 continue;
7534 }
7535
Jordan Liu7be7e652019-05-06 18:55:02 +00007536 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 UiccCard card = slot.getUiccCard();
7538 if (card != null) {
7539 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007540 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007541 cardId = slot.getEid();
7542 if (TextUtils.isEmpty(cardId)) {
7543 cardId = slot.getIccId();
7544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 }
7546
Jordan Liu857451f2019-05-09 16:35:35 -07007547 if (cardId != null) {
7548 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7549 // if cardId is an EID, it's all digits so this is fine
7550 cardId = IccUtils.stripTrailingFs(cardId);
7551 }
7552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 int cardState = 0;
7554 switch (slot.getCardState()) {
7555 case CARDSTATE_ABSENT:
7556 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7557 break;
7558 case CARDSTATE_PRESENT:
7559 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7560 break;
7561 case CARDSTATE_ERROR:
7562 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7563 break;
7564 case CARDSTATE_RESTRICTED:
7565 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7566 break;
7567 default:
7568 break;
7569
7570 }
7571
7572 infos[i] = new UiccSlotInfo(
7573 slot.isActive(),
7574 slot.isEuicc(),
7575 cardId,
7576 cardState,
7577 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007578 slot.isExtendedApduSupported(),
7579 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 }
7581 return infos;
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007584 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007585 }
7586
7587 @Override
7588 public boolean switchSlots(int[] physicalSlots) {
7589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590
7591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007597 }
Jack Yu4c988042018-02-27 15:30:01 -08007598
7599 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007600 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 return UiccController.getInstance().getCardIdForDefaultEuicc();
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
7607 }
7608
Pengquan Meng85728fb2018-03-12 16:31:21 -07007609 /**
goneil47ffb6e2018-04-06 15:40:58 -07007610 * A test API to reload the UICC profile.
7611 *
7612 * <p>Requires that the calling app has permission
7613 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7614 * @hide
7615 */
7616 @Override
7617 public void refreshUiccProfile(int subId) {
7618 enforceModifyPermission();
7619
7620 final long identity = Binder.clearCallingIdentity();
7621 try {
7622 Phone phone = getPhone(subId);
7623 if (phone == null) {
7624 return;
7625 }
7626 UiccCard uiccCard = phone.getUiccCard();
7627 if (uiccCard == null) {
7628 return;
7629 }
7630 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7631 if (uiccProfile == null) {
7632 return;
7633 }
7634 uiccProfile.refresh();
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
7639
7640 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007641 * Returns false if the mobile data is disabled by default, otherwise return true.
7642 */
7643 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007644 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007645 }
7646
7647 /**
7648 * Returns true if the data roaming is enabled by default, i.e the system property
7649 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7650 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7651 */
7652 private boolean getDefaultDataRoamingEnabled(int subId) {
7653 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007654 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007655 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007656 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7657 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7658 return isDataRoamingEnabled;
7659 }
7660
7661 /**
7662 * Returns the default network type for the given {@code subId}, if the default network type is
7663 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7664 */
7665 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007666 List<Integer> list = TelephonyProperties.default_network();
7667 int phoneId = mSubscriptionController.getPhoneId(subId);
7668 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7669 return list.get(phoneId);
7670 }
7671 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007672 }
fionaxua13278b2018-03-21 00:08:13 -07007673
7674 @Override
7675 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007676 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 final Phone phone = getPhone(subId);
7682 if (phone == null) {
7683 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7684 return;
7685 }
chen xueaba88a2019-03-15 13:15:10 -07007686 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7687 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007688 if (carrierPrivilegeRules == null) {
7689 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7690 } else {
7691 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 } finally {
7694 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007695 }
fionaxua13278b2018-03-21 00:08:13 -07007696 }
7697
7698 @Override
7699 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007700 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701
7702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 final Phone phone = getPhone(subId);
7705 if (phone == null) {
7706 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7707 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7708 }
7709 return phone.getCarrierIdListVersion();
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007712 }
fionaxua13278b2018-03-21 00:08:13 -07007713 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007714
7715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007716 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7717 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007719 mApp, subId, callingPackage, callingFeatureId,
7720 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007721 return -1;
7722 }
7723
7724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
7730 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007731
7732 @Override
7733 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007734 TelephonyPermissions
7735 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007736 mApp, subId, "getCdmaRoamingMode");
7737
7738 final long identity = Binder.clearCallingIdentity();
7739 try {
7740 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
7744 }
7745
7746 @Override
7747 public boolean setCdmaRoamingMode(int subId, int mode) {
7748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7749 mApp, subId, "setCdmaRoamingMode");
7750
7751 final long identity = Binder.clearCallingIdentity();
7752 try {
7753 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 }
7758
7759 @Override
7760 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7762 mApp, subId, "setCdmaSubscriptionMode");
7763
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
7770 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007771
sqianc5eccab2018-10-19 18:46:41 -07007772 @Override
sqian8c685422019-02-22 15:55:18 -08007773 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007774 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007776 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7777 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007778 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7779 }
7780 final long identity = Binder.clearCallingIdentity();
7781 try {
sqian854d44b2018-12-12 16:48:18 -08007782 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7783 for (Phone phone: PhoneFactory.getPhones()) {
7784 if (phone.getEmergencyNumberTracker() != null
7785 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7786 emergencyNumberListInternal.put(
7787 phone.getSubId(),
7788 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7789 }
sqian11b7a0e2018-12-05 18:48:28 -08007790 }
sqian854d44b2018-12-12 16:48:18 -08007791 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007792 } finally {
7793 Binder.restoreCallingIdentity(identity);
7794 }
sqianc5eccab2018-10-19 18:46:41 -07007795 }
7796
7797 @Override
sqian8c685422019-02-22 15:55:18 -08007798 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007799 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007800 if (!exactMatch) {
7801 TelephonyPermissions
7802 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007803 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007804 }
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
sqian854d44b2018-12-12 16:48:18 -08007807 for (Phone phone: PhoneFactory.getPhones()) {
7808 if (phone.getEmergencyNumberTracker() != null
7809 && phone.getEmergencyNumberTracker() != null) {
7810 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7811 number, exactMatch)) {
7812 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007813 }
7814 }
sqian11b7a0e2018-12-05 18:48:28 -08007815 }
7816 return false;
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
7820 }
7821
sqianf4ca7ed2019-01-15 18:32:07 -08007822 /**
7823 * Update emergency number list for test mode.
7824 */
7825 @Override
7826 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7828 "updateEmergencyNumberListTestMode");
7829
7830 final long identity = Binder.clearCallingIdentity();
7831 try {
7832 for (Phone phone: PhoneFactory.getPhones()) {
7833 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7834 if (tracker != null) {
7835 tracker.executeEmergencyNumberTestModeCommand(action, num);
7836 }
7837 }
7838 } finally {
7839 Binder.restoreCallingIdentity(identity);
7840 }
7841 }
7842
7843 /**
7844 * Get the full emergency number list for test mode.
7845 */
7846 @Override
7847 public List<String> getEmergencyNumberListTestMode() {
7848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7849 "getEmergencyNumberListTestMode");
7850
7851 final long identity = Binder.clearCallingIdentity();
7852 try {
7853 Set<String> emergencyNumbers = new HashSet<>();
7854 for (Phone phone: PhoneFactory.getPhones()) {
7855 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7856 if (tracker != null) {
7857 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7858 emergencyNumbers.add(num.getNumber());
7859 }
7860 }
7861 }
7862 return new ArrayList<>(emergencyNumbers);
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
7865 }
7866 }
7867
chen xud6b45bd2018-10-30 22:27:10 -07007868 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007869 public int getEmergencyNumberDbVersion(int subId) {
7870 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7871
7872 final long identity = Binder.clearCallingIdentity();
7873 try {
7874 final Phone phone = getPhone(subId);
7875 if (phone == null) {
7876 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7877 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7878 }
7879 return phone.getEmergencyNumberDbVersion();
7880 } finally {
7881 Binder.restoreCallingIdentity(identity);
7882 }
7883 }
7884
7885 @Override
7886 public void notifyOtaEmergencyNumberDbInstalled() {
7887 enforceModifyPermission();
7888
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
7891 for (Phone phone: PhoneFactory.getPhones()) {
7892 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7893 if (tracker != null) {
7894 tracker.updateOtaEmergencyNumberDatabase();
7895 }
7896 }
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
7900 }
7901
7902 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007903 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007904 enforceActiveEmergencySessionPermission();
7905
7906 final long identity = Binder.clearCallingIdentity();
7907 try {
7908 for (Phone phone: PhoneFactory.getPhones()) {
7909 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7910 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007911 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7912 }
7913 }
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
7917 }
7918
7919 @Override
7920 public void resetOtaEmergencyNumberDbFilePath() {
7921 enforceActiveEmergencySessionPermission();
7922
7923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 for (Phone phone: PhoneFactory.getPhones()) {
7926 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7927 if (tracker != null) {
7928 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007929 }
7930 }
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
7934 }
7935
7936 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007937 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7938 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7939 Phone phone = getPhone(subId);
7940 if (phone == null) {
7941 return null;
7942 }
7943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 UiccProfile profile = UiccController.getInstance()
7946 .getUiccProfileForPhone(phone.getPhoneId());
7947 if (profile != null) {
7948 return profile.getCertsFromCarrierPrivilegeAccessRules();
7949 }
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
7952 }
7953 return null;
7954 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007955
7956 /**
7957 * Enable or disable a modem stack.
7958 */
7959 @Override
7960 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7961 enforceModifyPermission();
7962
7963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 Phone phone = PhoneFactory.getPhone(slotIndex);
7966 if (phone == null) {
7967 return false;
7968 } else {
7969 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7970 }
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
7974 }
Michelecea4cf22018-12-21 15:00:11 -08007975
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007976 /**
7977 * Whether a modem stack is enabled or not.
7978 */
7979 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007980 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7981 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007982 Phone phone = PhoneFactory.getPhone(slotIndex);
7983 if (phone == null) return false;
7984
7985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007986 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7987 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007988 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7989 }
7990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007993 try {
7994 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7995 } catch (NoSuchElementException ex) {
7996 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7997 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007998 } finally {
7999 Binder.restoreCallingIdentity(identity);
8000 }
8001 }
8002
Michelecea4cf22018-12-21 15:00:11 -08008003 @Override
Michele0ea7d782019-03-19 14:58:42 -07008004 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008005 enforceModifyPermission();
8006
8007 final long identity = Binder.clearCallingIdentity();
8008 try {
8009 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008010 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008011 .commit();
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014 }
8015 }
8016
8017 @Override
Michele0ea7d782019-03-19 14:58:42 -07008018 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008019 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008021 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8022 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008023 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008024 }
Michelecea4cf22018-12-21 15:00:11 -08008025
8026 final long identity = Binder.clearCallingIdentity();
8027 try {
Michele0ea7d782019-03-19 14:58:42 -07008028 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008029 } finally {
8030 Binder.restoreCallingIdentity(identity);
8031 }
8032 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008033
Michele0ea7d782019-03-19 14:58:42 -07008034 @TelephonyManager.IsMultiSimSupportedResult
8035 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008036 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8037 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8038 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008039 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8040 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008041 }
8042 // Check if the hardware supports multisim functionality. If usage of multisim is not
8043 // supported by the modem, indicate that it is restricted.
8044 PhoneCapability staticCapability =
8045 mPhoneConfigurationManager.getStaticPhoneCapability();
8046 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008047 loge("isMultiSimSupportedInternal: no static configuration available");
8048 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008049 }
Sarah Chin7caee492020-02-18 20:49:02 +00008050 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008051 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8052 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008053 }
8054 // Check if support of multiple SIMs is restricted by carrier
8055 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008056 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008057 }
8058
Michele0ea7d782019-03-19 14:58:42 -07008059 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008060 }
8061
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008062 /**
8063 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008064 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8065 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8066 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008067 * @param numOfSims number of active sims we want to switch to
8068 */
8069 @Override
8070 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008071 if (numOfSims == 1) {
8072 enforceModifyPermission();
8073 } else {
8074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8075 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8076 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008077 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008078
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008079 try {
Michele30b57b22019-03-01 12:01:14 -08008080 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008081 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008082 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8083 return;
8084 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008085 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
8089 }
8090
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008091 @Override
8092 public boolean isApplicationOnUicc(int subId, int appType) {
8093 enforceReadPrivilegedPermission("isApplicationOnUicc");
8094 Phone phone = getPhone(subId);
8095 if (phone == null) {
8096 return false;
8097 }
8098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 UiccCard uiccCard = phone.getUiccCard();
8101 if (uiccCard == null) {
8102 return false;
8103 }
8104 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8105 if (uiccProfile == null) {
8106 return false;
8107 }
8108 if (TelephonyManager.APPTYPE_SIM <= appType
8109 && appType <= TelephonyManager.APPTYPE_ISIM) {
8110 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8111 }
8112 return false;
8113 } finally {
8114 Binder.restoreCallingIdentity(identity);
8115 }
8116 }
8117
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008118 /**
chen xub4baa772019-04-03 10:23:41 -07008119 * Get whether making changes to modem configurations will trigger reboot.
8120 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008121 */
8122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008123 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8124 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008126 mApp, subId, callingPackage, callingFeatureId,
8127 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008128 return false;
8129 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
8136 }
8137
Nathan Harold29f5f052019-02-15 13:41:57 -08008138 private void updateModemStateMetrics() {
8139 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8140 // TODO: check the state for each modem if the api is ready.
8141 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8142 }
8143
Pengquan Meng3889a572019-01-23 11:16:29 -08008144 @Override
8145 public int[] getSlotsMapping() {
8146 enforceReadPrivilegedPermission("getSlotsMapping");
8147
8148 final long identity = Binder.clearCallingIdentity();
8149 try {
8150 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8151 // All logical slots should have a mapping to a physical slot.
8152 int[] logicalSlotsMapping = new int[phoneCount];
8153 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8154 for (int i = 0; i < slotInfos.length; i++) {
8155 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8156 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8157 }
8158 }
8159 return logicalSlotsMapping;
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
8163 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008164
8165 /**
8166 * Get the IRadio HAL Version
8167 */
8168 @Override
8169 public int getRadioHalVersion() {
8170 Phone phone = getDefaultPhone();
8171 if (phone == null) return -1;
8172 HalVersion hv = phone.getHalVersion();
8173 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8174 return hv.major * 100 + hv.minor;
8175 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008176
8177 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008178 * Get the current calling package name.
8179 * @return the current calling package name
8180 */
8181 @Override
8182 public String getCurrentPackageName() {
8183 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8184 }
8185
8186 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008187 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8188 * corresponding network requests on a subId.
8189 *
8190 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008191 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008192 * 2) APN is un-metered for this subscription, or
8193 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008194 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008195 *
8196 * @return whether data is allowed for a apn type.
8197 *
8198 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008199 */
8200 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008201 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008202 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8203 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008204
8205 // Now that all security checks passes, perform the operation as ourselves.
8206 final long identity = Binder.clearCallingIdentity();
8207 try {
8208 Phone phone = getPhone(subId);
8209 if (phone == null) return false;
8210
Jack Yu41407ee2019-05-13 16:54:09 -07008211 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008212 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
8216 }
8217
8218 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008219 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008220 enforceReadPrivilegedPermission("isApnMetered");
8221
8222 // Now that all security checks passes, perform the operation as ourselves.
8223 final long identity = Binder.clearCallingIdentity();
8224 try {
8225 Phone phone = getPhone(subId);
8226 if (phone == null) return true; // By default return true.
8227
Jack Yu41407ee2019-05-13 16:54:09 -07008228 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
8232 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008233
8234 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008235 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8236 int subscriptionId, IBooleanConsumer resultCallback) {
8237 enforceModifyPermission();
8238 long token = Binder.clearCallingIdentity();
8239 try {
8240 Phone phone = getPhone(subscriptionId);
8241 if (phone == null) {
8242 try {
8243 if (resultCallback != null) {
8244 resultCallback.accept(false);
8245 }
8246 } catch (RemoteException e) {
8247 // ignore
8248 }
8249 return;
8250 }
8251 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8252 Pair.create(specifiers, (x) -> {
8253 try {
8254 if (resultCallback != null) {
8255 resultCallback.accept(x);
8256 }
8257 } catch (RemoteException e) {
8258 // ignore
8259 }
8260 });
8261 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8262 } finally {
8263 Binder.restoreCallingIdentity(token);
8264 }
8265 }
8266
8267 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008268 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008269 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008270 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8271 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8272 if (iccRecords == null) {
8273 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8274 return false;
8275 }
8276 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8277 }
8278
8279 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008280 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8281 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008282 if (callingPackage == null) {
8283 callingPackage = getCurrentPackageName();
8284 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008285 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8286 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008287 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8288 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008289 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8290 }
8291 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8292 Intent intent = new Intent();
8293 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8294 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8295 // Bring up choose default SMS subscription dialog right now
8296 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8297 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8298 mApp.startActivity(intent);
8299 }
chen xud5ca2d52019-05-28 15:20:57 -07008300
8301 @Override
8302 public String getMmsUAProfUrl(int subId) {
8303 //TODO investigate if this API should require proper permission check in R b/133791609
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008306 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8307 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008308 } finally {
8309 Binder.restoreCallingIdentity(identity);
8310 }
8311 }
8312
8313 @Override
8314 public String getMmsUserAgent(int subId) {
8315 //TODO investigate if this API should require proper permission check in R b/133791609
8316 final long identity = Binder.clearCallingIdentity();
8317 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008318 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8319 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
Jack Yub07d4972019-05-28 16:12:25 -07008324
8325 @Override
8326 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8327 enforceModifyPermission();
8328
8329 // Now that all security checks passes, perform the operation as ourselves.
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
8332 Phone phone = getPhone(subId);
8333 if (phone == null) return false;
8334
8335 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 }
8340
8341 @Override
8342 public boolean isDataAllowedInVoiceCall(int subId) {
8343 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8344
8345 // Now that all security checks passes, perform the operation as ourselves.
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
8348 Phone phone = getPhone(subId);
8349 if (phone == null) return false;
8350
8351 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008356
changbettyd5c246e2019-12-24 15:40:37 +08008357 @Override
8358 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8359 enforceModifyPermission();
8360
8361 // Now that all security checks passes, perform the operation as ourselves.
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
8364 Phone phone = getPhone(subId);
8365 if (phone == null) return false;
8366
8367 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
8372
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008373 /**
8374 * Updates whether conference event pacakge handling is enabled.
8375 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8376 * otherwise.
8377 */
8378 @Override
8379 public void setCepEnabled(boolean isCepEnabled) {
8380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8381
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8385 for (Phone phone : PhoneFactory.getPhones()) {
8386 Phone defaultPhone = phone.getImsPhone();
8387 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8388 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8389 ImsPhoneCallTracker imsPhoneCallTracker =
8390 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8391 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8392 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8393 + imsPhone.getMsisdn());
8394 }
8395 }
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 }
allenwtsu46dcc572020-01-08 18:24:03 +08008400
8401 /**
8402 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8403 *
8404 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8405 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8406 * before being read.
8407 */
8408 @Override
8409 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8410 isCompressed) {
8411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8412 mApp, subId, "notifyRcsAutoConfigurationReceived");
8413 try {
8414 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8415 if (configBinder == null) {
8416 Rlog.e(LOG_TAG, "null result for getImsConfig");
8417 } else {
8418 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8419 }
8420 } catch (RemoteException e) {
8421 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8422 }
8423 }
zoey chene02881a2019-12-30 16:11:23 +08008424
8425 @Override
8426 public boolean isIccLockEnabled(int subId) {
8427 enforceReadPrivilegedPermission("isIccLockEnabled");
8428
8429 // Now that all security checks passes, perform the operation as ourselves.
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 Phone phone = getPhone(subId);
8433 if (phone != null && phone.getIccCard() != null) {
8434 return phone.getIccCard().getIccLockEnabled();
8435 } else {
8436 return false;
8437 }
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
8443 /**
8444 * Set the ICC pin lock enabled or disabled.
8445 *
8446 * @return an integer representing the status of IccLock enabled or disabled in the following
8447 * three cases:
8448 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8449 * successfully.
8450 * - Positive number and zero for remaining password attempts.
8451 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8452 *
8453 */
8454 @Override
8455 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8456 enforceModifyPermission();
8457
8458 Phone phone = getPhone(subId);
8459 if (phone == null) {
8460 return 0;
8461 }
8462 // Now that all security checks passes, perform the operation as ourselves.
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8466 new Pair<Boolean, String>(enabled, password), phone, null);
8467 return attemptsRemaining;
8468
8469 } catch (Exception e) {
8470 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 return 0;
8475 }
8476
8477 /**
8478 * Change the ICC password used in ICC pin lock.
8479 *
8480 * @return an integer representing the status of IccLock changed in the following three cases:
8481 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8482 * - Positive number and zero for remaining password attempts.
8483 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8484 *
8485 */
8486 @Override
8487 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8488 enforceModifyPermission();
8489
8490 Phone phone = getPhone(subId);
8491 if (phone == null) {
8492 return 0;
8493 }
8494 // Now that all security checks passes, perform the operation as ourselves.
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8498 new Pair<String, String>(oldPassword, newPassword), phone, null);
8499 return attemptsRemaining;
8500
8501 } catch (Exception e) {
8502 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 return 0;
8507 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008508
8509 /**
8510 * Request for receiving user activity notification
8511 */
8512 @Override
8513 public void requestUserActivityNotification() {
8514 if (!mNotifyUserActivity.get()
8515 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8516 mNotifyUserActivity.set(true);
8517 }
8518 }
8519
8520 /**
8521 * Called when userActivity is signalled in the power manager.
8522 * This is safe to call from any thread, with any window manager locks held or not.
8523 */
8524 @Override
8525 public void userActivity() {
8526 // ***************************************
8527 // * Inherited from PhoneWindowManager *
8528 // ***************************************
8529 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8530 // WITH ITS LOCKS HELD.
8531 //
8532 // This code must be VERY careful about the locks
8533 // it acquires.
8534 // In fact, the current code acquires way too many,
8535 // and probably has lurking deadlocks.
8536
8537 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8538 throw new SecurityException("Only the OS may call notifyUserActivity()");
8539 }
8540
8541 if (mNotifyUserActivity.getAndSet(false)) {
8542 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8543 USER_ACTIVITY_NOTIFICATION_DELAY);
8544 }
8545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008546}