blob: 46c80ccc3f31f608dcd14a44be2897ed901187d6 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800193import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800282 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800283 private static final int CMD_GET_CALL_FORWARDING = 83;
284 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
285 private static final int CMD_SET_CALL_FORWARDING = 85;
286 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
287 private static final int CMD_GET_CALL_WAITING = 87;
288 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
289 private static final int CMD_SET_CALL_WAITING = 89;
290 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800292 // Parameters of select command.
293 private static final int SELECT_COMMAND = 0xA4;
294 private static final int SELECT_P1 = 0x04;
295 private static final int SELECT_P2 = 0;
296 private static final int SELECT_P3 = 0x10;
297
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 /** The singleton instance. */
299 private static PhoneInterfaceManager sInstance;
300
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800303 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700304 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private AppOpsManager mAppOps;
306 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800307 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700309 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 /** User Activity */
312 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
314
Derek Tan97ebb422014-09-05 16:55:38 -0700315 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
316 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800317 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800318 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700319
Michelecea4cf22018-12-21 15:00:11 -0800320 // String to store multi SIM allowed
321 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
322
Derek Tan740e1672017-06-27 14:56:27 -0700323 // The AID of ISD-R.
324 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
325
yinxub1bed742017-04-17 11:45:04 -0700326 private NetworkScanRequestTracker mNetworkScanRequestTracker;
327
David Kelly5e06a7f2018-03-12 14:10:59 +0000328 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
329 private static final int MANUFACTURER_CODE_LENGTH = 8;
330
Derek Tan89e89d42014-07-08 17:00:10 -0700331 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700332 * Experiment flag to enable erase modem config on reset network, default value is false
333 */
334 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
335 "reset_network_erase_modem_config_enabled";
336
337 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700338 * A request object to use for transmitting data to an ICC.
339 */
340 private static final class IccAPDUArgument {
341 public int channel, cla, command, p1, p2, p3;
342 public String data;
343
344 public IccAPDUArgument(int channel, int cla, int command,
345 int p1, int p2, int p3, String data) {
346 this.channel = channel;
347 this.cla = cla;
348 this.command = command;
349 this.p1 = p1;
350 this.p2 = p2;
351 this.p3 = p3;
352 this.data = data;
353 }
354 }
355
356 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700357 * A request object to use for transmitting data to an ICC.
358 */
359 private static final class ManualNetworkSelectionArgument {
360 public OperatorInfo operatorInfo;
361 public boolean persistSelection;
362
363 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
364 this.operatorInfo = operatorInfo;
365 this.persistSelection = persistSelection;
366 }
367 }
368
369 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
371 * request after sending. The main thread will notify the request when it is complete.
372 */
373 private static final class MainThreadRequest {
374 /** The argument to use for the request */
375 public Object argument;
376 /** The result of the request that is run on the main thread */
377 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800378 // The subscriber id that this request applies to. Defaults to
379 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
380 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Nathan Harold92bed182018-10-12 18:16:49 -0700382 // In cases where subId is unavailable, the caller needs to specify the phone.
383 public Phone phone;
384
vagdeviaf9a5b92018-08-15 16:01:53 -0700385 public WorkSource workSource;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 public MainThreadRequest(Object argument) {
388 this.argument = argument;
389 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800390
Nathan Harold92bed182018-10-12 18:16:49 -0700391 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
392 this.argument = argument;
393 if (phone != null) {
394 this.phone = phone;
395 }
396 this.workSource = workSource;
397 }
398
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800401 if (subId != null) {
402 this.subId = subId;
403 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700404 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 }
407
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800408 private static final class IncomingThirdPartyCallArgs {
409 public final ComponentName component;
410 public final String callId;
411 public final String callerDisplayName;
412
413 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
414 String callerDisplayName) {
415 this.component = component;
416 this.callId = callId;
417 this.callerDisplayName = callerDisplayName;
418 }
419 }
420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /**
422 * A handler that processes messages on the main thread in the phone process. Since many
423 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
424 * inbound binder threads to the main thread in the phone process. The Binder thread
425 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
426 * on, which will be notified when the operation completes and will contain the result of the
427 * request.
428 *
429 * <p>If a MainThreadRequest object is provided in the msg.obj field,
430 * note that request.result must be set to something non-null for the calling thread to
431 * unblock.
432 */
433 private final class MainThreadHandler extends Handler {
434 @Override
435 public void handleMessage(Message msg) {
436 MainThreadRequest request;
437 Message onCompleted;
438 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800441 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
443 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 case CMD_HANDLE_USSD_REQUEST: {
445 request = (MainThreadRequest) msg.obj;
446 final Phone phone = getPhoneFromRequest(request);
447 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
448 String ussdRequest = ussdObject.first;
449 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 if (!isUssdApiAllowed(request.subId)) {
452 // Carrier does not support use of this API, return failure.
453 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
454 UssdResponse response = new UssdResponse(ussdRequest, null);
455 Bundle returnData = new Bundle();
456 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
457 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 request.result = true;
460 notifyRequester(request);
461 return;
462 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700463
Pengquan Menga1bb6272018-09-06 09:59:22 -0700464 try {
465 request.result = phone != null
466 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
467 } catch (CallStateException cse) {
468 request.result = false;
469 }
470 // Wake up the requesting thread
471 notifyRequester(request);
472 break;
pkanwar32d516d2016-10-14 19:37:38 -0700473 }
474
Yorke Lee716f67e2015-06-17 15:39:16 -0700475 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 final Phone phone = getPhoneFromRequest(request);
478 request.result = phone != null ?
479 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
480 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduLogicalChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
496 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 iccArgument.channel, iccArgument.cla, iccArgument.command,
499 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 break;
503
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 if (ar.result == null) {
512 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800513 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800515 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 } else {
517 loge("iccTransmitApduLogicalChannel: Unknown exception");
518 }
519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 break;
522
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
524 request = (MainThreadRequest) msg.obj;
525 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 if (uiccCard == null) {
528 loge("iccTransmitApduBasicChannel: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 } else {
532 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
533 request);
534 uiccCard.iccTransmitApduBasicChannel(
535 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
536 iccArgument.p3, iccArgument.data, onCompleted);
537 }
538 break;
539
540 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduBasicChannel: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("iccTransmitApduBasicChannel: CommandException: " +
551 ar.exception);
552 } else {
553 loge("iccTransmitApduBasicChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
559 case CMD_EXCHANGE_SIM_IO:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccExchangeSimIO: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
569 request);
570 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
571 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
572 iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_EXCHANGE_SIM_IO_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6f, 0, (byte[])null);
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 case CMD_SEND_ENVELOPE:
588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("sendEnvelopeWithStatus: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
596 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
597 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800598 break;
599
600 case EVENT_SEND_ENVELOPE_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700603 if (ar.exception == null && ar.result != null) {
604 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800605 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
607 if (ar.result == null) {
608 loge("sendEnvelopeWithStatus: Empty response");
609 } else if (ar.exception instanceof CommandException) {
610 loge("sendEnvelopeWithStatus: CommandException: " +
611 ar.exception);
612 } else {
613 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
614 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 break;
618
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 case CMD_OPEN_CHANNEL:
620 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 if (uiccCard == null) {
624 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800625 request.result = new IccOpenLogicalChannelResponse(-1,
626 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800630 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
631 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_OPEN_CHANNEL_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 int[] result = (int[]) ar.result;
641 int channelId = result[0];
642 byte[] selectResponse = null;
643 if (result.length > 1) {
644 selectResponse = new byte[result.length - 1];
645 for (int i = 1; i < result.length; ++i) {
646 selectResponse[i - 1] = (byte) result[i];
647 }
648 }
649 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700650 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 if (ar.result == null) {
653 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 if (ar.exception != null) {
656 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
657 }
658
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700660 if (ar.exception instanceof CommandException) {
661 CommandException.Error error =
662 ((CommandException) (ar.exception)).getCommandError();
663 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700664 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700665 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 }
668 }
669 openChannelResp = new IccOpenLogicalChannelResponse(
670 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700672 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case CMD_CLOSE_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800678 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 if (uiccCard == null) {
680 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900681 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 } else {
684 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
685 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
689 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800690 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
691 break;
692
693 case CMD_NV_READ_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800706 request.result = "";
707 if (ar.result == null) {
708 loge("nvReadItem: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("nvReadItem: CommandException: " +
711 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800713 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
Jake Hambye994d462014-02-03 13:10:13 -0800719 case CMD_NV_WRITE_ITEM:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
722 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700724 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
727 case EVENT_NV_WRITE_ITEM_DONE:
728 handleNullReturnEvent(msg, "nvWriteItem");
729 break;
730
731 case CMD_NV_WRITE_CDMA_PRL:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_WRITE_CDMA_PRL_DONE:
738 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
739 break;
740
chen xu6dac5ab2018-10-26 17:39:23 -0700741 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800742 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700743 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
chen xu6dac5ab2018-10-26 17:39:23 -0700747 case EVENT_RESET_MODEM_CONFIG_DONE:
748 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800749 break;
750
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 case CMD_GET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result; // Integer
762 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800763 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800764 if (ar.result == null) {
765 loge("getPreferredNetworkType: Empty response");
766 } else if (ar.exception instanceof CommandException) {
767 loge("getPreferredNetworkType: CommandException: " +
768 ar.exception);
769 } else {
770 loge("getPreferredNetworkType: Unknown exception");
771 }
772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800774 break;
775
776 case CMD_SET_PREFERRED_NETWORK_TYPE:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
779 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700780 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800781 break;
782
783 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
784 handleNullReturnEvent(msg, "setPreferredNetworkType");
785 break;
786
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
788 request = (MainThreadRequest)msg.obj;
789 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000791 break;
792
793 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
794 ar = (AsyncResult)msg.obj;
795 request = (MainThreadRequest)ar.userObj;
796 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000798 break;
799
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800 case CMD_SET_VOICEMAIL_NUMBER:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
803 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800804 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
805 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800806 break;
807
808 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
809 handleNullReturnEvent(msg, "setVoicemailNumber");
810 break;
811
Stuart Scott54788802015-03-30 13:18:01 -0700812 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
815 request);
816 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
821 break;
822
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 case CMD_PERFORM_NETWORK_SCAN:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
826 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
827 break;
828
Shuo Qian4a594052020-01-23 11:59:30 -0800829 case CMD_GET_CALL_FORWARDING:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
832 int callForwardingReason = (Integer) request.argument;
833 getPhoneFromRequest(request).getCallForwardingOption(
834 callForwardingReason, onCompleted);
835 break;
836
837 case EVENT_GET_CALL_FORWARDING_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 CallForwardingInfo callForwardingInfo = null;
841 if (ar.exception == null && ar.result != null) {
842 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
843 for (CallForwardInfo callForwardInfo : callForwardInfos) {
844 // Service Class is a bit mask per 3gpp 27.007. Search for
845 // any service for voice call.
846 if ((callForwardInfo.serviceClass
847 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
848 callForwardingInfo = new CallForwardingInfo(
849 callForwardInfo.serviceClass, callForwardInfo.reason,
850 callForwardInfo.number,
851 callForwardInfo.timeSeconds);
852 break;
853 }
854 }
855 // Didn't find a call forward info for voice call.
856 if (callForwardingInfo == null) {
857 callForwardingInfo = new CallForwardingInfo(
858 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
859 0 /* reason */, null /* number */, 0 /* timeout */);
860 }
861 } else {
862 if (ar.result == null) {
863 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
864 }
865 if (ar.exception != null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
867 }
868 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
869 if (ar.exception instanceof CommandException) {
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
873 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
874 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
876 }
877 }
878 callForwardingInfo = new CallForwardingInfo(
879 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
880 }
881 request.result = callForwardingInfo;
882 notifyRequester(request);
883 break;
884
885 case CMD_SET_CALL_FORWARDING:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
888 CallForwardingInfo callForwardingInfoToSet =
889 (CallForwardingInfo) request.argument;
890 getPhoneFromRequest(request).setCallForwardingOption(
891 callForwardingInfoToSet.getStatus(),
892 callForwardingInfoToSet.getReason(),
893 callForwardingInfoToSet.getNumber(),
894 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
895 break;
896
897 case EVENT_SET_CALL_FORWARDING_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null) {
901 request.result = true;
902 } else {
903 request.result = false;
904 loge("setCallForwarding exception: " + ar.exception);
905 }
906 notifyRequester(request);
907 break;
908
909 case CMD_GET_CALL_WAITING:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
912 getPhoneFromRequest(request).getCallWaiting(onCompleted);
913 break;
914
915 case EVENT_GET_CALL_WAITING_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
919 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800920 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800921 // Service Class is a bit mask per 3gpp 27.007.
922 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 if (callForwardResults.length > 1
924 && ((callForwardResults[1]
925 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
926 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800927 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
928 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
929 } else {
930 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
931 }
932 } else {
933 if (ar.result == null) {
934 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
935 }
936 if (ar.exception != null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
938 }
939 if (ar.exception instanceof CommandException) {
940 CommandException.Error error =
941 ((CommandException) (ar.exception)).getCommandError();
942 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
943 callForwardingStatus =
944 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
945 }
946 }
947 }
948 request.result = callForwardingStatus;
949 notifyRequester(request);
950 break;
951
952 case CMD_SET_CALL_WAITING:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
955 boolean isEnable = (Boolean) request.argument;
956 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
957 break;
958
959 case EVENT_SET_CALL_WAITING_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null) {
963 request.result = true;
964 } else {
965 request.result = false;
966 loge("setCallWaiting exception: " + ar.exception);
967 }
968 notifyRequester(request);
969 break;
970
Shishir Agrawal302c8692015-06-19 13:49:39 -0700971 case EVENT_PERFORM_NETWORK_SCAN_DONE:
972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
974 CellNetworkScanResult cellScanResult;
975 if (ar.exception == null && ar.result != null) {
976 cellScanResult = new CellNetworkScanResult(
977 CellNetworkScanResult.STATUS_SUCCESS,
978 (List<OperatorInfo>) ar.result);
979 } else {
980 if (ar.result == null) {
981 loge("getCellNetworkScanResults: Empty response");
982 }
983 if (ar.exception != null) {
984 loge("getCellNetworkScanResults: Exception: " + ar.exception);
985 }
986 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
991 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
992 } else if (error == CommandException.Error.GENERIC_FAILURE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
994 }
995 }
996 cellScanResult = new CellNetworkScanResult(errorCode, null);
997 }
998 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 break;
1001
1002 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1003 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001004 ManualNetworkSelectionArgument selArg =
1005 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001006 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1007 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001008 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1009 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001010 break;
1011
1012 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result = true;
1017 } else {
1018 request.result = false;
1019 loge("setNetworkSelectionModeManual " + ar.exception);
1020 }
1021 notifyRequester(request);
1022 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001023 break;
1024
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001025 case CMD_GET_MODEM_ACTIVITY_INFO:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001028 if (defaultPhone != null) {
1029 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1030 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001031 break;
1032
1033 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 if (ar.exception == null && ar.result != null) {
1037 request.result = ar.result;
1038 } else {
1039 if (ar.result == null) {
1040 loge("queryModemActivityInfo: Empty response");
1041 } else if (ar.exception instanceof CommandException) {
1042 loge("queryModemActivityInfo: CommandException: " +
1043 ar.exception);
1044 } else {
1045 loge("queryModemActivityInfo: Unknown exception");
1046 }
1047 }
Amit Mahajand4766222016-01-28 15:28:28 -08001048 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1049 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -08001050 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001053 break;
1054
Meng Wang1a7c35a2016-05-05 20:56:15 -07001055 case CMD_SET_ALLOWED_CARRIERS:
1056 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001057 CarrierRestrictionRules argument =
1058 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001059 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001060 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001061 break;
1062
1063 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result;
1068 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001069 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1070 if (ar.exception instanceof CommandException) {
1071 loge("setAllowedCarriers: CommandException: " + ar.exception);
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1075 request.result =
1076 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1077 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001078 } else {
1079 loge("setAllowedCarriers: Unknown exception");
1080 }
1081 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001082 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001083 break;
1084
1085 case CMD_GET_ALLOWED_CARRIERS:
1086 request = (MainThreadRequest) msg.obj;
1087 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001088 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001089 break;
1090
1091 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null && ar.result != null) {
1095 request.result = ar.result;
1096 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001097 request.result = new IllegalStateException(
1098 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001099 if (ar.result == null) {
1100 loge("getAllowedCarriers: Empty response");
1101 } else if (ar.exception instanceof CommandException) {
1102 loge("getAllowedCarriers: CommandException: " +
1103 ar.exception);
1104 } else {
1105 loge("getAllowedCarriers: Unknown exception");
1106 }
1107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001108 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001109 break;
1110
Nathan Haroldb3014052017-01-25 15:57:32 -08001111 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 if (ar.exception == null && ar.result != null) {
1115 request.result = ar.result;
1116 } else {
1117 request.result = new IllegalArgumentException(
1118 "Failed to retrieve Forbidden Plmns");
1119 if (ar.result == null) {
1120 loge("getForbiddenPlmns: Empty response");
1121 } else {
1122 loge("getForbiddenPlmns: Unknown exception");
1123 }
1124 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001125 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001126 break;
1127
1128 case CMD_GET_FORBIDDEN_PLMNS:
1129 request = (MainThreadRequest) msg.obj;
1130 uiccCard = getUiccCardFromRequest(request);
1131 if (uiccCard == null) {
1132 loge("getForbiddenPlmns() UiccCard is null");
1133 request.result = new IllegalArgumentException(
1134 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001136 break;
1137 }
1138 Integer appType = (Integer) request.argument;
1139 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1140 if (uiccApp == null) {
1141 loge("getForbiddenPlmns() no app with specified type -- "
1142 + appType);
1143 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001144 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001145 break;
1146 } else {
1147 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1148 + " specified type -- " + appType);
1149 }
1150 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1151 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1152 onCompleted);
1153 break;
1154
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001155 case CMD_SWITCH_SLOTS:
1156 request = (MainThreadRequest) msg.obj;
1157 int[] physicalSlots = (int[]) request.argument;
1158 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1159 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1160 break;
1161
1162 case EVENT_SWITCH_SLOTS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
1167 break;
1168 case CMD_GET_NETWORK_SELECTION_MODE:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1171 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1172 break;
1173
1174 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception != null) {
1178 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1179 } else {
1180 int mode = ((int[]) ar.result)[0];
1181 if (mode == 0) {
1182 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1183 } else {
1184 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1185 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001186 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001187 notifyRequester(request);
1188 break;
1189 case CMD_GET_CDMA_ROAMING_MODE:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1192 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1193 break;
1194 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 if (ar.exception != null) {
1198 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1199 } else {
1200 request.result = ((int[]) ar.result)[0];
1201 }
1202 notifyRequester(request);
1203 break;
1204 case CMD_SET_CDMA_ROAMING_MODE:
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1207 int mode = (int) request.argument;
1208 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1209 break;
1210 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
1213 request.result = ar.exception == null;
1214 notifyRequester(request);
1215 break;
1216 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1219 int subscriptionMode = (int) request.argument;
1220 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1221 break;
1222 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
1225 request.result = ar.exception == null;
1226 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001227 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001228 case CMD_GET_ALL_CELL_INFO:
1229 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001230 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001231 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001232 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001233 case EVENT_GET_ALL_CELL_INFO_DONE:
1234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001236 // If a timeout occurs, the response will be null
1237 request.result = (ar.exception == null && ar.result != null)
1238 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 case CMD_REQUEST_CELL_INFO_UPDATE:
1244 request = (MainThreadRequest) msg.obj;
1245 request.phone.requestCellInfoUpdate(request.workSource,
1246 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1247 break;
1248 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
1251 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1252 try {
1253 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001254 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001255 cb.onError(
1256 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1257 ar.exception.getClass().getName(),
1258 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001259 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001260 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001261 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001262 } else {
1263 // use the result as returned
1264 cb.onCellInfo((List<CellInfo>) ar.result);
1265 }
1266 } catch (RemoteException re) {
1267 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1268 }
1269 break;
1270 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 request = (MainThreadRequest) msg.obj;
1272 WorkSource ws = (WorkSource) request.argument;
1273 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001274 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = ar.result;
1281 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001282 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001283 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001284 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001285 }
1286
1287 synchronized (request) {
1288 request.notifyAll();
1289 }
1290 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001291 case CMD_MODEM_REBOOT:
1292 request = (MainThreadRequest) msg.obj;
1293 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001294 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001295 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001296 case EVENT_CMD_MODEM_REBOOT_DONE:
1297 handleNullReturnEvent(msg, "rebootModem");
1298 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001299 case CMD_REQUEST_ENABLE_MODEM:
1300 request = (MainThreadRequest) msg.obj;
1301 boolean enable = (boolean) request.argument;
1302 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001303 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001304 PhoneConfigurationManager.getInstance()
1305 .enablePhone(request.phone, enable, onCompleted);
1306 break;
1307 case EVENT_ENABLE_MODEM_DONE:
1308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001311 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001312 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001313 if ((boolean) request.result) {
1314 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1315 updateModemStateMetrics();
1316 } else {
1317 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1318 + ar.exception);
1319 }
1320 notifyRequester(request);
1321 break;
1322 case CMD_GET_MODEM_STATUS:
1323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1325 PhoneConfigurationManager.getInstance()
1326 .getPhoneStatusFromModem(request.phone, onCompleted);
1327 break;
1328 case EVENT_GET_MODEM_STATUS_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 int id = request.phone.getPhoneId();
1332 if (ar.exception == null && ar.result != null) {
1333 request.result = ar.result;
1334 //update the cache as modem status has changed
1335 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1336 (boolean) request.result);
1337 } else {
1338 // Return true if modem status cannot be retrieved. For most cases,
1339 // modem status is on. And for older version modems, GET_MODEM_STATUS
1340 // and disable modem are not supported. Modem is always on.
1341 // TODO: this should be fixed in R to support a third
1342 // status UNKNOWN b/131631629
1343 request.result = true;
1344 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1345 + ar.exception);
1346 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001347 notifyRequester(request);
1348 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001349 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1350 request = (MainThreadRequest) msg.obj;
1351 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1352 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1353 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1354 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1355 break;
1356 }
1357 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1361 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1362 args.second.accept(ar.exception == null);
1363 notifyRequester(request);
1364 break;
1365 }
yincheng zhao2737e882019-09-06 17:06:54 -07001366 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 if (ar.exception == null && ar.result != null) {
1370 request.result = ar.result;
1371 } else {
1372 request.result = -1;
1373 loge("Failed to set Forbidden Plmns");
1374 if (ar.result == null) {
1375 loge("setForbidenPlmns: Empty response");
1376 } else if (ar.exception != null) {
1377 loge("setForbiddenPlmns: Exception: " + ar.exception);
1378 request.result = -1;
1379 } else {
1380 loge("setForbiddenPlmns: Unknown exception");
1381 }
1382 }
1383 notifyRequester(request);
1384 break;
1385 case CMD_SET_FORBIDDEN_PLMNS:
1386 request = (MainThreadRequest) msg.obj;
1387 uiccCard = getUiccCardFromRequest(request);
1388 if (uiccCard == null) {
1389 loge("setForbiddenPlmns: UiccCard is null");
1390 request.result = -1;
1391 notifyRequester(request);
1392 break;
1393 }
1394 Pair<Integer, List<String>> setFplmnsArgs =
1395 (Pair<Integer, List<String>>) request.argument;
1396 appType = setFplmnsArgs.first;
1397 List<String> fplmns = setFplmnsArgs.second;
1398 uiccApp = uiccCard.getApplicationByType(appType);
1399 if (uiccApp == null) {
1400 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1401 request.result = -1;
1402 loge("Failed to get UICC App");
1403 notifyRequester(request);
1404 } else {
1405 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1406 ((SIMRecords) uiccApp.getIccRecords())
1407 .setForbiddenPlmns(onCompleted, fplmns);
1408 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001409 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001410 case CMD_ERASE_MODEM_CONFIG:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1413 defaultPhone.eraseModemConfig(onCompleted);
1414 break;
1415 case EVENT_ERASE_MODEM_CONFIG_DONE:
1416 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001417 break;
zoey chene02881a2019-12-30 16:11:23 +08001418
1419 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1422 Pair<String, String> changed = (Pair<String, String>) request.argument;
1423 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1424 changed.first, changed.second, onCompleted);
1425 break;
1426 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception == null) {
1430 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1431 } else {
1432 request.result = msg.arg1;
1433 }
1434 notifyRequester(request);
1435 break;
1436
1437 case CMD_SET_ICC_LOCK_ENABLED:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1440 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1441 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1442 enabled.first, enabled.second, onCompleted);
1443 break;
1444 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 if (ar.exception == null) {
1448 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1449 } else {
1450 request.result = msg.arg1;
1451 }
1452 notifyRequester(request);
1453 break;
1454
Peter Wangdafb9ac2020-01-15 14:13:38 -08001455 case MSG_NOTIFY_USER_ACTIVITY:
1456 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001457 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001458 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1459 getDefaultPhone().getContext().sendBroadcastAsUser(
1460 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1461 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 default:
1463 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1464 break;
1465 }
1466 }
Jake Hambye994d462014-02-03 13:10:13 -08001467
Pengquan Menga1bb6272018-09-06 09:59:22 -07001468 private void notifyRequester(MainThreadRequest request) {
1469 synchronized (request) {
1470 request.notifyAll();
1471 }
1472 }
1473
Jake Hambye994d462014-02-03 13:10:13 -08001474 private void handleNullReturnEvent(Message msg, String command) {
1475 AsyncResult ar = (AsyncResult) msg.obj;
1476 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1477 if (ar.exception == null) {
1478 request.result = true;
1479 } else {
1480 request.result = false;
1481 if (ar.exception instanceof CommandException) {
1482 loge(command + ": CommandException: " + ar.exception);
1483 } else {
1484 loge(command + ": Unknown exception");
1485 }
1486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
1491 /**
1492 * Posts the specified command to be executed on the main thread,
1493 * waits for the request to complete, and returns the result.
1494 * @see #sendRequestAsync
1495 */
1496 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001497 return sendRequest(
1498 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001499 }
1500
1501 /**
1502 * Posts the specified command to be executed on the main thread,
1503 * waits for the request to complete, and returns the result.
1504 * @see #sendRequestAsync
1505 */
1506 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1507 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001508 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
1511 /**
1512 * Posts the specified command to be executed on the main thread,
1513 * waits for the request to complete, and returns the result.
1514 * @see #sendRequestAsync
1515 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001516 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001517 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001518 }
1519
1520 /**
1521 * Posts the specified command to be executed on the main thread,
1522 * waits for the request to complete, and returns the result.
1523 * @see #sendRequestAsync
1524 */
Nathan Harold92bed182018-10-12 18:16:49 -07001525 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1526 return sendRequest(command, argument, subId, null, workSource);
1527 }
1528
1529 /**
1530 * Posts the specified command to be executed on the main thread,
1531 * waits for the request to complete, and returns the result.
1532 * @see #sendRequestAsync
1533 */
1534 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1535 return sendRequest(
1536 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1537 }
1538
1539 /**
1540 * Posts the specified command to be executed on the main thread,
1541 * waits for the request to complete, and returns the result.
1542 * @see #sendRequestAsync
1543 */
1544 private Object sendRequest(
1545 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1547 throw new RuntimeException("This method will deadlock if called from the main thread.");
1548 }
1549
Nathan Harold92bed182018-10-12 18:16:49 -07001550 MainThreadRequest request = null;
1551 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1552 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1553 } else if (phone != null) {
1554 request = new MainThreadRequest(argument, phone, workSource);
1555 } else {
1556 request = new MainThreadRequest(argument, subId, workSource);
1557 }
1558
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 Message msg = mMainThreadHandler.obtainMessage(command, request);
1560 msg.sendToTarget();
1561
1562 // Wait for the request to complete
1563 synchronized (request) {
1564 while (request.result == null) {
1565 try {
1566 request.wait();
1567 } catch (InterruptedException e) {
1568 // Do nothing, go back and wait until the request is complete
1569 }
1570 }
1571 }
1572 return request.result;
1573 }
1574
1575 /**
1576 * Asynchronous ("fire and forget") version of sendRequest():
1577 * Posts the specified command to be executed on the main thread, and
1578 * returns immediately.
1579 * @see #sendRequest
1580 */
1581 private void sendRequestAsync(int command) {
1582 mMainThreadHandler.sendEmptyMessage(command);
1583 }
1584
1585 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001586 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001587 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001588 */
1589 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001590 sendRequestAsync(command, argument, null, null);
1591 }
1592
1593 /**
1594 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1595 * @see {@link #sendRequest(int,Object)}
1596 */
1597 private void sendRequestAsync(
1598 int command, Object argument, Phone phone, WorkSource workSource) {
1599 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001600 Message msg = mMainThreadHandler.obtainMessage(command, request);
1601 msg.sendToTarget();
1602 }
1603
1604 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 * Initialize the singleton PhoneInterfaceManager instance.
1606 * This is only done once, at startup, from PhoneApp.onCreate().
1607 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001608 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 synchronized (PhoneInterfaceManager.class) {
1610 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001611 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 } else {
1613 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1614 }
1615 return sInstance;
1616 }
1617 }
1618
1619 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001620 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001623 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001624 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1626 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001627 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001628 mTelephonySharedPreferences =
1629 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001630 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001631 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001632 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001633
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 publish();
1635 }
1636
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001637 private Phone getDefaultPhone() {
1638 Phone thePhone = getPhone(getDefaultSubscription());
1639 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 private void publish() {
1643 if (DBG) log("publish: " + this);
1644
Peter Wangc035ce42020-01-08 21:00:22 -08001645 TelephonyFrameworkInitializer
1646 .getTelephonyServiceManager()
1647 .getTelephonyServiceRegisterer()
1648 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650
Stuart Scott584921c2015-01-15 17:10:34 -08001651 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001652 if (request.phone != null) {
1653 return request.phone;
1654 } else {
1655 return getPhoneFromSubId(request.subId);
1656 }
1657 }
1658
1659 private Phone getPhoneFromSubId(int subId) {
1660 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1661 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001662 }
1663
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001664 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1665 Phone phone = getPhoneFromRequest(request);
1666 return phone == null ? null :
1667 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1668 }
1669
Wink Saville36469e72014-06-11 15:17:00 -07001670 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001671 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001672 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674
Naina Nallurid63128d2019-09-17 14:10:30 -07001675 private void sendEraseModemConfig(Phone phone) {
1676 if (phone != null) {
1677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1678 mApp, phone.getSubId(), "eraseModemConfig");
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1682 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
1685 }
1686 }
1687 }
1688
Peter Wang44b186e2020-01-13 23:33:09 -08001689 private boolean isImsAvailableOnDevice() {
1690 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1691 if (pm == null) {
1692 // For some reason package manger is not available.. This will fail internally anyway,
1693 // so do not throw error and allow.
1694 return true;
1695 }
1696 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1697 }
1698
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001700 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001701 }
1702
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 if (DBG) log("dial: " + number);
1705 // No permission check needed here: This is just a wrapper around the
1706 // ACTION_DIAL intent, which is available to any app since it puts up
1707 // the UI before it does anything.
1708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 String url = createTelUrl(number);
1712 if (url == null) {
1713 return;
1714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 // PENDING: should we just silently fail if phone is offhook or ringing?
1717 PhoneConstants.State state = mCM.getState(subId);
1718 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1719 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1720 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1721 mApp.startActivity(intent);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726 }
1727
1728 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Wink Savilleb564aae2014-10-23 10:18:09 -07001732 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 if (DBG) log("call: " + number);
1734
1735 // This is just a wrapper around the ACTION_CALL intent, but we still
1736 // need to do a permission check since we're calling startActivity()
1737 // from the context of the phone app.
1738 enforceCallPermission();
1739
Jordan Liu1617b712019-07-10 15:06:26 -07001740 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 != AppOpsManager.MODE_ALLOWED) {
1742 return;
1743 }
1744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 String url = createTelUrl(number);
1748 if (url == null) {
1749 return;
1750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 boolean isValid = false;
1753 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1754 if (slist != null) {
1755 for (SubscriptionInfo subInfoRecord : slist) {
1756 if (subInfoRecord.getSubscriptionId() == subId) {
1757 isValid = true;
1758 break;
1759 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001760 }
Wink Saville08874612014-08-31 19:19:58 -07001761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 if (!isValid) {
1763 return;
1764 }
Wink Saville08874612014-08-31 19:19:58 -07001765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1767 intent.putExtra(SUBSCRIPTION_KEY, subId);
1768 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1769 mApp.startActivity(intent);
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
1772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Wink Savilleb564aae2014-10-23 10:18:09 -07001775 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001776 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001777 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1778 }
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001781 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001782 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1783 }
1784
Wink Savilleb564aae2014-10-23 10:18:09 -07001785 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1791 checkSimPin.start();
1792 return checkSimPin.unlockSim(null, pin);
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
1795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 }
1797
Wink Savilleb564aae2014-10-23 10:18:09 -07001798 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1804 checkSimPuk.start();
1805 return checkSimPuk.unlockSim(puk, pin);
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
1811 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001812 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 * a synchronous one.
1814 */
1815 private static class UnlockSim extends Thread {
1816
1817 private final IccCard mSimCard;
1818
1819 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001820 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1821 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822
1823 // For replies from SimCard interface
1824 private Handler mHandler;
1825
1826 // For async handler to identify request type
1827 private static final int SUPPLY_PIN_COMPLETE = 100;
1828
1829 public UnlockSim(IccCard simCard) {
1830 mSimCard = simCard;
1831 }
1832
1833 @Override
1834 public void run() {
1835 Looper.prepare();
1836 synchronized (UnlockSim.this) {
1837 mHandler = new Handler() {
1838 @Override
1839 public void handleMessage(Message msg) {
1840 AsyncResult ar = (AsyncResult) msg.obj;
1841 switch (msg.what) {
1842 case SUPPLY_PIN_COMPLETE:
1843 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1844 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001845 mRetryCount = msg.arg1;
1846 if (ar.exception != null) {
1847 if (ar.exception instanceof CommandException &&
1848 ((CommandException)(ar.exception)).getCommandError()
1849 == CommandException.Error.PASSWORD_INCORRECT) {
1850 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1851 } else {
1852 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1853 }
1854 } else {
1855 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 mDone = true;
1858 UnlockSim.this.notifyAll();
1859 }
1860 break;
1861 }
1862 }
1863 };
1864 UnlockSim.this.notifyAll();
1865 }
1866 Looper.loop();
1867 }
1868
1869 /*
1870 * Use PIN or PUK to unlock SIM card
1871 *
1872 * If PUK is null, unlock SIM card with PIN
1873 *
1874 * If PUK is not null, unlock SIM card with PUK and set PIN code
1875 */
Wink Saville9de0f752013-10-22 19:04:03 -07001876 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877
1878 while (mHandler == null) {
1879 try {
1880 wait();
1881 } catch (InterruptedException e) {
1882 Thread.currentThread().interrupt();
1883 }
1884 }
1885 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1886
1887 if (puk == null) {
1888 mSimCard.supplyPin(pin, callback);
1889 } else {
1890 mSimCard.supplyPuk(puk, pin, callback);
1891 }
1892
1893 while (!mDone) {
1894 try {
1895 Log.d(LOG_TAG, "wait for done");
1896 wait();
1897 } catch (InterruptedException e) {
1898 // Restore the interrupted status
1899 Thread.currentThread().interrupt();
1900 }
1901 }
1902 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001903 int[] resultArray = new int[2];
1904 resultArray[0] = mResult;
1905 resultArray[1] = mRetryCount;
1906 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908 }
1909
1910 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001912
1913 }
1914
Wink Savilleb564aae2014-10-23 10:18:09 -07001915 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 // No permission check needed here: this call is harmless, and it's
1917 // needed for the ServiceState.requestStateUpdate() call (which is
1918 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001919 final long identity = Binder.clearCallingIdentity();
1920 try {
1921 final Phone phone = getPhone(subId);
1922 if (phone != null) {
1923 phone.updateServiceLocation();
1924 }
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 }
1929
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001930 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 @Override
1932 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001933 return isRadioOnWithFeature(callingPackage, null);
1934 }
1935
1936
1937 @Override
1938 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1939 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1940 callingFeatureId);
1941 }
1942
1943 @Deprecated
1944 @Override
1945 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1946 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001947 }
1948
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001950 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1951 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001953 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 return false;
1955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956
1957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 return isRadioOnForSubscriber(subId);
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
1962 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 }
1964
1965 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 final Phone phone = getPhone(subId);
1969 if (phone != null) {
1970 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1971 } else {
1972 return false;
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001980 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
Wink Saville36469e72014-06-11 15:17:00 -07001982
Wink Savilleb564aae2014-10-23 10:18:09 -07001983 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985
1986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
1990 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1991 }
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 }
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
1997 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001998 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Wink Savilleb564aae2014-10-23 10:18:09 -07002001 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 final Phone phone = getPhone(subId);
2007 if (phone == null) {
2008 return false;
2009 }
2010 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2011 toggleRadioOnOffForSubscriber(subId);
2012 }
2013 return true;
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
Wink Saville36469e72014-06-11 15:17:00 -07002018
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002019 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002020 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002021 /*
2022 * If any of the Radios are available, it will need to be
2023 * shutdown. So return true if any Radio is available.
2024 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2028 Phone phone = PhoneFactory.getPhone(i);
2029 if (phone != null && phone.isRadioAvailable()) return true;
2030 }
2031 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2032 return false;
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002035 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002036 }
2037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002039 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 enforceModifyPermission();
2041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2045 logv("Shutting down Phone " + i);
2046 shutdownRadioUsingPhoneId(i);
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002050 }
2051 }
2052
2053 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002054 Phone phone = PhoneFactory.getPhone(phoneId);
2055 if (phone != null && phone.isRadioAvailable()) {
2056 phone.shutdownRadio();
2057 }
2058 }
2059
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2066 if (defaultPhone != null) {
2067 defaultPhone.setRadioPower(turnOn);
2068 return true;
2069 } else {
2070 loge("There's no default phone.");
2071 return false;
2072 }
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002075 }
Wink Saville36469e72014-06-11 15:17:00 -07002076 }
2077
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
2085 phone.setRadioPower(turnOn);
2086 return true;
2087 } else {
2088 return false;
2089 }
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
Wink Saville36469e72014-06-11 15:17:00 -07002095 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 public boolean enableDataConnectivity() {
2098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 int subId = mSubscriptionController.getDefaultDataSubId();
2103 final Phone phone = getPhone(subId);
2104 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002105 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 return true;
2107 } else {
2108 return false;
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
Wink Saville36469e72014-06-11 15:17:00 -07002115 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002116 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 public boolean disableDataConnectivity() {
2118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119
2120 final long identity = Binder.clearCallingIdentity();
2121 try {
2122 int subId = mSubscriptionController.getDefaultDataSubId();
2123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002125 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126 return true;
2127 } else {
2128 return false;
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002136 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002141 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142 } else {
2143 return false;
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
2149
2150 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002151 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
2153
pkanwarae03a6b2016-11-06 20:37:09 -08002154 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155 enforceCallPermission();
2156
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2160 return;
2161 }
2162 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2163 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
2166 }
pkanwar32d516d2016-10-14 19:37:38 -07002167 };
2168
Wink Savilleb564aae2014-10-23 10:18:09 -07002169 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2175 return false;
2176 }
2177 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002184 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
2190 Phone phone = PhoneFactory.getPhone(slotIndex);
2191 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2192 PhoneConstantConversions.convertCallState(phone.getState());
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
2195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002199 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002200 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2201 }
2202
2203 @Override
2204 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002207 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 if (phone != null) {
2209 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2210 } else {
2211 return PhoneConstantConversions.convertDataState(
2212 PhoneConstants.DataState.DISCONNECTED);
2213 }
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002220 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002221 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2222 }
2223
2224 @Override
2225 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002228 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 if (phone != null) {
2230 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2231 } else {
2232 return TelephonyManager.DATA_ACTIVITY_NONE;
2233 }
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238
2239 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002240 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002242 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002243
2244 LocationAccessPolicy.LocationPermissionResult locationResult =
2245 LocationAccessPolicy.checkLocationPermission(mApp,
2246 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2247 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002249 .setCallingPid(Binder.getCallingPid())
2250 .setCallingUid(Binder.getCallingUid())
2251 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002252 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002253 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2254 .build());
2255 switch (locationResult) {
2256 case DENIED_HARD:
2257 throw new SecurityException("Not allowed to access cell location");
2258 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002259 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2260 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002267 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002268 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Svetoslav64fad262015-04-14 14:35:21 -07002272 }
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002275 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002276 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2277 // registered cell info, so return a NULL country instead.
2278 final long identity = Binder.clearCallingIdentity();
2279 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002280 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2281 // Get default phone in this case.
2282 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2283 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002284 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002285 // Todo: fix this when we can get the actual cellular network info when the device
2286 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002287 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002288 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2289 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002290 return "";
2291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 Phone phone = PhoneFactory.getPhone(phoneId);
2293 if (phone != null) {
2294 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002295 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 if (sst != null) {
2297 LocaleTracker lt = sst.getLocaleTracker();
2298 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002299 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2300 return lt.getCurrentCountry();
2301 } else if (emergencyNumberTracker != null) {
2302 return emergencyNumberTracker.getEmergencyCountryIso();
2303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304 }
2305 }
2306 }
2307 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002308 } finally {
2309 Binder.restoreCallingIdentity(identity);
2310 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002311 }
2312
2313 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 mApp.enforceCallingOrSelfPermission(
2321 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 final Phone phone = getPhone(subId);
2326 if (phone != null) {
2327 phone.enableLocationUpdates();
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 @Override
2335 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002336 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002337 }
2338
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mApp.enforceCallingOrSelfPermission(
2342 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 final Phone phone = getPhone(subId);
2347 if (phone != null) {
2348 phone.disableLocationUpdates();
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Nathan Harold31d7ff32018-10-15 20:20:30 -07002355 /**
2356 * Returns the target SDK version number for a given package name.
2357 *
Nathan Haroldec184742019-07-10 17:04:16 -07002358 * This call MUST be invoked before clearing the calling UID.
2359 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002360 * @return target SDK if the package is found or INT_MAX.
2361 */
2362 private int getTargetSdk(String packageName) {
2363 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002364 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002365 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002366 if (ai != null) return ai.targetSdkVersion;
2367 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002368 loge("Failed to get package info for pkg="
2369 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002370 }
2371 return Integer.MAX_VALUE;
2372 }
2373
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 @Override
2375 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002376 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2377 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002378 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2380 throw new SecurityException(
2381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002383
Jordan Liu1617b712019-07-10 15:06:26 -07002384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2386 return null;
2387 }
Svetoslav64fad262015-04-14 14:35:21 -07002388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393
Nathan Haroldf180aac2018-06-01 18:43:55 -07002394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2395 for (CellInfo ci : info) {
2396 if (ci instanceof CellInfoGsm) {
2397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2398 } else if (ci instanceof CellInfoWcdma) {
2399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002405 private List<CellInfo> getCachedCellInfo() {
2406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2407 for (Phone phone : PhoneFactory.getPhones()) {
2408 List<CellInfo> info = phone.getAllCellInfo();
2409 if (info != null) cellInfos.addAll(info);
2410 }
2411 return cellInfos;
2412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413
2414 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002418
2419 LocationAccessPolicy.LocationPermissionResult locationResult =
2420 LocationAccessPolicy.checkLocationPermission(mApp,
2421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2422 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002424 .setCallingPid(Binder.getCallingPid())
2425 .setCallingUid(Binder.getCallingUid())
2426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2429 .build());
2430 switch (locationResult) {
2431 case DENIED_HARD:
2432 throw new SecurityException("Not allowed to access cell info");
2433 case DENIED_SOFT:
2434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 final int targetSdk = getTargetSdk(callingPackage);
2438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2439 return getCachedCellInfo();
2440 }
2441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 if (info != null) cellInfos.addAll(info);
2451 }
2452 return cellInfos;
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 }
2456 }
2457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2460 String callingFeatureId) {
2461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002463 }
2464
2465 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002468 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002470 }
2471
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002476
2477 LocationAccessPolicy.LocationPermissionResult locationResult =
2478 LocationAccessPolicy.checkLocationPermission(mApp,
2479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2480 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002482 .setCallingPid(Binder.getCallingPid())
2483 .setCallingUid(Binder.getCallingUid())
2484 .setMethod("requestCellInfoUpdate")
2485 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2486 .build());
2487 switch (locationResult) {
2488 case DENIED_HARD:
2489 throw new SecurityException("Not allowed to access cell info");
2490 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002491 try {
2492 cb.onCellInfo(new ArrayList<CellInfo>());
2493 } catch (RemoteException re) {
2494 // Drop without consequences
2495 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002496 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 }
2498
Nathan Harolda939a962019-05-09 10:13:47 -07002499
2500 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002501 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2502
2503 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2504 }
2505
2506 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002508 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002513 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Shishir Agrawala9f32182016-04-12 12:00:16 -07002519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002520 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 Phone phone = PhoneFactory.getPhone(slotIndex);
2522 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002523 return null;
2524 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002526 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002527 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 return null;
2529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return phone.getImei();
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002537 }
2538
2539 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002540 public String getTypeAllocationCodeForSlot(int slotIndex) {
2541 Phone phone = PhoneFactory.getPhone(slotIndex);
2542 String tac = null;
2543 if (phone != null) {
2544 String imei = phone.getImei();
2545 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2546 }
2547 return tac;
2548 }
2549
2550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002551 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002552 Phone phone = PhoneFactory.getPhone(slotIndex);
2553 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002554 return null;
2555 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556
Jeff Davidson913390f2018-02-23 17:11:49 -08002557 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002558 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002559 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 return null;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 return phone.getMeid();
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Jack Yu2af8d712017-03-15 17:14:14 -07002569 }
2570
2571 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002572 public String getManufacturerCodeForSlot(int slotIndex) {
2573 Phone phone = PhoneFactory.getPhone(slotIndex);
2574 String manufacturerCode = null;
2575 if (phone != null) {
2576 String meid = phone.getMeid();
2577 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2578 }
2579 return manufacturerCode;
2580 }
2581
2582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002583 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2584 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 Phone phone = PhoneFactory.getPhone(slotIndex);
2586 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002587 return null;
2588 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 int subId = phone.getSubId();
2590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002591 mApp, subId, callingPackage, callingFeatureId,
2592 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002593 return null;
2594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 return phone.getDeviceSvn();
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002602 }
2603
fionaxu43304da2017-11-27 22:51:16 -08002604 @Override
2605 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
fionaxu43304da2017-11-27 22:51:16 -08002613 }
2614
2615 @Override
2616 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 final Phone phone = getPhone(subId);
2620 return phone == null ? null : phone.getCarrierName();
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
fionaxu43304da2017-11-27 22:51:16 -08002624 }
2625
calvinpanffe225e2018-11-01 19:43:06 +08002626 @Override
chen xu0026ca62019-03-06 15:28:50 -08002627 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 final Phone phone = getPhone(subId);
2631 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002632 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
2636 }
2637
2638 @Override
chen xu0026ca62019-03-06 15:28:50 -08002639 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002643 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
2647 }
2648
chen xu651eec72018-11-11 19:03:44 -08002649 @Override
chen xu864e11c2018-12-06 22:10:03 -08002650 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2651 if (!isSubscriptionMccMnc) {
2652 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2653 }
chen xu651eec72018-11-11 19:03:44 -08002654 final Phone phone = PhoneFactory.getPhone(slotIndex);
2655 if (phone == null) {
2656 return TelephonyManager.UNKNOWN_CARRIER_ID;
2657 }
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
2664 }
2665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 //
2667 // Internal helper methods.
2668 //
2669
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002670 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2672 *
2673 * @throws SecurityException if the caller does not have the required permission
2674 */
2675 private void enforceModifyPermission() {
2676 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2677 }
2678
Shuo Qiancd19c462020-01-16 20:51:11 -08002679 /**
2680 * Make sure the caller is system.
2681 *
2682 * @throws SecurityException if the caller is not system.
2683 */
2684 private void enforceSystemCaller() {
2685 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2686 throw new SecurityException("Caller must be system");
2687 }
2688 }
2689
Shuo Qian3b6ee772019-11-13 17:43:31 -08002690 private void enforceActiveEmergencySessionPermission() {
2691 mApp.enforceCallingOrSelfPermission(
2692 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2693 }
2694
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 /**
2696 * Make sure the caller has the CALL_PHONE permission.
2697 *
2698 * @throws SecurityException if the caller does not have the required permission
2699 */
2700 private void enforceCallPermission() {
2701 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2702 }
2703
paulhu5a773602019-08-23 19:17:33 +08002704 private void enforceSettingsPermission() {
2705 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002706 }
2707
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 private String createTelUrl(String number) {
2709 if (TextUtils.isEmpty(number)) {
2710 return null;
2711 }
2712
Jake Hambye994d462014-02-03 13:10:13 -08002713 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Ihab Awadf9e92732013-12-05 18:02:52 -08002716 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2718 }
2719
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 private static void logv(String msg) {
2721 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2722 }
2723
Ihab Awadf9e92732013-12-05 18:02:52 -08002724 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2726 }
2727
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002730 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002734 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 final Phone phone = PhoneFactory.getPhone(slotIndex);
2738 if (phone == null) {
2739 return PhoneConstants.PHONE_TYPE_NONE;
2740 } else {
2741 return phone.getPhoneType();
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
2748 /**
2749 * Returns the CDMA ERI icon index to display
2750 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002752 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2753 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2754 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002755 }
2756
Sanket Padawe356d7632015-06-22 14:03:32 -07002757 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002758 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2759 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002761 mApp, subId, callingPackage, callingFeatureId,
2762 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002763 return -1;
2764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone != null) {
2770 return phone.getCdmaEriIconIndex();
2771 } else {
2772 return -1;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
2780 * Returns the CDMA ERI icon mode,
2781 * 0 - ON
2782 * 1 - FLASHING
2783 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002785 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2786 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2787 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002788 }
2789
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002791 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002794 mApp, subId, callingPackage, callingFeatureId,
2795 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002796 return -1;
2797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 return phone.getCdmaEriIconMode();
2804 } else {
2805 return -1;
2806 }
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811
2812 /**
2813 * Returns the CDMA ERI text,
2814 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002815 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002816 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2817 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2818 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002822 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2823 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 mApp, subId, callingPackage, callingFeatureId,
2826 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002827 return null;
2828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = getPhone(subId);
2833 if (phone != null) {
2834 return phone.getCdmaEriText();
2835 } else {
2836 return null;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
2843 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002844 * Returns the CDMA MDN.
2845 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002847 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2849 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002854 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 return phone.getLine1Number();
2856 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 return null;
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002862 }
2863 }
2864
2865 /**
2866 * Returns the CDMA MIN.
2867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002869 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2871 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 final Phone phone = getPhone(subId);
2876 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2877 return phone.getCdmaMin();
2878 } else {
2879 return null;
2880 }
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002883 }
2884 }
2885
Hall Liud892bec2018-11-30 14:51:45 -08002886 @Override
2887 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2888 INumberVerificationCallback callback, String callingPackage) {
2889 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2890 != PERMISSION_GRANTED) {
2891 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2892 }
2893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2894
2895 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2896 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2897 throw new SecurityException("Calling package must be configured in the device config");
2898 }
2899
2900 if (range == null) {
2901 throw new NullPointerException("Range must be non-null");
2902 }
2903
2904 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002905 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002906
2907 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2908 }
2909
Junda Liuca05d5d2014-08-14 22:36:34 -07002910 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 * Returns true if CDMA provisioning needs to run.
2912 */
2913 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 final long identity = Binder.clearCallingIdentity();
2915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002916 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
2922 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002923 * Sets the voice mail number of a given subId.
2924 */
2925 @Override
2926 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2928 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2933 new Pair<String, String>(alphaTag, number), new Integer(subId));
2934 return success;
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002938 }
2939
Ta-wei Yen87c49842016-05-13 21:19:52 -07002940 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002941 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002943 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2944 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002945 if (!TextUtils.equals(callingPackage, systemDialer)) {
2946 throw new SecurityException("caller must be system dialer");
2947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2952 if (phoneAccountHandle == null) {
2953 return null;
2954 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002958 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002959 }
2960
2961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002962 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2963 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002966 mApp, subId, callingPackage, callingFeatureId,
2967 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002968 return null;
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002971 final long identity = Binder.clearCallingIdentity();
2972 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 }
2978
2979 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002980 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2981 VisualVoicemailSmsFilterSettings settings) {
2982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002991 }
2992
2993 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002994 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003004 }
3005
3006 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003007 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3008 String callingPackage, int subId) {
3009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003018 }
3019
3020 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003021 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003031 }
3032
3033 @Override
3034 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3035 String number, int port, String text, PendingIntent sentIntent) {
3036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003037 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003038 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003039 SmsController smsController = PhoneFactory.getSmsController();
3040 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3041 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003042 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003043
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003044 /**
fionaxu0152e512016-11-14 13:36:14 -08003045 * Sets the voice activation state of a given subId.
3046 */
3047 @Override
3048 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3050 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 final Phone phone = getPhone(subId);
3055 if (phone != null) {
3056 phone.setVoiceActivationState(activationState);
3057 } else {
3058 loge("setVoiceActivationState fails with invalid subId: " + subId);
3059 }
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003062 }
3063 }
3064
3065 /**
3066 * Sets the data activation state of a given subId.
3067 */
3068 @Override
3069 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3071 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 final Phone phone = getPhone(subId);
3076 if (phone != null) {
3077 phone.setDataActivationState(activationState);
3078 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003079 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 }
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003083 }
3084 }
3085
3086 /**
3087 * Returns the voice activation state of a given subId.
3088 */
3089 @Override
3090 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
fionaxu0152e512016-11-14 13:36:14 -08003093 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 if (phone != null) {
3097 return phone.getVoiceActivationState();
3098 } else {
3099 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003103 }
3104 }
3105
3106 /**
3107 * Returns the data activation state of a given subId.
3108 */
3109 @Override
3110 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
fionaxu0152e512016-11-14 13:36:14 -08003113 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 if (phone != null) {
3117 return phone.getDataActivationState();
3118 } else {
3119 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3120 }
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003123 }
3124 }
3125
3126 /**
Wink Saville36469e72014-06-11 15:17:00 -07003127 * Returns the unread count of voicemails for a subId
3128 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003130 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3131 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003133 mApp, subId, callingPackage, callingFeatureId,
3134 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003135 return 0;
3136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 final Phone phone = getPhone(subId);
3140 if (phone != null) {
3141 return phone.getVoiceMessageCount();
3142 } else {
3143 return 0;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
3150 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003151 * returns true, if the device is in a state where both voice and data
3152 * are supported simultaneously. This can change based on location or network condition.
3153 */
3154 @Override
3155 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 final Phone phone = getPhone(subId);
3159 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003163 }
3164
3165 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003166 * Send the dialer code if called from the current default dialer or the caller has
3167 * carrier privilege.
3168 * @param inputCode The dialer code to send
3169 */
3170 @Override
3171 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003172 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003173 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003174 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3175 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003176 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003178 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
fionaxu235cc5e2017-03-06 22:25:57 -08003187 }
3188
Pengquan Menga1bb6272018-09-06 09:59:22 -07003189 @Override
3190 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003191 TelephonyPermissions
3192 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3193 mApp, subId, "getNetworkSelectionMode");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 if (!isActiveSubscription(subId)) {
3197 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3198 }
3199 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003202 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003203 }
3204
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003206 public boolean isInEmergencySmsMode() {
3207 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 for (Phone phone : PhoneFactory.getPhones()) {
3211 if (phone.isInEmergencySmsMode()) {
3212 return true;
3213 }
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 return false;
3219 }
3220
shilu366312e2019-12-17 09:28:10 -08003221 /**
3222 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3223 * @param subId The subscription to use to check the configuration.
3224 * @param c The callback that will be used to send the result.
3225 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003226 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003227 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3228 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003229 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3230 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003231
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003232 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3233 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3234 "IMS not available on device.");
3235 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 final long token = Binder.clearCallingIdentity();
3237 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003239 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(token);
3245 }
3246 }
3247
shilu366312e2019-12-17 09:28:10 -08003248 /**
3249 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3250 * @param subId The subscription to use to check the configuration.
3251 * @param c The callback that will be used to send the result.
3252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003254 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003255 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3256 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003257 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3258 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3259 }
Meng Wangafbc5852019-09-19 17:37:13 -07003260 final long token = Binder.clearCallingIdentity();
3261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3264 .removeRegistrationCallbackForSubscription(c, subId);
3265 } catch (ImsException e) {
3266 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3267 + "is inactive, ignoring unregister.");
3268 // If the subscription is no longer active, just return, since the callback
3269 // will already have been removed internally.
3270 } finally {
3271 Binder.restoreCallingIdentity(token);
3272 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 }
3274
Brad Ebingera34a6c22019-10-22 17:36:18 -07003275 /**
3276 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3277 */
3278 @Override
3279 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3280 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3281 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3282 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3283 "IMS not available on device.");
3284 }
3285 final long token = Binder.clearCallingIdentity();
3286 try {
3287 Phone phone = getPhone(subId);
3288 if (phone == null) {
3289 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3290 + subId + "'");
3291 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3292 }
3293 phone.getImsRegistrationState(regState -> {
3294 try {
3295 consumer.accept((regState == null)
3296 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3297 } catch (RemoteException e) {
3298 // Ignore if the remote process is no longer available to call back.
3299 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3300 }
3301 });
3302 } finally {
3303 Binder.restoreCallingIdentity(token);
3304 }
3305 }
3306
3307 /**
3308 * Get the transport type for the IMS service registration state.
3309 */
3310 @Override
3311 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003312 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3313 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3316 "IMS not available on device.");
3317 }
3318 final long token = Binder.clearCallingIdentity();
3319 try {
3320 Phone phone = getPhone(subId);
3321 if (phone == null) {
3322 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3323 + subId + "'");
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3325 }
3326 phone.getImsRegistrationTech(regTech -> {
3327 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3328 int regTechConverted = (regTech == null)
3329 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3330 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3331 regTechConverted);
3332 try {
3333 consumer.accept(regTechConverted);
3334 } catch (RemoteException e) {
3335 // Ignore if the remote process is no longer available to call back.
3336 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3337 }
3338 });
3339 } finally {
3340 Binder.restoreCallingIdentity(token);
3341 }
3342 }
3343
shilu366312e2019-12-17 09:28:10 -08003344 /**
3345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3346 * @param subId The subscription to use to check the configuration.
3347 * @param c The callback that will be used to send the result.
3348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003350 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3351 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003352 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3353 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003354 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3355 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3356 "IMS not available on device.");
3357 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3359 final long token = Binder.clearCallingIdentity();
3360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003363 } catch (ImsException e) {
3364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 } finally {
3366 Binder.restoreCallingIdentity(token);
3367 }
3368 }
3369
shilu366312e2019-12-17 09:28:10 -08003370 /**
3371 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3372 * @param subId The subscription to use to check the configuration.
3373 * @param c The callback that will be used to send the result.
3374 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003376 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003377 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3378 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3381 }
Meng Wangafbc5852019-09-19 17:37:13 -07003382
3383 final long token = Binder.clearCallingIdentity();
3384 try {
3385 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3386 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003387 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003388 } catch (ImsException e) {
3389 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3390 + "is inactive, ignoring unregister.");
3391 // If the subscription is no longer active, just return, since the callback
3392 // will already have been removed internally.
3393 } finally {
3394 Binder.restoreCallingIdentity(token);
3395 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 }
3397
3398 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003399 public boolean isCapable(int subId, int capability, int regTech) {
3400 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3402 final long token = Binder.clearCallingIdentity();
3403 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003406 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3408 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003410 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3411 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 } finally {
3413 Binder.restoreCallingIdentity(token);
3414 }
3415 }
3416
3417 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003418 public boolean isAvailable(int subId, int capability, int regTech) {
3419 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 final long token = Binder.clearCallingIdentity();
3421 try {
3422 Phone phone = getPhone(subId);
3423 if (phone == null) return false;
3424 return phone.isImsCapabilityAvailable(capability, regTech);
3425 } finally {
3426 Binder.restoreCallingIdentity(token);
3427 }
3428 }
3429
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003430 /**
3431 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3432 * subscription.
3433 * @param subId The subscription to use to check the configuration.
3434 * @param callback The callback that will be used to send the result.
3435 * @param capability The MmTelFeature capability that will be used to send the result.
3436 * @param transportType The transport type of the MmTelFeature capability.
3437 */
3438 @Override
3439 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3440 int transportType) {
3441 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3442 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3443 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3444 "IMS not available on device.");
3445 }
3446 final long token = Binder.clearCallingIdentity();
3447 try {
3448 int slotId = getSlotIndex(subId);
3449 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3450 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3451 + subId + "'");
3452 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3453 }
3454 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3455 transportType, aBoolean -> {
3456 try {
3457 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3458 } catch (RemoteException e) {
3459 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3460 + "running. Ignore");
3461 }
3462 });
3463 } finally {
3464 Binder.restoreCallingIdentity(token);
3465 }
3466 }
3467
shilu366312e2019-12-17 09:28:10 -08003468 /**
3469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3470 * @param subId The subscription to use to check the configuration.
3471 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003472 @Override
3473 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003474 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3475 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003476
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3478 final long token = Binder.clearCallingIdentity();
3479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003482 } catch (ImsException e) {
3483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003484 } finally {
3485 Binder.restoreCallingIdentity(token);
3486 }
3487 }
3488
3489 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003490 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003492 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003496 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003498 } catch (ImsException e) {
3499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
3503 }
3504
shilu366312e2019-12-17 09:28:10 -08003505 /**
3506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3507 * @param subId The subscription to use to check the configuration.
3508 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003510 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003511 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3512 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003516 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3517 } catch (ImsException e) {
3518 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522 }
3523
3524 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003525 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003527 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003531 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003532 } catch (ImsException e) {
3533 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
3537 }
3538
shilu366312e2019-12-17 09:28:10 -08003539 /**
3540 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3541 * @param subId The subscription to use to check the configuration.
3542 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 @Override
3544 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003545 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3546 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 } catch (ImsException e) {
3553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
3557 }
3558
3559 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003560 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003562 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003566 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003567 } catch (ImsException e) {
3568 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
3572 }
3573
shilu366312e2019-12-17 09:28:10 -08003574 /**
3575 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3576 * @param subId The subscription to use to check the configuration.
3577 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 @Override
3579 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003580 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3581 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
3594 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003595 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003597 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003603 } catch (ImsException e) {
3604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
3609
3610 @Override
3611 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3613 "setVoWiFiNonPersistent");
3614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003617 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003618 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003619 } catch (ImsException e) {
3620 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
3624 }
3625
shilu366312e2019-12-17 09:28:10 -08003626 /**
3627 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3628 * @param subId The subscription to use to check the configuration.
3629 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 @Override
3631 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003632 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3633 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003639 } catch (ImsException e) {
3640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 }
3645
3646 @Override
3647 public void setVoWiFiModeSetting(int subId, int mode) {
3648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3649 "setVoWiFiModeSetting");
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003655 } catch (ImsException e) {
3656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
3660 }
3661
3662 @Override
3663 public int getVoWiFiRoamingModeSetting(int subId) {
3664 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003670 } catch (ImsException e) {
3671 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
3677 @Override
3678 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3680 "setVoWiFiRoamingModeSetting");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003684 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003686 } catch (ImsException e) {
3687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
3694 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3696 "setRttCapabilityEnabled");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003700 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3701 } catch (ImsException e) {
3702 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
3706 }
3707
shilu366312e2019-12-17 09:28:10 -08003708 /**
3709 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3710 * @param subId The subscription to use to check the configuration.
3711 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 @Override
3713 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003714 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3715 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003721 } catch (ImsException e) {
3722 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 }
3727
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003728 @Override
3729 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3730 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003733 if (!isImsAvailableOnDevice()) {
3734 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3735 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003736 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003739 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003740 } catch (ImsException e) {
3741 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
3747 @Override
3748 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3749 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3750 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3753 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003754 try {
3755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003757 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003759 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3760 + "is inactive, ignoring unregister.");
3761 // If the subscription is no longer active, just return, since the callback will already
3762 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 }
3767
allenwtsu99c623b2020-01-03 18:24:23 +08003768
3769 private void checkModifyPhoneStatePermission(int subId, String message) {
3770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3771 message);
3772 }
3773
3774 private boolean isImsProvisioningRequired(int subId, int capability,
3775 boolean isMmtelCapability) {
3776 Phone phone = getPhone(subId);
3777 if (phone == null) {
3778 loge("phone instance null for subid " + subId);
3779 return false;
3780 }
3781 if (isMmtelCapability) {
3782 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3783 return false;
3784 }
3785 } else {
3786 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3787 return false;
3788 }
3789 }
3790 return true;
3791 }
3792
3793 @Override
3794 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3795 boolean isProvisioned) {
3796 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3801 if (!isImsProvisioningRequired(subId, capability, false)) {
3802 return;
3803 }
3804
3805 // this capability requires provisioning, route to the correct API.
3806 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3807 switch (capability) {
3808 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3809 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3810 ims.setEabProvisioned(isProvisioned);
3811 break;
3812 default: {
3813 throw new IllegalArgumentException("Tried to set provisioning for "
3814 + "rcs capability '" + capability + "', which does not require "
3815 + "provisioning.");
3816 }
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821
3822 }
3823
3824
3825 @Override
3826 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3827 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3831 if (!isImsProvisioningRequired(subId, capability, false)) {
3832 return true;
3833 }
3834
3835 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3836 switch (capability) {
3837 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3838 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3839 return ims.isEabProvisionedOnDevice();
3840
3841 default: {
3842 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3843 + "capability '" + capability + "', which does not require "
3844 + "provisioning.");
3845 }
3846 }
3847
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
3850 }
3851 }
3852
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003853 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003854 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3855 boolean isProvisioned) {
3856 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3857 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3858 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3859 }
allenwtsu99c623b2020-01-03 18:24:23 +08003860 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003864 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003865 return;
3866 }
3867
3868 // this capability requires provisioning, route to the correct API.
3869 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3870 switch (capability) {
3871 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3872 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3873 ims.setVolteProvisioned(isProvisioned);
3874 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3875 ims.setWfcProvisioned(isProvisioned);
3876 }
3877 break;
3878 }
3879 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3880 // There is currently no difference in VT provisioning type.
3881 ims.setVtProvisioned(isProvisioned);
3882 break;
3883 }
3884 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3885 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3886 // change the capability of the feature instead if needed.
3887 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3888 == isProvisioned) {
3889 // No change in provisioning.
3890 return;
3891 }
3892 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3893 try {
3894 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003895 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003896 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3897 + ", Exception" + e.getMessage());
3898 }
3899 break;
3900 }
3901 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003902 throw new IllegalArgumentException("Tried to set provisioning for "
3903 + "MmTel capability '" + capability + "', which does not require "
3904 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 }
3906 }
3907
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
3910 }
3911 }
3912
3913 @Override
3914 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3915 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3916 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3917 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3918 }
3919 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003923 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003924 return true;
3925 }
3926
3927 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3928 switch (capability) {
3929 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3930 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3931 return ims.isVolteProvisionedOnDevice();
3932 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3933 return ims.isWfcProvisionedOnDevice();
3934 }
3935 // This should never happen, since we are checking tech above to make sure it
3936 // is either LTE or IWLAN.
3937 throw new IllegalArgumentException("Invalid radio technology for voice "
3938 + "capability.");
3939 }
3940 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3941 // There is currently no difference in VT provisioning type.
3942 return ims.isVtProvisionedOnDevice();
3943 }
3944 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3945 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3946 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3947 }
3948 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003949 throw new IllegalArgumentException(
3950 "Tried to get provisioning for MmTel capability '" + capability
3951 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003952 }
3953 }
3954
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959
3960 @Override
3961 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3962 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3963 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3964 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3965 }
3966 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3967 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3968 return (provisionedBits & capability) > 0;
3969 }
3970
3971 @Override
3972 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3973 boolean isProvisioned) {
3974 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3975 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3976 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3977 }
3978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3979 "setProvisioningStatusForCapability");
3980 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3981 // If the current provisioning status for capability already matches isProvisioned,
3982 // do nothing.
3983 if (((provisionedBits & capability) > 0) == isProvisioned) {
3984 return;
3985 }
3986 if (isProvisioned) {
3987 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3988 } else {
3989 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3990 }
3991 }
3992
3993 /**
3994 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3995 * technology. The bitfield should mirror the bitfield defined by
3996 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3997 */
3998 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3999 String key = getMmTelProvisioningKey(subId, tech);
4000 // Default is no capabilities are provisioned.
4001 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4002 }
4003
4004 /**
4005 * Sets the MmTel capability provisioning bitfield (defined by
4006 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4007 * technology specified.
4008 *
4009 * Note: This is a synchronous command and should not be called on UI thread.
4010 */
4011 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4012 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4013 String key = getMmTelProvisioningKey(subId, tech);
4014 editor.putInt(key, newField);
4015 editor.commit();
4016 }
4017
4018 private static String getMmTelProvisioningKey(int subId, int tech) {
4019 // resulting key is provision_ims_mmtel_{subId}_{tech}
4020 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4021 }
4022
4023 /**
4024 * Query CarrierConfig to see if the specified capability requires provisioning for the
4025 * carrier associated with the subscription id.
4026 */
4027 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4028 int capability) {
4029 CarrierConfigManager configManager = new CarrierConfigManager(context);
4030 PersistableBundle c = configManager.getConfigForSubId(subId);
4031 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004032 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004033 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4034 false);
4035 boolean requireVoiceVtProvisioning = c.getBoolean(
4036 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4037
4038 // First check to make sure that the capability requires provisioning.
4039 switch (capability) {
4040 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4041 // intentional fallthrough
4042 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4043 if (requireVoiceVtProvisioning) {
4044 // Voice and Video requires provisioning
4045 return true;
4046 }
4047 break;
4048 }
4049 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4050 if (requireUtProvisioning) {
4051 // UT requires provisioning
4052 return true;
4053 }
4054 break;
4055 }
4056 }
4057 return false;
4058 }
4059
allenwtsu99c623b2020-01-03 18:24:23 +08004060 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4061 int capability) {
4062 CarrierConfigManager configManager = new CarrierConfigManager(context);
4063 PersistableBundle c = configManager.getConfigForSubId(subId);
4064
4065 boolean requireRcsProvisioning = c.getBoolean(
4066 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4067
4068 // First check to make sure that the capability requires provisioning.
4069 switch (capability) {
4070 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4071 // intentional fallthrough
4072 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4073 if (requireRcsProvisioning) {
4074 // OPTION or PRESENCE requires provisioning
4075 return true;
4076 }
4077 break;
4078 }
4079 }
4080 return false;
4081 }
4082
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004083 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004084 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4086 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4087 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004088 enforceReadPrivilegedPermission("getImsProvisioningInt");
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004092 int slotId = getSlotIndex(subId);
4093 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4094 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4095 + subId + "' for key:" + key);
4096 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4097 }
4098 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004100 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4101 + subId + "' for key:" + key);
4102 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
4106 }
4107
4108 @Override
4109 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4111 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4112 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004113 enforceReadPrivilegedPermission("getImsProvisioningString");
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004117 int slotId = getSlotIndex(subId);
4118 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4119 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4120 + subId + "' for key:" + key);
4121 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4122 }
4123 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004125 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4126 + subId + "' for key:" + key);
4127 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
4131 }
4132
4133 @Override
4134 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004135 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4136 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4137 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4139 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004143 int slotId = getSlotIndex(subId);
4144 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4145 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4146 + subId + "' for key:" + key);
4147 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4148 }
4149 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004151 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4152 + "' for key:" + key);
4153 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
4157 }
4158
4159 @Override
4160 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004161 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4162 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4163 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4165 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004169 int slotId = getSlotIndex(subId);
4170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4171 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4172 + subId + "' for key:" + key);
4173 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4174 }
4175 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004176 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004177 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4178 + "' for key:" + key);
4179 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 int slotId = SubscriptionManager.getSlotIndex(subId);
4187 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4189 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 }
4191 return slotId;
4192 }
4193
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004194 private int getSlotIndex(int subId) {
4195 int slotId = SubscriptionManager.getSlotIndex(subId);
4196 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4197 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4198 }
4199 return slotId;
4200 }
4201
Wink Saville36469e72014-06-11 15:17:00 -07004202 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004203 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004204 */
4205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004206 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4207 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004208 final int targetSdk = getTargetSdk(callingPackage);
4209 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004210 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004211 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004212 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004213 mApp, subId, callingPackage, callingFeatureId,
4214 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4216 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 final Phone phone = getPhone(subId);
4221 if (phone != null) {
4222 return phone.getServiceState().getDataNetworkType();
4223 } else {
4224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4225 }
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004229 }
4230
4231 /**
4232 * Returns the data network type
4233 */
4234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004235 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4236 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4237 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004238 }
4239
4240 /**
4241 * Returns the data network type for a subId
4242 */
4243 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004244 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004247 mApp, subId, callingPackage, callingFeatureId,
4248 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4250 }
4251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 final Phone phone = getPhone(subId);
4255 if (phone != null) {
4256 return phone.getServiceState().getDataNetworkType();
4257 } else {
4258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4259 }
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004263 }
4264
4265 /**
Wink Saville36469e72014-06-11 15:17:00 -07004266 * Returns the Voice network type for a subId
4267 */
4268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4270 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4275 }
4276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final Phone phone = getPhone(subId);
4280 if (phone != null) {
4281 return phone.getServiceState().getVoiceNetworkType();
4282 } else {
4283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004288 }
4289
4290 /**
4291 * @return true if a ICC card is present
4292 */
4293 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004294 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004295 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4296 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004297 }
4298
4299 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004300 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004301 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004302 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004303 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 final Phone phone = PhoneFactory.getPhone(slotIndex);
4307 if (phone != null) {
4308 return phone.getIccCard().hasIccCard();
4309 } else {
4310 return false;
4311 }
4312 } finally {
4313 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004315 }
4316
4317 /**
4318 * Return if the current radio is LTE on CDMA. This
4319 * is a tri-state return value as for a period of time
4320 * the mode may be unknown.
4321 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004322 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004323 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004324 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004325 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004326 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004327 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4328 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4329 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004330 }
4331
Sanket Padawe356d7632015-06-22 14:03:32 -07004332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004333 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4334 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004335 try {
4336 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4337 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004338 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4339 }
4340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 final Phone phone = getPhone(subId);
4344 if (phone == null) {
4345 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4346 } else {
4347 return phone.getLteOnCdmaMode();
4348 }
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004351 }
Wink Saville36469e72014-06-11 15:17:00 -07004352 }
4353
Wink Saville36469e72014-06-11 15:17:00 -07004354 /**
4355 * {@hide}
4356 * Returns Default subId, 0 in the case of single standby.
4357 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004358 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004359 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004360 }
4361
Shishir Agrawala9f32182016-04-12 12:00:16 -07004362 private int getSlotForDefaultSubscription() {
4363 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4364 }
4365
Wink Savilleb564aae2014-10-23 10:18:09 -07004366 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004367 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004368 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004369
Pengquan Menge92a50d2018-09-21 15:54:48 -07004370 private boolean isActiveSubscription(int subId) {
4371 return mSubscriptionController.isActiveSubId(subId);
4372 }
4373
Ihab Awadf2177b72013-11-25 13:33:23 -08004374 /**
4375 * @see android.telephony.TelephonyManager.WifiCallingChoices
4376 */
4377 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004380 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4382 getWhenToMakeWifiCallsDefaultPreference());
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
4385 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004386 }
4387
4388 /**
4389 * @see android.telephony.TelephonyManager.WifiCallingChoices
4390 */
4391 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004395 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004400 }
4401
Sailesh Nepald1e68152013-12-12 19:08:02 -08004402 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004403 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004404 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004405 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004406
Jordan Liu4c733742019-02-28 12:03:40 -08004407 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4408 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4409 if (phoneId == -1) {
4410 throw new IllegalArgumentException("Given slot index: " + slotIndex
4411 + " does not correspond to an active phone");
4412 }
4413 return PhoneFactory.getPhone(phoneId);
4414 }
4415
Shishir Agrawal566b7612013-10-28 14:41:00 -07004416 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004417 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4418 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4420 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004422 if (DBG) {
4423 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4424 }
4425 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4426 p2);
4427 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004428
Jordan Liu4c733742019-02-28 12:03:40 -08004429
4430 @Override
4431 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4432 int slotIndex, String callingPackage, String aid, int p2) {
4433 enforceModifyPermission();
4434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4435 if (DBG) {
4436 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4437 }
4438 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4439 callingPackage, aid, p2);
4440 }
4441
4442 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4443 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 if (TextUtils.equals(ISDR_AID, aid)) {
4447 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004448 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4449 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 if (bestComponent == null
4451 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4452 loge("The calling package is not allowed to access ISD-R.");
4453 throw new SecurityException(
4454 "The calling package is not allowed to access ISD-R.");
4455 }
Derek Tan740e1672017-06-27 14:56:27 -07004456 }
Derek Tan740e1672017-06-27 14:56:27 -07004457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004459 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4460 null /* workSource */);
4461 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 return response;
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004466 }
4467
4468 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004469 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4471 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004472 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4473 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004475
Jordan Liu4c733742019-02-28 12:03:40 -08004476 @Override
4477 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4478 enforceModifyPermission();
4479 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4480 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4481 channel);
4482 }
4483
4484 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 final long identity = Binder.clearCallingIdentity();
4486 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 if (channel < 0) {
4488 return false;
4489 }
Jordan Liu4c733742019-02-28 12:03:40 -08004490 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4491 null /* workSource */);
4492 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493 return success;
4494 } finally {
4495 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004497 }
4498
4499 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004500 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004501 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4503 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004504 if (DBG) {
4505 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4506 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4507 + p3 + " data=" + data);
4508 }
4509 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4510 command, p1, p2, p3, data);
4511 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004512
Jordan Liu4c733742019-02-28 12:03:40 -08004513 @Override
4514 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4515 int command, int p1, int p2, int p3, String data) {
4516 enforceModifyPermission();
4517 if (DBG) {
4518 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4519 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4520 + p3 + " data=" + data);
4521 }
4522 return iccTransmitApduLogicalChannelWithPermission(
4523 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4524 data);
4525 }
4526
4527 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4528 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004531 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 return "";
4533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004536 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4537 null /* workSource */);
4538 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 // Append the returned status code to the end of the response payload.
4541 String s = Integer.toHexString(
4542 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4543 if (response.payload != null) {
4544 s = IccUtils.bytesToHexString(response.payload) + s;
4545 }
4546 return s;
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004549 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004550 }
Jake Hambye994d462014-02-03 13:10:13 -08004551
Evan Charltonc66da362014-05-16 14:06:40 -07004552 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004553 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4554 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4556 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004558 if (DBG) {
4559 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4560 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4561 }
4562 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4563 cla, command, p1, p2, p3, data);
4564 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004565
Jordan Liu4c733742019-02-28 12:03:40 -08004566 @Override
4567 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4568 int command, int p1, int p2, int p3, String data) {
4569 enforceModifyPermission();
4570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4571 if (DBG) {
4572 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4573 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4574 + " data=" + data);
4575 }
4576
4577 return iccTransmitApduBasicChannelWithPermission(
4578 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4579 p2, p3, data);
4580 }
4581
4582 // open APDU basic channel assuming the caller has sufficient permissions
4583 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4584 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4588 && TextUtils.equals(ISDR_AID, data)) {
4589 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004590 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4591 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 if (bestComponent == null
4593 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4594 loge("The calling package is not allowed to select ISD-R.");
4595 throw new SecurityException(
4596 "The calling package is not allowed to select ISD-R.");
4597 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004598 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004601 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4602 null /* workSource */);
4603 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 // Append the returned status code to the end of the response payload.
4606 String s = Integer.toHexString(
4607 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4608 if (response.payload != null) {
4609 s = IccUtils.bytesToHexString(response.payload) + s;
4610 }
4611 return s;
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004615 }
4616
4617 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004618 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004619 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4621 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 if (DBG) {
4626 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4627 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4628 }
4629
4630 IccIoResult response =
4631 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4632 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4633 subId);
4634
4635 if (DBG) {
4636 log("Exchange SIM_IO [R]" + response);
4637 }
4638
4639 byte[] result = null;
4640 int length = 2;
4641 if (response.payload != null) {
4642 length = 2 + response.payload.length;
4643 result = new byte[length];
4644 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4645 } else {
4646 result = new byte[length];
4647 }
4648
4649 result[length - 1] = (byte) response.sw2;
4650 result[length - 2] = (byte) response.sw1;
4651 return result;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004655 }
4656
Nathan Haroldb3014052017-01-25 15:57:32 -08004657 /**
4658 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4659 * on a particular subscription
4660 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004661 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4662 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004664 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004665 return null;
4666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
4670 if (appType != TelephonyManager.APPTYPE_USIM
4671 && appType != TelephonyManager.APPTYPE_SIM) {
4672 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4673 return null;
4674 }
4675 Object response = sendRequest(
4676 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4677 if (response instanceof String[]) {
4678 return (String[]) response;
4679 }
yincheng zhao2737e882019-09-06 17:06:54 -07004680 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004682 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004685 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004686 }
4687
yincheng zhao2737e882019-09-06 17:06:54 -07004688 /**
4689 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4690 * subscription.
4691 *
4692 * @param subId the id of the subscription.
4693 * @param appType the uicc app type, must be USIM or SIM.
4694 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4695 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004696 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004697 * @return number of fplmns that is successfully written to the SIM.
4698 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004699 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4700 String callingFeatureId) {
4701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4702 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004703 if (DBG) logv("no permissions for setForbiddenplmns");
4704 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4705 }
4706 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4707 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4708 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4709 }
4710 if (fplmns == null) {
4711 throw new IllegalArgumentException("Fplmn List provided is null");
4712 }
4713 for (String fplmn : fplmns) {
4714 if (!CellIdentity.isValidPlmn(fplmn)) {
4715 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4716 }
4717 }
4718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 Object response = sendRequest(
4721 CMD_SET_FORBIDDEN_PLMNS,
4722 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4723 subId);
4724 return (int) response;
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004730 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004731 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4733 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 final long identity = Binder.clearCallingIdentity();
4736 try {
4737 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4738 if (response.payload == null) {
4739 return "";
4740 }
Evan Charltonc66da362014-05-16 14:06:40 -07004741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 // Append the returned status code to the end of the response payload.
4743 String s = Integer.toHexString(
4744 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4745 s = IccUtils.bytesToHexString(response.payload) + s;
4746 return s;
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
Evan Charltonc66da362014-05-16 14:06:40 -07004750 }
4751
Jake Hambye994d462014-02-03 13:10:13 -08004752 /**
4753 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4754 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4755 *
4756 * @param itemID the ID of the item to read
4757 * @return the NV item as a String, or null on error.
4758 */
4759 @Override
4760 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4763 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764
4765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004768 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4770 return value;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Jake Hambye994d462014-02-03 13:10:13 -08004774 }
4775
4776 /**
4777 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4778 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4779 *
4780 * @param itemID the ID of the item to read
4781 * @param itemValue the value to write, as a String
4782 * @return true on success; false on any failure
4783 */
4784 @Override
4785 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4788 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789
4790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4793 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004794 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4796 return success;
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
4799 }
Jake Hambye994d462014-02-03 13:10:13 -08004800 }
4801
4802 /**
4803 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4804 * Used for device configuration by some CDMA operators.
4805 *
4806 * @param preferredRoamingList byte array containing the new PRL
4807 * @return true on success; false on any failure
4808 */
4809 @Override
4810 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4817 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4818 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4819 return success;
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Jake Hambye994d462014-02-03 13:10:13 -08004823 }
4824
4825 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004826 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004827 * Used for device configuration by some CDMA operators.
4828 *
chen xu6dac5ab2018-10-26 17:39:23 -07004829 * @param slotIndex - device slot.
4830 *
Jake Hambye994d462014-02-03 13:10:13 -08004831 * @return true on success; false on any failure
4832 */
4833 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004834 public boolean resetModemConfig(int slotIndex) {
4835 Phone phone = PhoneFactory.getPhone(slotIndex);
4836 if (phone != null) {
4837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4838 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839
chen xu6dac5ab2018-10-26 17:39:23 -07004840 final long identity = Binder.clearCallingIdentity();
4841 try {
4842 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4843 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4844 return success;
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 }
chen xu6dac5ab2018-10-26 17:39:23 -07004849 return false;
4850 }
4851
4852 /**
4853 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4854 *
4855 * @param slotIndex - device slot.
4856 *
4857 * @return true on success; false on any failure
4858 */
4859 @Override
4860 public boolean rebootModem(int slotIndex) {
4861 Phone phone = PhoneFactory.getPhone(slotIndex);
4862 if (phone != null) {
4863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4864 mApp, phone.getSubId(), "rebootModem");
4865
4866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4869 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4870 return success;
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
4874 }
4875 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004876 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004877
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004878 public String[] getPcscfAddress(String apnType, String callingPackage,
4879 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004880 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4882 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004883 return new String[0];
4884 }
4885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 final long identity = Binder.clearCallingIdentity();
4887 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004888 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
Wink Saville36469e72014-06-11 15:17:00 -07004892 }
4893
Brad Ebinger51f743a2017-01-23 13:50:20 -08004894 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004895 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4896 * {@link #disableIms(int)}.
4897 * @param slotIndex device slot.
4898 */
4899 public void resetIms(int slotIndex) {
4900 enforceModifyPermission();
4901
4902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 if (mImsResolver == null) {
4905 // may happen if the does not support IMS.
4906 return;
4907 }
4908 mImsResolver.disableIms(slotIndex);
4909 mImsResolver.enableIms(slotIndex);
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004916 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4917 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004918 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004919 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004920 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921
4922 final long identity = Binder.clearCallingIdentity();
4923 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004924 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004925 // may happen if the device does not support IMS.
4926 return;
4927 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004928 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004932 }
4933
4934 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004935 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4936 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004937 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004938 public void disableIms(int slotId) {
4939 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004943 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004944 // may happen if the device does not support IMS.
4945 return;
4946 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004947 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004951 }
4952
4953 /**
4954 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4955 * feature or {@link null} if the service is not available. If the feature is available, the
4956 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4957 */
4958 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004959 IImsServiceFeatureCallback callback) {
4960 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004964 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004965 // may happen if the device does not support IMS.
4966 return null;
4967 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004968 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004972 }
4973
4974 /**
4975 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4976 * feature during emergency calling or {@link null} if the service is not available. If the
4977 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4978 * listener for feature updates.
4979 */
4980 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004985 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004986 // may happen if the device does not support IMS.
4987 return null;
4988 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004989 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004993 }
4994
Brad Ebinger5f64b052017-12-14 14:26:15 -08004995 /**
4996 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004997 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004998 */
4999 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005004 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005005 // may happen if the device does not support IMS.
5006 return null;
5007 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005008 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005012 }
5013
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005014 /**
5015 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005016 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005017 */
5018 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
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.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005031 }
5032
Brad Ebinger884c07b2018-02-15 16:17:40 -08005033 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005034 * Sets the ImsService Package Name that Telephony will bind to.
5035 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005036 * @param slotIndex the slot ID that the ImsService should bind for.
5037 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005038 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005039 * @param featureTypes An integer array of feature types associated with a packageName.
5040 * @param packageName The name of the package that the current configuration will be replaced
5041 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005042 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005043 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005044 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5045 int[] featureTypes, String packageName) {
5046 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5049 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005050 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005054 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005055 // may happen if the device does not support IMS.
5056 return false;
5057 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005058 Map<Integer, String> featureConfig = new HashMap<>();
5059 for (int featureType : featureTypes) {
5060 featureConfig.put(featureType, packageName);
5061 }
5062 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5063 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005067 }
5068
5069 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005070 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005071 *
5072 * @param slotId The slot that the ImsService is associated with.
5073 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5074 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005075 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 * @return the package name of the ImsService configuration.
5077 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5079 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005080 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005081 TelephonyPermissions
5082 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5083 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5084 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 final long identity = Binder.clearCallingIdentity();
5087 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005088 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005089 // may happen if the device does not support IMS.
5090 return "";
5091 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005092 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005093 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5094 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005098 }
5099
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005100 /**
5101 * Get the MmTelFeature state associated with the requested subscription id.
5102 * @param subId The subscription that the MmTelFeature is associated with.
5103 * @param callback A callback with an integer containing the
5104 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5105 */
5106 @Override
5107 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5108 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5109 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5110 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5111 "IMS not available on device.");
5112 }
5113 final long token = Binder.clearCallingIdentity();
5114 try {
5115 int slotId = getSlotIndex(subId);
5116 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5117 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5118 + subId + "'");
5119 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5120 }
5121 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5122 try {
5123 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5124 } catch (RemoteException e) {
5125 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5126 + "Ignore");
5127 }
5128 });
5129 } finally {
5130 Binder.restoreCallingIdentity(token);
5131 }
5132 }
5133
Wink Saville36469e72014-06-11 15:17:00 -07005134 public void setImsRegistrationState(boolean registered) {
5135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136
5137 final long identity = Binder.clearCallingIdentity();
5138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005139 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
Wink Saville36469e72014-06-11 15:17:00 -07005143 }
5144
5145 /**
Stuart Scott54788802015-03-30 13:18:01 -07005146 * Set the network selection mode to automatic.
5147 *
5148 */
5149 @Override
5150 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5152 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
shilufc958392020-01-20 11:36:01 -08005156 if (!isActiveSubscription(subId)) {
5157 return;
5158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5160 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Stuart Scott54788802015-03-30 13:18:01 -07005164 }
5165
Pengquan Mengea84e042018-09-20 14:57:26 -07005166 /**
5167 * Ask the radio to connect to the input network and change selection mode to manual.
5168 *
5169 * @param subId the id of the subscription.
5170 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5171 * the operator to attach to.
5172 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5173 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5174 * normal network selection next time.
5175 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005176 */
5177 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005178 public boolean setNetworkSelectionModeManual(
5179 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5181 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005182
5183 if (!isActiveSubscription(subId)) {
5184 return false;
5185 }
5186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005189 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005191 if (DBG) {
5192 log("setNetworkSelectionModeManual: subId: " + subId
5193 + " operator: " + operatorInfo);
5194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005199 }
shilu84f6e8b2019-12-19 13:58:01 -08005200 /**
5201 * Get the manual network selection
5202 *
5203 * @param subId the id of the subscription.
5204 *
5205 * @return the previously saved user selected PLMN
5206 */
5207 @Override
5208 public String getManualNetworkSelectionPlmn(int subId) {
5209 TelephonyPermissions
5210 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5211 mApp, subId, "getManualNetworkSelectionPlmn");
5212
5213 final long identity = Binder.clearCallingIdentity();
5214 try {
5215 if (!isActiveSubscription(subId)) {
5216 return "";
5217 }
5218
5219 final Phone phone = getPhone(subId);
5220 if (phone == null) {
5221 return "";
5222 }
5223 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5224 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5225 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
5229 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005230
5231 /**
5232 * Scans for available networks.
5233 */
5234 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005235 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5236 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5238 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005239 LocationAccessPolicy.LocationPermissionResult locationResult =
5240 LocationAccessPolicy.checkLocationPermission(mApp,
5241 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5242 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005243 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005244 .setCallingPid(Binder.getCallingPid())
5245 .setCallingUid(Binder.getCallingUid())
5246 .setMethod("getCellNetworkScanResults")
5247 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5248 .build());
5249 switch (locationResult) {
5250 case DENIED_HARD:
5251 throw new SecurityException("Not allowed to access scan results -- location");
5252 case DENIED_SOFT:
5253 return null;
5254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255
Pengquan Menga1bb6272018-09-06 09:59:22 -07005256 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 try {
5258 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005259 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005264 }
5265
5266 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005267 * Get the call forwarding info, given the call forwarding reason.
5268 */
5269 @Override
5270 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5271 enforceReadPrivilegedPermission("getCallForwarding");
5272 long identity = Binder.clearCallingIdentity();
5273 try {
5274 if (DBG) {
5275 log("getCallForwarding: subId " + subId
5276 + " callForwardingReason" + callForwardingReason);
5277 }
5278 return (CallForwardingInfo) sendRequest(
5279 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
5283 }
5284
5285 /**
5286 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5287 * reason, the number to forward, and the timeout before the forwarding is attempted.
5288 */
5289 @Override
5290 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5291 enforceModifyPermission();
5292 long identity = Binder.clearCallingIdentity();
5293 try {
5294 if (DBG) {
5295 log("setCallForwarding: subId " + subId
5296 + " callForwardingInfo" + callForwardingInfo);
5297 }
5298 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
5302 }
5303
5304 /**
5305 * Get the call forwarding info, given the call forwarding reason.
5306 */
5307 @Override
5308 public int getCallWaitingStatus(int subId) {
5309 enforceReadPrivilegedPermission("getCallForwarding");
5310 long identity = Binder.clearCallingIdentity();
5311 try {
5312 if (DBG) log("getCallWaitingStatus: subId " + subId);
5313 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
5319 /**
5320 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5321 * reason, the number to forward, and the timeout before the forwarding is attempted.
5322 */
5323 @Override
5324 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5325 enforceModifyPermission();
5326 long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5329 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
5333 }
5334
5335 /**
yinxub1bed742017-04-17 11:45:04 -07005336 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005337 *
yinxub1bed742017-04-17 11:45:04 -07005338 * @param subId id of the subscription
5339 * @param request contains the radio access networks with bands/channels to scan
5340 * @param messenger callback messenger for scan results or errors
5341 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005342 * @return the id of the requested scan which can be used to stop the scan.
5343 */
5344 @Override
5345 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005346 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005349 LocationAccessPolicy.LocationPermissionResult locationResult =
5350 LocationAccessPolicy.checkLocationPermission(mApp,
5351 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5352 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005353 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005354 .setCallingPid(Binder.getCallingPid())
5355 .setCallingUid(Binder.getCallingUid())
5356 .setMethod("requestNetworkScan")
5357 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5358 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005359 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005360 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005361 if (e != null) {
5362 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5363 throw e;
5364 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005365 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005366 return TelephonyScanManager.INVALID_SCAN_ID;
5367 }
5368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 }
Hall Liu912dfd32019-04-25 14:02:26 -07005370 int callingUid = Binder.getCallingUid();
5371 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 return mNetworkScanRequestTracker.startNetworkScan(
5375 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005376 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
yinxu504e1392017-04-12 16:03:22 -07005380 }
5381
Hall Liub2ac8ef2019-02-28 15:56:23 -08005382 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005383 NetworkScanRequest request, int subId) {
5384 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5385 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5386 boolean hasNetworkScanPermission =
5387 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5388 == PERMISSION_GRANTED;
5389
5390 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5391 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5392 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005393 }
5394
5395 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5396 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005397 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5398 return new SecurityException("Specific channels must not be"
5399 + " scanned without location access.");
5400 }
5401 }
5402 }
5403
Hall Liub2ac8ef2019-02-28 15:56:23 -08005404 return null;
5405 }
5406
yinxu504e1392017-04-12 16:03:22 -07005407 /**
5408 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005409 *
5410 * @param subId id of the subscription
5411 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005412 */
5413 @Override
5414 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5416 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417
Hall Liu912dfd32019-04-25 14:02:26 -07005418 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005421 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
yinxu504e1392017-04-12 16:03:22 -07005425 }
5426
5427 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005428 * Get the calculated preferred network type.
5429 * Used for debugging incorrect network type.
5430 *
5431 * @return the preferred network type, defined in RILConstants.java.
5432 */
5433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005434 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005435 final Phone defaultPhone = getDefaultPhone();
5436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005438 return RILConstants.PREFERRED_NETWORK_MODE;
5439 }
5440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005444 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
Junda Liu84d15a22014-07-02 11:21:04 -07005448 }
5449
5450 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005451 * Get the preferred network type.
5452 * Used for device configuration by some CDMA operators.
5453 *
5454 * @return the preferred network type, defined in RILConstants.java.
5455 */
5456 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005457 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005458 TelephonyPermissions
5459 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5460 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 if (DBG) log("getPreferredNetworkType");
5465 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5466 int networkType = (result != null ? result[0] : -1);
5467 if (DBG) log("getPreferredNetworkType: " + networkType);
5468 return networkType;
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005472 }
5473
5474 /**
5475 * Set the preferred network type.
5476 * Used for device configuration by some CDMA operators.
5477 *
5478 * @param networkType the preferred network type, defined in RILConstants.java.
5479 * @return true on success; false on any failure.
5480 */
5481 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005482 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5484 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005488 Settings.Global.putInt(mApp.getContentResolver(),
5489 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5490 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005493 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005494 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005495
5496 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005497 * Get the allowed network types that store in the telephony provider.
5498 *
5499 * @param subId the id of the subscription.
5500 * @return allowedNetworkTypes the allowed network types.
5501 */
5502 @Override
5503 public long getAllowedNetworkTypes(int subId) {
5504 TelephonyPermissions
5505 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5506 mApp, subId, "getAllowedNetworkTypes");
5507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 return SubscriptionManager.getLongSubscriptionProperty(
5511 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
5515 }
5516
5517 /**
5518 * Set the allowed network types.
5519 *
5520 * @param subId the id of the subscription.
5521 * @param allowedNetworkTypes the allowed network types.
5522 * @return true on success; false on any failure.
5523 */
5524 @Override
5525 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, subId, "setAllowedNetworkTypes");
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 SubscriptionManager.setSubscriptionProperty(subId,
5531 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5532 String.valueOf(allowedNetworkTypes));
5533 return setPreferredNetworkTypesInternal(subId);
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
5537 }
5538
5539 private boolean setPreferredNetworkTypesInternal(int subId) {
5540 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5541 Settings.Global.getInt(mApp.getContentResolver(),
5542 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5543 RILConstants.PREFERRED_NETWORK_MODE));
5544 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5545 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5546 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5547 (int) (networkTypeBitMask & allowedNetworkTypes));
5548
5549 if (DBG) {
5550 log("setPreferredNetworkTypesInternal: subId " + subId
5551 + " networkTypes " + networkTypeBitMask
5552 + " allowedNetworkTypes " + allowedNetworkTypes
5553 + " networkMode " + networkMode);
5554 }
5555
5556 Boolean success = (Boolean) sendRequest(
5557 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5558 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5559 return success;
5560 }
5561
5562 /**
Miaoa84611c2019-03-15 09:21:10 +08005563 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005564 *
Miaoa84611c2019-03-15 09:21:10 +08005565 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005566 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005567 * @hide
5568 */
5569 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005570 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005573 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 try {
Miaoa84611c2019-03-15 09:21:10 +08005575 if (phone != null) {
5576 return phone.hasMatchedTetherApnSetting();
5577 } else {
5578 return false;
5579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 } finally {
5581 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005582 }
Junda Liu475951f2014-11-07 16:45:03 -08005583 }
5584
5585 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005586 * Set mobile data enabled
5587 * Used by the user through settings etc to turn on/off mobile data
5588 *
5589 * @param enable {@code true} turn turn data on, else {@code false}
5590 */
5591 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005592 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5594 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595
5596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 int phoneId = mSubscriptionController.getPhoneId(subId);
5599 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5600 Phone phone = PhoneFactory.getPhone(phoneId);
5601 if (phone != null) {
5602 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005603 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 }
5607 } finally {
5608 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005609 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005610 }
5611
5612 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005613 * Enable or disable always reporting signal strength changes from radio.
5614 *
5615 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5616 */
5617 @Override
5618 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5619 enforceModifyPermission();
5620 enforceSystemCaller();
5621
5622 final long identity = Binder.clearCallingIdentity();
5623 final Phone phone = getPhone(subId);
5624 try {
5625 if (phone != null) {
5626 if (DBG) {
5627 log("setAlwaysReportSignalStrength: subId=" + subId
5628 + " isEnable=" + isEnable);
5629 }
5630 phone.setAlwaysReportSignalStrength(isEnable);
5631 } else {
5632 loge("setAlwaysReportSignalStrength: no phone found for subId="
5633 + subId);
5634 }
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
5638 }
5639
5640 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005641 * Get the user enabled state of Mobile Data.
5642 *
5643 * TODO: remove and use isUserDataEnabled.
5644 * This can't be removed now because some vendor codes
5645 * calls through ITelephony directly while they should
5646 * use TelephonyManager.
5647 *
5648 * @return true on enabled
5649 */
5650 @Override
5651 public boolean getDataEnabled(int subId) {
5652 return isUserDataEnabled(subId);
5653 }
5654
5655 /**
5656 * Get whether mobile data is enabled per user setting.
5657 *
5658 * There are other factors deciding whether mobile data is actually enabled, but they are
5659 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005660 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005661 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005662 *
5663 * @return {@code true} if data is enabled else {@code false}
5664 */
5665 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005666 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005667 try {
5668 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5669 null);
5670 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
5677 int phoneId = mSubscriptionController.getPhoneId(subId);
5678 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5679 Phone phone = PhoneFactory.getPhone(phoneId);
5680 if (phone != null) {
5681 boolean retVal = phone.isUserDataEnabled();
5682 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5683 return retVal;
5684 } else {
5685 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5686 return false;
5687 }
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005690 }
5691 }
5692
5693 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005694 * Checks if the device is capable of mobile data by considering whether whether the
5695 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5696 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005697 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005698 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005699 */
5700 @Override
5701 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005702 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703
5704 final long identity = Binder.clearCallingIdentity();
5705 try {
5706 int phoneId = mSubscriptionController.getPhoneId(subId);
5707 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5708 Phone phone = PhoneFactory.getPhone(phoneId);
5709 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005710 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5712 return retVal;
5713 } else {
5714 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5715 return false;
5716 }
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005719 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005720 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005721
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005722 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5723 Phone phone) {
5724 //load access rules from carrier configs, and check those as well: b/139133814
5725 SubscriptionController subController = SubscriptionController.getInstance();
5726 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5727 || subController == null) return privilegeFromSim;
5728
5729 int uid = Binder.getCallingUid();
5730 PackageManager pkgMgr = phone.getContext().getPackageManager();
5731 String[] packages = pkgMgr.getPackagesForUid(uid);
5732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5736 SubscriptionManager subManager = (SubscriptionManager)
5737 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5738 for (String pkg : packages) {
5739 if (subManager.canManageSubscription(subInfo, pkg)) {
5740 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5741 }
5742 }
5743 return privilegeFromSim;
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
5746 }
5747 }
5748
5749 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5750 String pkgName) {
5751 //load access rules from carrier configs, and check those as well: b/139133814
5752 SubscriptionController subController = SubscriptionController.getInstance();
5753 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5754 || subController == null) return privilegeFromSim;
5755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5759 SubscriptionManager subManager = (SubscriptionManager)
5760 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5761 return subManager.canManageSubscription(subInfo, pkgName)
5762 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
5766 }
5767
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005768 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005769 public int getCarrierPrivilegeStatus(int subId) {
5770 final Phone phone = getPhone(subId);
5771 if (phone == null) {
5772 loge("getCarrierPrivilegeStatus: Invalid subId");
5773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5774 }
5775 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005776 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005777 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5779 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005780
5781 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5782 card.getCarrierPrivilegeStatusForCurrentTransaction(
5783 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005784 }
Junda Liu29340342014-07-10 15:23:27 -07005785
5786 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005787 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005788 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005789 final Phone phone = getPhone(subId);
5790 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005791 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5793 }
5794 UiccProfile profile =
5795 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5796 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005797 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5799 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005800 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005801 profile.getCarrierPrivilegeStatusForUid(
5802 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005803 }
5804
5805 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005806 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5807 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005809 }
5810
5811 int phoneId = SubscriptionManager.getPhoneId(subId);
5812 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005813 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005814 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5816 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005817 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5818 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5819 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005820 }
5821
5822 @Override
5823 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005824 if (TextUtils.isEmpty(pkgName))
5825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005826 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5827 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5828 UiccCard card = UiccController.getInstance().getUiccCard(i);
5829 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005830 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005831 continue;
5832 }
5833
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005834 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5835 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5836 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005837 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5838 break;
5839 }
5840 }
5841
5842 return result;
Junda Liu29340342014-07-10 15:23:27 -07005843 }
Derek Tan89e89d42014-07-08 17:00:10 -07005844
5845 @Override
Junda Liue64de782015-04-16 17:19:16 -07005846 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5847 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5848 loge("phoneId " + phoneId + " is not valid.");
5849 return null;
5850 }
5851 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005852 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005853 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005854 return null ;
5855 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005856 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005857 }
5858
Amith Yamasani6e118872016-02-19 12:53:51 -08005859 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005860 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005861 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005862 List<String> privilegedPackages = new ArrayList<>();
5863 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005864 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5865 // has UICC in that slot.
5866 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005867 if (card.hasCarrierPrivilegeRules()) {
5868 if (packages == null) {
5869 // Only check packages in user 0 for now
5870 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005871 PackageManager.MATCH_DISABLED_COMPONENTS
5872 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005873 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005874 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005875 }
5876 for (int p = packages.size() - 1; p >= 0; p--) {
5877 PackageInfo pkgInfo = packages.get(p);
5878 if (pkgInfo != null && pkgInfo.packageName != null
5879 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005880 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005881 privilegedPackages.add(pkgInfo.packageName);
5882 }
5883 }
5884 }
5885 }
5886 return privilegedPackages;
5887 }
5888
chen xuf7e9fe82019-05-09 19:31:02 -07005889 @Override
5890 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005891 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5892
5893 final long identity = Binder.clearCallingIdentity();
5894
chen xuf7e9fe82019-05-09 19:31:02 -07005895 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005896 try {
5897 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5898 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5899 }
5900 } finally {
5901 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005902 }
5903 return privilegedPackages;
5904 }
5905
Wink Savilleb564aae2014-10-23 10:18:09 -07005906 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005907 final Phone phone = getPhone(subId);
5908 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005909 if (card == null) {
5910 loge("getIccId: No UICC");
5911 return null;
5912 }
5913 String iccId = card.getIccId();
5914 if (TextUtils.isEmpty(iccId)) {
5915 loge("getIccId: ICC ID is null or empty.");
5916 return null;
5917 }
5918 return iccId;
5919 }
5920
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005921 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005922 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5923 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005924 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005925 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 final long identity = Binder.clearCallingIdentity();
5928 try {
5929 final String iccId = getIccId(subId);
5930 final Phone phone = getPhone(subId);
5931 if (phone == null) {
5932 return false;
5933 }
5934 final String subscriberId = phone.getSubscriberId();
5935
5936 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005937 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 + subscriberId + " to " + number);
5939 }
5940
5941 if (TextUtils.isEmpty(iccId)) {
5942 return false;
5943 }
5944
5945 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5946
5947 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5948 if (alphaTag == null) {
5949 editor.remove(alphaTagPrefKey);
5950 } else {
5951 editor.putString(alphaTagPrefKey, alphaTag);
5952 }
5953
5954 // Record both the line number and IMSI for this ICCID, since we need to
5955 // track all merged IMSIs based on line number
5956 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5957 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5958 if (number == null) {
5959 editor.remove(numberPrefKey);
5960 editor.remove(subscriberPrefKey);
5961 } else {
5962 editor.putString(numberPrefKey, number);
5963 editor.putString(subscriberPrefKey, subscriberId);
5964 }
5965
5966 editor.commit();
5967 return true;
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005970 }
Derek Tan7226c842014-07-02 17:42:23 -07005971 }
5972
5973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005974 public String getLine1NumberForDisplay(int subId, String callingPackage,
5975 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005976 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005978 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005979 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005980 return null;
5981 }
Derek Tan97ebb422014-09-05 16:55:38 -07005982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 final long identity = Binder.clearCallingIdentity();
5984 try {
5985 String iccId = getIccId(subId);
5986 if (iccId != null) {
5987 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5988 if (DBG_MERGE) {
5989 log("getLine1NumberForDisplay returning "
5990 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5991 }
5992 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5995 return null;
5996 } finally {
5997 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005998 }
Derek Tan7226c842014-07-02 17:42:23 -07005999 }
6000
6001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006002 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6003 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006005 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006006 return null;
6007 }
Derek Tan97ebb422014-09-05 16:55:38 -07006008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 final long identity = Binder.clearCallingIdentity();
6010 try {
6011 String iccId = getIccId(subId);
6012 if (iccId != null) {
6013 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6014 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6015 }
6016 return null;
6017 } finally {
6018 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006019 }
Derek Tan7226c842014-07-02 17:42:23 -07006020 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006021
6022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006023 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6024 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006025 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6026 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006028 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006029 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006030 return null;
6031 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006032
Jordan Liub49b04b2019-05-06 14:45:15 -07006033 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6034 // the process, where TelephonyManager was instantiated.
6035 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006036 final long identity = Binder.clearCallingIdentity();
6037 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006038 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 final TelephonyManager tele = TelephonyManager.from(context);
6040 final SubscriptionManager sub = SubscriptionManager.from(context);
6041
6042 // Figure out what subscribers are currently active
6043 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
Jordan Liub49b04b2019-05-06 14:45:15 -07006045 // Only consider subs which match the current subId
6046 // This logic can be simplified. See b/131189269 for progress.
6047 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006048 activeSubscriberIds.add(tele.getSubscriberId(subId));
6049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050
6051 // First pass, find a number override for an active subscriber
6052 String mergeNumber = null;
6053 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6054 for (String key : prefs.keySet()) {
6055 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6056 final String subscriberId = (String) prefs.get(key);
6057 if (activeSubscriberIds.contains(subscriberId)) {
6058 final String iccId = key.substring(
6059 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6060 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6061 mergeNumber = (String) prefs.get(numberKey);
6062 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006063 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 + " for active subscriber " + subscriberId);
6065 }
6066 if (!TextUtils.isEmpty(mergeNumber)) {
6067 break;
6068 }
6069 }
6070 }
6071 }
6072
6073 // Shortcut when no active merged subscribers
6074 if (TextUtils.isEmpty(mergeNumber)) {
6075 return null;
6076 }
6077
6078 // Second pass, find all subscribers under that line override
6079 final ArraySet<String> result = new ArraySet<>();
6080 for (String key : prefs.keySet()) {
6081 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6082 final String number = (String) prefs.get(key);
6083 if (mergeNumber.equals(number)) {
6084 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6085 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6086 final String subscriberId = (String) prefs.get(subscriberKey);
6087 if (!TextUtils.isEmpty(subscriberId)) {
6088 result.add(subscriberId);
6089 }
6090 }
6091 }
6092 }
6093
6094 final String[] resultArray = result.toArray(new String[result.size()]);
6095 Arrays.sort(resultArray);
6096 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006097 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6099 }
6100 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006103 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006104 }
6105
6106 @Override
zoey chen38003472019-12-13 17:16:31 +08006107 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6108 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 final TelephonyManager telephonyManager = mApp.getSystemService(
6113 TelephonyManager.class);
6114 String subscriberId = telephonyManager.getSubscriberId(subId);
6115 if (subscriberId == null) {
6116 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006117 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006118 + subId);
6119 }
6120 return null;
6121 }
6122
6123 final SubscriptionInfo info = SubscriptionController.getInstance()
6124 .getSubscriptionInfo(subId);
6125 final ParcelUuid groupUuid = info.getGroupUuid();
6126 // If it doesn't belong to any group, return just subscriberId of itself.
6127 if (groupUuid == null) {
6128 return new String[]{subscriberId};
6129 }
6130
6131 // Get all subscriberIds from the group.
6132 final List<String> mergedSubscriberIds = new ArrayList<>();
6133 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006134 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6135 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006136 for (SubscriptionInfo subInfo : groupInfos) {
6137 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6138 if (subscriberId != null) {
6139 mergedSubscriberIds.add(subscriberId);
6140 }
6141 }
6142
6143 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146
6147 }
6148 }
6149
6150 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006151 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006152 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006153 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154
6155 final long identity = Binder.clearCallingIdentity();
6156 try {
6157 final Phone phone = getPhone(subId);
6158 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006162 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006163
6164 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006165 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006166 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6167 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006168 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6169 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170
6171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 final Phone phone = getPhone(subId);
6174 if (phone == null) {
6175 return false;
6176 }
6177 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6178 cdmaNonRoamingList);
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006181 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006182 }
6183
6184 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006185 @Deprecated
6186 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6187 enforceModifyPermission();
6188
6189 int returnValue = 0;
6190 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006191 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006192 if(result.exception == null) {
6193 if (result.result != null) {
6194 byte[] responseData = (byte[])(result.result);
6195 if(responseData.length > oemResp.length) {
6196 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6197 responseData.length + "bytes. Buffer Size is " +
6198 oemResp.length + "bytes.");
6199 }
6200 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6201 returnValue = responseData.length;
6202 }
6203 } else {
6204 CommandException ex = (CommandException) result.exception;
6205 returnValue = ex.getCommandError().ordinal();
6206 if(returnValue > 0) returnValue *= -1;
6207 }
6208 } catch (RuntimeException e) {
6209 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6210 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6211 if(returnValue > 0) returnValue *= -1;
6212 }
6213
6214 return returnValue;
6215 }
6216
6217 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006218 public void setRadioCapability(RadioAccessFamily[] rafs) {
6219 try {
6220 ProxyController.getInstance().setRadioCapability(rafs);
6221 } catch (RuntimeException e) {
6222 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6223 }
6224 }
6225
6226 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006227 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006228 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006229 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006230 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006231 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 final long identity = Binder.clearCallingIdentity();
6234 try {
chen xub97461a2018-10-26 14:17:57 -07006235 TelephonyPermissions
6236 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6237 mApp, phone.getSubId(), "getRadioAccessFamily");
6238 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
chen xub97461a2018-10-26 14:17:57 -07006242 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006243 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006244
6245 @Override
6246 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006247 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006252 ImsManager.getInstance(defaultPhone.getContext(),
6253 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006257 }
6258
6259 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006260 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006261 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6263 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006264 return false;
6265 }
Svet Ganovb320e182015-04-16 12:30:10 -07006266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 // Check the user preference and the system-level IMS setting. Even if the user has
6270 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6271 // In the long run, we may instead need to check if there exists a connection service
6272 // which can support video calling.
6273 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006274 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 return imsManager.isVtEnabledByPlatform()
6276 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6277 && imsManager.isVtEnabledByUser();
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006281 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006282
Andrew Leea1239f22015-03-02 17:44:07 -08006283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006284 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6285 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006287 mApp, subId, callingPackage, callingFeatureId,
6288 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 return false;
6290 }
6291
6292 final long identity = Binder.clearCallingIdentity();
6293 try {
6294 CarrierConfigManager configManager =
6295 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006296 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
Andrew Leea1239f22015-03-02 17:44:07 -08006301 }
6302
6303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006304 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006306 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 return false;
6308 }
6309
6310 final long identity = Binder.clearCallingIdentity();
6311 try {
6312 CarrierConfigManager configManager =
6313 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006314 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
Andrew Leea1239f22015-03-02 17:44:07 -08006319 }
6320
Andrew Lee9431b832015-03-09 18:46:45 -07006321 @Override
6322 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006323 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006324 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006325 }
6326
6327 @Override
6328 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 final long identity = Binder.clearCallingIdentity();
6330 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
Andrew Lee9431b832015-03-09 18:46:45 -07006335 }
6336
Hall Liuf6668912018-10-31 17:05:23 -07006337 /**
6338 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6339 * support for the feature and device firmware support.
6340 *
6341 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6342 */
6343 @Override
6344 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006346 final Phone phone = getPhone(subscriptionId);
6347 if (phone == null) {
6348 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6349 return false;
6350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006352 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6354 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006355 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 return isCarrierSupported && isDeviceSupported;
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
Hall Liu98187582018-01-22 19:15:32 -08006360 }
6361
Hall Liuf6668912018-10-31 17:05:23 -07006362 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006363 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6364 * RTT setting, will return true if the device and carrier both support RTT.
6365 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006366 */
6367 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 final long identity = Binder.clearCallingIdentity();
6369 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006370 boolean isRttSupported = isRttSupported(subscriptionId);
6371 boolean isUserRttSettingOn = Settings.Secure.getInt(
6372 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6373 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6374 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6375 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006379 }
6380
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006381 @Deprecated
6382 @Override
6383 public String getDeviceId(String callingPackage) {
6384 return getDeviceIdWithFeature(callingPackage, null);
6385 }
6386
Sanket Padawe7310cc72015-01-14 09:53:20 -08006387 /**
6388 * Returns the unique device ID of phone, for example, the IMEI for
6389 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6390 *
6391 * <p>Requires Permission:
6392 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6393 */
6394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006395 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006396 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006397 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006398 return null;
6399 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006400 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006401 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006402 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006403 return null;
6404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 return phone.getDeviceId();
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006412 }
6413
Ping Sunc67b7c22016-03-02 19:16:45 +08006414 /**
6415 * {@hide}
6416 * Returns the IMS Registration Status on a particular subid
6417 *
6418 * @param subId
6419 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006420 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006421 Phone phone = getPhone(subId);
6422 if (phone != null) {
6423 return phone.isImsRegistered();
6424 } else {
6425 return false;
6426 }
6427 }
6428
Santos Cordon7a1885b2015-02-03 11:15:19 -08006429 @Override
6430 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431 final long identity = Binder.clearCallingIdentity();
6432 try {
6433 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006437 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006438
Tyler Gunnf70ed162019-04-03 15:28:53 -07006439 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006440 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006441 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006443 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006444 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6445 }
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
6453
6454 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006455 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6456 final long identity = Binder.clearCallingIdentity();
6457 try {
6458 Phone phone = getPhone(subscriptionId);
6459 if (phone == null) {
6460 return null;
6461 }
6462 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006468 /**
6469 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006470 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006471 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 Phone phone = getPhone(subId);
6475 if (phone != null) {
6476 return phone.isWifiCallingEnabled();
6477 } else {
6478 return false;
6479 }
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006482 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006483 }
6484
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006485 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006486 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006487 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006488 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 Phone phone = getPhone(subId);
6492 if (phone != null) {
6493 return phone.isVideoEnabled();
6494 } else {
6495 return false;
6496 }
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006499 }
6500 }
6501
6502 /**
6503 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6504 * defined in {@link ImsRegistrationImplBase}.
6505 */
6506 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507 final long identity = Binder.clearCallingIdentity();
6508 try {
6509 Phone phone = getPhone(subId);
6510 if (phone != null) {
6511 return phone.getImsRegistrationTech();
6512 } else {
6513 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6514 }
6515 } finally {
6516 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006517 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006518 }
6519
Stuart Scott8eef64f2015-04-08 15:13:54 -07006520 @Override
6521 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006522 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006523 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6524 return;
6525 }
6526
Svet Ganovcc087f82015-05-12 20:35:54 -07006527 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006528
Svet Ganovcc087f82015-05-12 20:35:54 -07006529 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006530 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6531 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006532 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006533 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006534 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006535 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6536 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006537 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006538 // There has been issues when Sms raw table somehow stores orphan
6539 // fragments. They lead to garbled message when new fragments come
6540 // in and combined with those stale ones. In case this happens again,
6541 // user can reset all network settings which will clean up this table.
6542 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006543 // Clean up IMS settings as well here.
6544 int slotId = getSlotIndex(subId);
6545 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6546 ImsManager.getInstance(mApp, slotId).factoryReset();
6547 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006548
6549 // Erase modem config if erase modem on network setting is enabled.
6550 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6551 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6552 if (configValue != null && Boolean.parseBoolean(configValue)) {
6553 sendEraseModemConfig(getDefaultPhone());
6554 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006555 } finally {
6556 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006557 }
6558 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006559
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006560 private void cleanUpSmsRawTable(Context context) {
6561 ContentResolver resolver = context.getContentResolver();
6562 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6563 resolver.delete(uri, null, null);
6564 }
6565
Narayan Kamath1c496c22015-04-16 14:40:19 +01006566 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006567 public String getSimLocaleForSubscriber(int subId) {
6568 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6569 final Phone phone = getPhone(subId);
6570 if (phone == null) {
6571 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006572 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 final long identity = Binder.clearCallingIdentity();
6575 try {
chen xu5d3637b2019-01-21 23:31:38 -08006576 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006577 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006578 if (info == null) {
6579 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6580 return null;
6581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 // Try and fetch the locale from the carrier properties or from the SIM language
6583 // preferences (EF-PL and EF-LI)...
6584 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006586 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6587 if (localeFromDefaultSim != null) {
6588 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6589 if (DBG) log("Using locale from subId: " + subId + " locale: "
6590 + localeFromDefaultSim);
6591 return localeFromDefaultSim.toLanguageTag();
6592 } else {
6593 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 }
6595 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 // The SIM language preferences only store a language (e.g. fr = French), not an
6598 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6599 // the SIM and carrier preferences does not include a country we add the country
6600 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006601 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006603 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 return mccLocale.toLanguageTag();
6605 }
6606
6607 if (DBG) log("No locale found - returning null");
6608 return null;
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006612 }
6613
6614 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006615 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6616 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006617 }
6618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 /**
6620 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6621 */
6622 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006623 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6624 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006625 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006626
Chenjie Yu1ba97252018-01-11 18:16:20 -08006627 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006628 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006629
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006630 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006631 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6632 * representing the state of the modem.
6633 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006634 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6635 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006636 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006637 */
6638 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006639 public void requestModemActivityInfo(ResultReceiver result) {
6640 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006641 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642
6643 final long identity = Binder.clearCallingIdentity();
6644 try {
6645 ModemActivityInfo ret = null;
6646 synchronized (mLastModemActivityInfo) {
6647 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6648 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006649 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006650 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006652 int[] txTimeMs = info.getTransmitTimeMillis();
6653 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006655 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 }
6657 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006658 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6659 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 mLastModemActivityInfo.setIdleTimeMillis(
6661 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006662 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6663 mLastModemActivityInfo.setReceiveTimeMillis(
6664 info.getReceiveTimeMillis() + mLastModemActivityInfo
6665 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006666 }
Chen Xud78231e2019-09-10 18:49:52 -07006667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6669 mLastModemActivityInfo.getSleepTimeMillis(),
6670 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006671 mLastModemActivityInfo.getTransmitTimeMillis(),
6672 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 Bundle bundle = new Bundle();
6675 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6676 result.send(0, bundle);
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006679 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006680 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006681
Siddharth Rayb8114062018-06-17 15:02:38 -07006682 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6683 // less than total activity duration.
6684 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6685 if (info == null) {
6686 return false;
6687 }
6688 int activityDurationMs =
6689 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6690 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006691 int[] txTimeMs = info.getTransmitTimeMillis();
6692 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6693 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006694 }
6695 return (info.isValid()
6696 && (info.getSleepTimeMillis() <= activityDurationMs)
6697 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006698 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006699 && (totalTxTimeMs <= activityDurationMs));
6700 }
6701
Jack Yu85bd38a2015-11-09 11:34:32 -08006702 /**
6703 * {@hide}
6704 * Returns the service state information on specified subscription.
6705 */
6706 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006707 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006710 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006711 return null;
6712 }
6713
Hall Liuf19c44f2018-11-27 14:38:17 -08006714 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6715 LocationAccessPolicy.checkLocationPermission(mApp,
6716 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6717 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006718 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006719 .setCallingPid(Binder.getCallingPid())
6720 .setCallingUid(Binder.getCallingUid())
6721 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006722 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006723 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6724 .build());
6725
6726 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6727 LocationAccessPolicy.checkLocationPermission(mApp,
6728 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6729 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006730 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006731 .setCallingPid(Binder.getCallingPid())
6732 .setCallingUid(Binder.getCallingUid())
6733 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006734 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006735 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6736 .build());
6737 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6738 boolean hasFinePermission =
6739 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6740 boolean hasCoarsePermission =
6741 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 final Phone phone = getPhone(subId);
6746 if (phone == null) {
6747 return null;
6748 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006749
Hall Liuf19c44f2018-11-27 14:38:17 -08006750 ServiceState ss = phone.getServiceState();
6751
6752 // Scrub out the location info in ServiceState depending on what level of access
6753 // the caller has.
6754 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006755 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6756 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006760 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006761
6762 /**
6763 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6764 *
6765 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6766 * voicemail ringtone.
6767 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6768 * PhoneAccount.
6769 */
6770 @Override
6771 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 final long identity = Binder.clearCallingIdentity();
6773 try {
6774 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6775 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006776 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006783 }
6784
6785 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006786 * Sets the per-account voicemail ringtone.
6787 *
6788 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6789 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6790 *
6791 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6792 * voicemail ringtone.
6793 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6794 * PhoneAccount.
6795 */
6796 @Override
6797 public void setVoicemailRingtoneUri(String callingPackage,
6798 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006799 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006801 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6802 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6804 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6805 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6811 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006812 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 }
6814 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006817 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006818 }
6819
6820 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006821 * Returns whether vibration is set for voicemail notification in Phone settings.
6822 *
6823 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6824 * voicemail vibration setting.
6825 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6826 */
6827 @Override
6828 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 final long identity = Binder.clearCallingIdentity();
6830 try {
6831 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6832 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006833 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6837 } finally {
6838 Binder.restoreCallingIdentity(identity);
6839 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006840 }
6841
Youhan Wange64578a2016-05-02 15:32:42 -07006842 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006843 * Sets the per-account voicemail vibration.
6844 *
6845 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6846 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6847 *
6848 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6849 * voicemail vibration setting.
6850 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6851 * specific PhoneAccount.
6852 */
6853 @Override
6854 public void setVoicemailVibrationEnabled(String callingPackage,
6855 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006856 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006857 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006858 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6859 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6861 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6862 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006863 }
6864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6868 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006869 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 }
6871 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006874 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006875 }
6876
6877 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006878 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6879 *
6880 * @throws SecurityException if the caller does not have the required permission
6881 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006882 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006883 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006884 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006885 }
6886
6887 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006888 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6889 * permission.
6890 *
6891 * @throws SecurityException if the caller does not have the required permission
6892 */
6893 private void enforceSendSmsPermission() {
6894 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6895 }
6896
6897 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006898 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006899 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006900 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006901 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006902 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 final long identity = Binder.clearCallingIdentity();
6904 try {
6905 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006906 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 if (componentName == null) {
6908 throw new SecurityException(
6909 "Caller not current active visual voicemail package[null]");
6910 }
6911 String vvmPackage = componentName.getPackageName();
6912 if (!callingPackage.equals(vvmPackage)) {
6913 throw new SecurityException("Caller not current active visual voicemail package["
6914 + vvmPackage + "]");
6915 }
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006918 }
6919 }
6920
6921 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006922 * Return the application ID for the app type.
6923 *
6924 * @param subId the subscription ID that this request applies to.
6925 * @param appType the uicc app type.
6926 * @return Application ID for specificied app type, or null if no uicc.
6927 */
6928 @Override
6929 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006930 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006931 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932
6933 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006934 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935 if (phone == null) {
6936 return null;
6937 }
6938 String aid = null;
6939 try {
6940 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6941 .getApplicationByType(appType).getAid();
6942 } catch (Exception e) {
6943 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6944 }
6945 return aid;
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006948 }
Youhan Wange64578a2016-05-02 15:32:42 -07006949 }
6950
Youhan Wang4001d252016-05-11 10:29:41 -07006951 /**
6952 * Return the Electronic Serial Number.
6953 *
6954 * @param subId the subscription ID that this request applies to.
6955 * @return ESN or null if error.
6956 */
6957 @Override
6958 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006959 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006960 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961
6962 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006963 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 if (phone == null) {
6965 return null;
6966 }
6967 String esn = null;
6968 try {
6969 esn = phone.getEsn();
6970 } catch (Exception e) {
6971 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6972 }
6973 return esn;
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006976 }
Youhan Wang4001d252016-05-11 10:29:41 -07006977 }
6978
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006979 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006980 * Return the Preferred Roaming List Version.
6981 *
6982 * @param subId the subscription ID that this request applies to.
6983 * @return PRLVersion or null if error.
6984 */
6985 @Override
6986 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006987 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006988 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989
6990 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006991 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 if (phone == null) {
6993 return null;
6994 }
6995 String cdmaPrlVersion = null;
6996 try {
6997 cdmaPrlVersion = phone.getCdmaPrlVersion();
6998 } catch (Exception e) {
6999 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7000 }
7001 return cdmaPrlVersion;
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007004 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007005 }
7006
7007 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007008 * Get snapshot of Telephony histograms
7009 * @return List of Telephony histograms
7010 * @hide
7011 */
7012 @Override
7013 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7015 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 return RIL.getTelephonyRILTimingHistograms();
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007023 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007024
7025 /**
7026 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007027 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7028 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007029 * Require system privileges. In the future we may add this to carrier APIs.
7030 *
Michele Berionne482f8202018-11-27 18:57:59 -08007031 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007032 */
7033 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007034 @TelephonyManager.SetCarrierRestrictionResult
7035 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007036 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007038
Michele Berionne482f8202018-11-27 18:57:59 -08007039 if (carrierRestrictionRules == null) {
7040 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007041 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 final long identity = Binder.clearCallingIdentity();
7044 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007045 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007046 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007050 }
7051
7052 /**
7053 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007054 * Get the allowed carrier list and the excluded carrier list, including the priority between
7055 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007056 * Require system privileges. In the future we may add this to carrier APIs.
7057 *
Michele Berionne482f8202018-11-27 18:57:59 -08007058 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007059 */
7060 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007061 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007062 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007067 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7068 if (response instanceof CarrierRestrictionRules) {
7069 return (CarrierRestrictionRules) response;
7070 }
7071 // Response is an Exception of some kind,
7072 // which is signalled to the user as a NULL retval
7073 return null;
7074 } catch (Exception e) {
7075 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7076 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007080 }
7081
fionaxu59545b42016-05-25 15:53:37 -07007082 /**
7083 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7084 * @param subId the subscription ID that this action applies to.
7085 * @param enabled control enable or disable metered apns.
7086 * {@hide}
7087 */
7088 @Override
7089 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7090 enforceModifyPermission();
7091 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092
7093 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007094 if (phone == null) {
7095 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7096 return;
7097 }
7098 try {
7099 phone.carrierActionSetMeteredApnsEnabled(enabled);
7100 } catch (Exception e) {
7101 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 } finally {
7103 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007104 }
7105 }
7106
7107 /**
7108 * Action set from carrier signalling broadcast receivers to enable/disable radio
7109 * @param subId the subscription ID that this action applies to.
7110 * @param enabled control enable or disable radio.
7111 * {@hide}
7112 */
7113 @Override
7114 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7115 enforceModifyPermission();
7116 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117
7118 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007119 if (phone == null) {
7120 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7121 return;
7122 }
7123 try {
7124 phone.carrierActionSetRadioEnabled(enabled);
7125 } catch (Exception e) {
7126 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 } finally {
7128 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007129 }
7130 }
7131
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007132 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007133 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7134 * network status based on which carrier apps could apply actions accordingly,
7135 * enable/disable default url handler for example.
7136 *
7137 * @param subId the subscription ID that this action applies to.
7138 * @param report control start/stop reporting the default network status.
7139 * {@hide}
7140 */
7141 @Override
7142 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7143 enforceModifyPermission();
7144 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145
7146 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007147 if (phone == null) {
7148 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7149 return;
7150 }
7151 try {
7152 phone.carrierActionReportDefaultNetworkStatus(report);
7153 } catch (Exception e) {
7154 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 } finally {
7156 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007157 }
7158 }
7159
7160 /**
fionaxud9622282017-07-17 17:51:30 -07007161 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7162 * @param subId the subscription ID that this action applies to.
7163 * {@hide}
7164 */
7165 @Override
7166 public void carrierActionResetAll(int subId) {
7167 enforceModifyPermission();
7168 final Phone phone = getPhone(subId);
7169 if (phone == null) {
7170 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7171 return;
7172 }
7173 try {
7174 phone.carrierActionResetAll();
7175 } catch (Exception e) {
7176 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7177 }
7178 }
7179
7180 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007181 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7182 * bug report is being generated.
7183 */
7184 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007185 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007186 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7187 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007188 writer.println("Permission Denial: can't dump Phone from pid="
7189 + Binder.getCallingPid()
7190 + ", uid=" + Binder.getCallingUid()
7191 + "without permission "
7192 + android.Manifest.permission.DUMP);
7193 return;
7194 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007195 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007196 }
Jack Yueb89b242016-06-22 13:27:47 -07007197
Brad Ebingerdac2f002018-04-03 15:17:52 -07007198 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007199 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7200 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7201 @NonNull String[] args) {
7202 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7203 this, in.getFileDescriptor(), out.getFileDescriptor(),
7204 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007205 }
7206
Jack Yueb89b242016-06-22 13:27:47 -07007207 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007208 * Policy control of data connection. Usually used when data limit is passed.
7209 * @param enabled True if enabling the data, otherwise disabling.
7210 * @param subId Subscription index
7211 * {@hide}
7212 */
7213 @Override
7214 public void setPolicyDataEnabled(boolean enabled, int subId) {
7215 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216
7217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 Phone phone = getPhone(subId);
7220 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007221 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 }
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007225 }
7226 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007227
7228 /**
7229 * Get Client request stats
7230 * @return List of Client Request Stats
7231 * @hide
7232 */
7233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007234 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7235 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007237 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007238 return null;
7239 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007240 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 if (phone != null) {
7245 return phone.getClientRequestStats();
7246 }
7247
7248 return null;
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007252 }
7253
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007254 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007255 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007256 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007257 }
Jack Yueb4124c2017-02-16 15:32:43 -08007258
7259 /**
Grace Chen70990072017-03-24 17:21:30 -07007260 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007261 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007262 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007263 * @param state State of SIM (power down, power up, pass through)
7264 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7265 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7266 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007267 *
7268 **/
7269 @Override
Grace Chen70990072017-03-24 17:21:30 -07007270 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007271 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007272 Phone phone = PhoneFactory.getPhone(slotIndex);
7273
vagdeviaf9a5b92018-08-15 16:01:53 -07007274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276 final long identity = Binder.clearCallingIdentity();
7277 try {
7278 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007279 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 }
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007283 }
7284 }
Shuo Qiandd210312017-04-12 22:11:33 +00007285
Tyler Gunn65d45c22017-06-05 11:22:26 -07007286 private boolean isUssdApiAllowed(int subId) {
7287 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007288 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007289 if (configManager == null) {
7290 return false;
7291 }
7292 PersistableBundle pb = configManager.getConfigForSubId(subId);
7293 if (pb == null) {
7294 return false;
7295 }
7296 return pb.getBoolean(
7297 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7298 }
7299
Shuo Qiandd210312017-04-12 22:11:33 +00007300 /**
7301 * Check if phone is in emergency callback mode
7302 * @return true if phone is in emergency callback mode
7303 * @param subId sub id
7304 */
goneil9c5f4872017-12-05 14:07:56 -08007305 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007306 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007307 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007308 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 if (phone != null) {
7313 return phone.isInEcm();
7314 } else {
7315 return false;
7316 }
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007319 }
7320 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007321
7322 /**
7323 * Get the current signal strength information for the given subscription.
7324 * Because this information is not updated when the device is in a low power state
7325 * it should not be relied-upon to be current.
7326 * @param subId Subscription index
7327 * @return the most recent cached signal strength info from the modem
7328 */
7329 @Override
7330 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007331 final long identity = Binder.clearCallingIdentity();
7332 try {
7333 Phone p = getPhone(subId);
7334 if (p == null) {
7335 return null;
7336 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 return p.getSignalStrength();
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007342 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007343
Pengquan Meng77b7f132018-08-22 14:49:57 -07007344 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007345 * Get the current modem radio state for the given slot.
7346 * @param slotIndex slot index.
7347 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007348 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007349 * @return the current radio power state from the modem
7350 */
7351 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007352 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007353 Phone phone = PhoneFactory.getPhone(slotIndex);
7354 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7356 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007357 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7358 }
7359
7360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 return phone.getRadioPowerState();
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
7366 }
7367 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7368 }
7369
7370 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007371 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7372 *
7373 * <p>Requires one of the following permissions:
7374 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7375 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7376 * privileges.
7377 *
7378 * @param subId subscription id
7379 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7380 * {@code false}.
7381 */
7382 @Override
7383 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007384 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7385 null /* message */);
7386
Pengquan Menga1bb6272018-09-06 09:59:22 -07007387 boolean isEnabled = false;
7388 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007389 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007390 Phone phone = getPhone(subId);
7391 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007392 } catch (Exception e) {
7393 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7394 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007395 } finally {
7396 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007397 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007398 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007399 }
7400
7401
7402 /**
7403 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7404 *
7405 * <p> Requires permission:
7406 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7407 * privileges.
7408 *
7409 * @param subId subscription id
7410 * @param isEnabled {@code true} means enable, {@code false} means disable.
7411 */
7412 @Override
7413 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7415 mApp, subId, "setDataRoamingEnabled");
7416
Pengquan Menga1bb6272018-09-06 09:59:22 -07007417 final long identity = Binder.clearCallingIdentity();
7418 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007419 Phone phone = getPhone(subId);
7420 if (phone != null) {
7421 phone.setDataRoamingEnabled(isEnabled);
7422 }
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007425 }
7426 }
7427
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007428 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007429 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007430 TelephonyPermissions
7431 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007432 mApp, subId, "isManualNetworkSelectionAllowed");
7433
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007434 boolean isAllowed = true;
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007437 Phone phone = getPhone(subId);
7438 if (phone != null) {
7439 isAllowed = phone.isCspPlmnEnabled();
7440 }
7441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
7444 return isAllowed;
7445 }
7446
7447 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007448 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007449 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007450 try {
7451 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007452 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007453 } catch (SecurityException e) {
7454 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7455 // has carrier privileges on an active UICC
7456 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7457 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007458 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007459 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007460 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007461
7462 final long identity = Binder.clearCallingIdentity();
7463 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007464 UiccController uiccController = UiccController.getInstance();
7465 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007466 if (hasReadPermission) {
7467 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007468 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007469
7470 // Remove private info if the caller doesn't have access
7471 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7472 for (UiccCardInfo cardInfo : cardInfos) {
7473 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7474 // is available
7475 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7476 if (card == null || card.getUiccProfile() == null) {
7477 // assume no access if the card or profile is unavailable
7478 filteredInfos.add(cardInfo.getUnprivileged());
7479 continue;
7480 }
7481 UiccProfile profile = card.getUiccProfile();
7482 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7483 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7484 filteredInfos.add(cardInfo);
7485 } else {
7486 filteredInfos.add(cardInfo.getUnprivileged());
7487 }
7488 }
7489 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
7493 }
7494
7495 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007496 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007497 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7502 if (slots == null) {
7503 Rlog.i(LOG_TAG, "slots is null.");
7504 return null;
7505 }
7506
7507 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7508 for (int i = 0; i < slots.length; i++) {
7509 UiccSlot slot = slots[i];
7510 if (slot == null) {
7511 continue;
7512 }
7513
Jordan Liu7be7e652019-05-06 18:55:02 +00007514 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 UiccCard card = slot.getUiccCard();
7516 if (card != null) {
7517 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007518 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007519 cardId = slot.getEid();
7520 if (TextUtils.isEmpty(cardId)) {
7521 cardId = slot.getIccId();
7522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 }
7524
Jordan Liu857451f2019-05-09 16:35:35 -07007525 if (cardId != null) {
7526 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7527 // if cardId is an EID, it's all digits so this is fine
7528 cardId = IccUtils.stripTrailingFs(cardId);
7529 }
7530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 int cardState = 0;
7532 switch (slot.getCardState()) {
7533 case CARDSTATE_ABSENT:
7534 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7535 break;
7536 case CARDSTATE_PRESENT:
7537 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7538 break;
7539 case CARDSTATE_ERROR:
7540 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7541 break;
7542 case CARDSTATE_RESTRICTED:
7543 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7544 break;
7545 default:
7546 break;
7547
7548 }
7549
7550 infos[i] = new UiccSlotInfo(
7551 slot.isActive(),
7552 slot.isEuicc(),
7553 cardId,
7554 cardState,
7555 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007556 slot.isExtendedApduSupported(),
7557 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 }
7559 return infos;
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007562 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007563 }
7564
7565 @Override
7566 public boolean switchSlots(int[] physicalSlots) {
7567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007575 }
Jack Yu4c988042018-02-27 15:30:01 -08007576
7577 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007578 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 return UiccController.getInstance().getCardIdForDefaultEuicc();
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
7586
Pengquan Meng85728fb2018-03-12 16:31:21 -07007587 /**
goneil47ffb6e2018-04-06 15:40:58 -07007588 * A test API to reload the UICC profile.
7589 *
7590 * <p>Requires that the calling app has permission
7591 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7592 * @hide
7593 */
7594 @Override
7595 public void refreshUiccProfile(int subId) {
7596 enforceModifyPermission();
7597
7598 final long identity = Binder.clearCallingIdentity();
7599 try {
7600 Phone phone = getPhone(subId);
7601 if (phone == null) {
7602 return;
7603 }
7604 UiccCard uiccCard = phone.getUiccCard();
7605 if (uiccCard == null) {
7606 return;
7607 }
7608 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7609 if (uiccProfile == null) {
7610 return;
7611 }
7612 uiccProfile.refresh();
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
7616 }
7617
7618 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007619 * Returns false if the mobile data is disabled by default, otherwise return true.
7620 */
7621 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007622 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007623 }
7624
7625 /**
7626 * Returns true if the data roaming is enabled by default, i.e the system property
7627 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7628 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7629 */
7630 private boolean getDefaultDataRoamingEnabled(int subId) {
7631 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007632 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007633 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007634 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7635 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7636 return isDataRoamingEnabled;
7637 }
7638
7639 /**
7640 * Returns the default network type for the given {@code subId}, if the default network type is
7641 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7642 */
7643 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007644 List<Integer> list = TelephonyProperties.default_network();
7645 int phoneId = mSubscriptionController.getPhoneId(subId);
7646 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7647 return list.get(phoneId);
7648 }
7649 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007650 }
fionaxua13278b2018-03-21 00:08:13 -07007651
7652 @Override
7653 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007654 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656
7657 final long identity = Binder.clearCallingIdentity();
7658 try {
7659 final Phone phone = getPhone(subId);
7660 if (phone == null) {
7661 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7662 return;
7663 }
chen xueaba88a2019-03-15 13:15:10 -07007664 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7665 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 } finally {
7667 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007668 }
fionaxua13278b2018-03-21 00:08:13 -07007669 }
7670
7671 @Override
7672 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007673 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 final Phone phone = getPhone(subId);
7678 if (phone == null) {
7679 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7680 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7681 }
7682 return phone.getCarrierIdListVersion();
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007685 }
fionaxua13278b2018-03-21 00:08:13 -07007686 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007687
7688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007689 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7690 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007692 mApp, subId, callingPackage, callingFeatureId,
7693 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007694 return -1;
7695 }
7696
7697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007704
7705 @Override
7706 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007707 TelephonyPermissions
7708 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007709 mApp, subId, "getCdmaRoamingMode");
7710
7711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 }
7718
7719 @Override
7720 public boolean setCdmaRoamingMode(int subId, int mode) {
7721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7722 mApp, subId, "setCdmaRoamingMode");
7723
7724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
7729 }
7730 }
7731
7732 @Override
7733 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7735 mApp, subId, "setCdmaSubscriptionMode");
7736
7737 final long identity = Binder.clearCallingIdentity();
7738 try {
7739 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7740 } finally {
7741 Binder.restoreCallingIdentity(identity);
7742 }
7743 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007744
sqianc5eccab2018-10-19 18:46:41 -07007745 @Override
sqian8c685422019-02-22 15:55:18 -08007746 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007747 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007749 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7750 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007751 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7752 }
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
sqian854d44b2018-12-12 16:48:18 -08007755 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7756 for (Phone phone: PhoneFactory.getPhones()) {
7757 if (phone.getEmergencyNumberTracker() != null
7758 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7759 emergencyNumberListInternal.put(
7760 phone.getSubId(),
7761 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7762 }
sqian11b7a0e2018-12-05 18:48:28 -08007763 }
sqian854d44b2018-12-12 16:48:18 -08007764 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
sqianc5eccab2018-10-19 18:46:41 -07007768 }
7769
7770 @Override
sqian8c685422019-02-22 15:55:18 -08007771 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007772 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007773 if (!exactMatch) {
7774 TelephonyPermissions
7775 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007776 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007777 }
7778 final long identity = Binder.clearCallingIdentity();
7779 try {
sqian854d44b2018-12-12 16:48:18 -08007780 for (Phone phone: PhoneFactory.getPhones()) {
7781 if (phone.getEmergencyNumberTracker() != null
7782 && phone.getEmergencyNumberTracker() != null) {
7783 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7784 number, exactMatch)) {
7785 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007786 }
7787 }
sqian11b7a0e2018-12-05 18:48:28 -08007788 }
7789 return false;
7790 } finally {
7791 Binder.restoreCallingIdentity(identity);
7792 }
7793 }
7794
sqianf4ca7ed2019-01-15 18:32:07 -08007795 /**
7796 * Update emergency number list for test mode.
7797 */
7798 @Override
7799 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7800 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7801 "updateEmergencyNumberListTestMode");
7802
7803 final long identity = Binder.clearCallingIdentity();
7804 try {
7805 for (Phone phone: PhoneFactory.getPhones()) {
7806 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7807 if (tracker != null) {
7808 tracker.executeEmergencyNumberTestModeCommand(action, num);
7809 }
7810 }
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
7813 }
7814 }
7815
7816 /**
7817 * Get the full emergency number list for test mode.
7818 */
7819 @Override
7820 public List<String> getEmergencyNumberListTestMode() {
7821 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7822 "getEmergencyNumberListTestMode");
7823
7824 final long identity = Binder.clearCallingIdentity();
7825 try {
7826 Set<String> emergencyNumbers = new HashSet<>();
7827 for (Phone phone: PhoneFactory.getPhones()) {
7828 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7829 if (tracker != null) {
7830 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7831 emergencyNumbers.add(num.getNumber());
7832 }
7833 }
7834 }
7835 return new ArrayList<>(emergencyNumbers);
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
7838 }
7839 }
7840
chen xud6b45bd2018-10-30 22:27:10 -07007841 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007842 public int getEmergencyNumberDbVersion(int subId) {
7843 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7844
7845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 final Phone phone = getPhone(subId);
7848 if (phone == null) {
7849 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7850 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7851 }
7852 return phone.getEmergencyNumberDbVersion();
7853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
7856 }
7857
7858 @Override
7859 public void notifyOtaEmergencyNumberDbInstalled() {
7860 enforceModifyPermission();
7861
7862 final long identity = Binder.clearCallingIdentity();
7863 try {
7864 for (Phone phone: PhoneFactory.getPhones()) {
7865 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7866 if (tracker != null) {
7867 tracker.updateOtaEmergencyNumberDatabase();
7868 }
7869 }
7870 } finally {
7871 Binder.restoreCallingIdentity(identity);
7872 }
7873 }
7874
7875 @Override
7876 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7877 enforceActiveEmergencySessionPermission();
7878
7879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 for (Phone phone: PhoneFactory.getPhones()) {
7882 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7883 if (tracker != null) {
7884 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7885 }
7886 }
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
7889 }
7890 }
7891
7892 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007893 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7894 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7895 Phone phone = getPhone(subId);
7896 if (phone == null) {
7897 return null;
7898 }
7899 final long identity = Binder.clearCallingIdentity();
7900 try {
7901 UiccProfile profile = UiccController.getInstance()
7902 .getUiccProfileForPhone(phone.getPhoneId());
7903 if (profile != null) {
7904 return profile.getCertsFromCarrierPrivilegeAccessRules();
7905 }
7906 } finally {
7907 Binder.restoreCallingIdentity(identity);
7908 }
7909 return null;
7910 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007911
7912 /**
7913 * Enable or disable a modem stack.
7914 */
7915 @Override
7916 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7917 enforceModifyPermission();
7918
7919 final long identity = Binder.clearCallingIdentity();
7920 try {
7921 Phone phone = PhoneFactory.getPhone(slotIndex);
7922 if (phone == null) {
7923 return false;
7924 } else {
7925 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7926 }
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
7929 }
7930 }
Michelecea4cf22018-12-21 15:00:11 -08007931
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007932 /**
7933 * Whether a modem stack is enabled or not.
7934 */
7935 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007936 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7937 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007938 Phone phone = PhoneFactory.getPhone(slotIndex);
7939 if (phone == null) return false;
7940
7941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007942 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7943 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007944 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7945 }
7946
7947 final long identity = Binder.clearCallingIdentity();
7948 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007949 try {
7950 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7951 } catch (NoSuchElementException ex) {
7952 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7953 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007954 } finally {
7955 Binder.restoreCallingIdentity(identity);
7956 }
7957 }
7958
Michelecea4cf22018-12-21 15:00:11 -08007959 @Override
Michele0ea7d782019-03-19 14:58:42 -07007960 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007961 enforceModifyPermission();
7962
7963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007966 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007967 .commit();
7968 } finally {
7969 Binder.restoreCallingIdentity(identity);
7970 }
7971 }
7972
7973 @Override
Michele0ea7d782019-03-19 14:58:42 -07007974 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007975 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007977 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7978 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007979 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007980 }
Michelecea4cf22018-12-21 15:00:11 -08007981
7982 final long identity = Binder.clearCallingIdentity();
7983 try {
Michele0ea7d782019-03-19 14:58:42 -07007984 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007985 } finally {
7986 Binder.restoreCallingIdentity(identity);
7987 }
7988 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007989
Michele0ea7d782019-03-19 14:58:42 -07007990 @TelephonyManager.IsMultiSimSupportedResult
7991 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007992 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7993 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7994 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007995 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7996 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007997 }
7998 // Check if the hardware supports multisim functionality. If usage of multisim is not
7999 // supported by the modem, indicate that it is restricted.
8000 PhoneCapability staticCapability =
8001 mPhoneConfigurationManager.getStaticPhoneCapability();
8002 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008003 loge("isMultiSimSupportedInternal: no static configuration available");
8004 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008005 }
Sarah Chin7caee492020-02-18 20:49:02 +00008006 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008007 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8008 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008009 }
8010 // Check if support of multiple SIMs is restricted by carrier
8011 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008012 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008013 }
8014
Michele0ea7d782019-03-19 14:58:42 -07008015 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008016 }
8017
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008018 /**
8019 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008020 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8021 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8022 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008023 * @param numOfSims number of active sims we want to switch to
8024 */
8025 @Override
8026 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008027 if (numOfSims == 1) {
8028 enforceModifyPermission();
8029 } else {
8030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8031 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8032 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008033 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008034
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008035 try {
Michele30b57b22019-03-01 12:01:14 -08008036 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008037 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008038 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8039 return;
8040 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008041 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
8044 }
8045 }
8046
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008047 @Override
8048 public boolean isApplicationOnUicc(int subId, int appType) {
8049 enforceReadPrivilegedPermission("isApplicationOnUicc");
8050 Phone phone = getPhone(subId);
8051 if (phone == null) {
8052 return false;
8053 }
8054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 UiccCard uiccCard = phone.getUiccCard();
8057 if (uiccCard == null) {
8058 return false;
8059 }
8060 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8061 if (uiccProfile == null) {
8062 return false;
8063 }
8064 if (TelephonyManager.APPTYPE_SIM <= appType
8065 && appType <= TelephonyManager.APPTYPE_ISIM) {
8066 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8067 }
8068 return false;
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
8071 }
8072 }
8073
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008074 /**
chen xub4baa772019-04-03 10:23:41 -07008075 * Get whether making changes to modem configurations will trigger reboot.
8076 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008077 */
8078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008079 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8080 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008082 mApp, subId, callingPackage, callingFeatureId,
8083 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008084 return false;
8085 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
8091 }
8092 }
8093
Nathan Harold29f5f052019-02-15 13:41:57 -08008094 private void updateModemStateMetrics() {
8095 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8096 // TODO: check the state for each modem if the api is ready.
8097 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8098 }
8099
Pengquan Meng3889a572019-01-23 11:16:29 -08008100 @Override
8101 public int[] getSlotsMapping() {
8102 enforceReadPrivilegedPermission("getSlotsMapping");
8103
8104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8107 // All logical slots should have a mapping to a physical slot.
8108 int[] logicalSlotsMapping = new int[phoneCount];
8109 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8110 for (int i = 0; i < slotInfos.length; i++) {
8111 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8112 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8113 }
8114 }
8115 return logicalSlotsMapping;
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
8118 }
8119 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008120
8121 /**
8122 * Get the IRadio HAL Version
8123 */
8124 @Override
8125 public int getRadioHalVersion() {
8126 Phone phone = getDefaultPhone();
8127 if (phone == null) return -1;
8128 HalVersion hv = phone.getHalVersion();
8129 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8130 return hv.major * 100 + hv.minor;
8131 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008132
8133 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008134 * Get the current calling package name.
8135 * @return the current calling package name
8136 */
8137 @Override
8138 public String getCurrentPackageName() {
8139 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8140 }
8141
8142 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008143 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8144 * corresponding network requests on a subId.
8145 *
8146 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008147 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008148 * 2) APN is un-metered for this subscription, or
8149 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008150 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008151 *
8152 * @return whether data is allowed for a apn type.
8153 *
8154 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008155 */
8156 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008157 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008158 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8159 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008160
8161 // Now that all security checks passes, perform the operation as ourselves.
8162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 Phone phone = getPhone(subId);
8165 if (phone == null) return false;
8166
Jack Yu41407ee2019-05-13 16:54:09 -07008167 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008168 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
8172 }
8173
8174 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008175 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008176 enforceReadPrivilegedPermission("isApnMetered");
8177
8178 // Now that all security checks passes, perform the operation as ourselves.
8179 final long identity = Binder.clearCallingIdentity();
8180 try {
8181 Phone phone = getPhone(subId);
8182 if (phone == null) return true; // By default return true.
8183
Jack Yu41407ee2019-05-13 16:54:09 -07008184 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
8188 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008189
8190 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008191 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8192 int subscriptionId, IBooleanConsumer resultCallback) {
8193 enforceModifyPermission();
8194 long token = Binder.clearCallingIdentity();
8195 try {
8196 Phone phone = getPhone(subscriptionId);
8197 if (phone == null) {
8198 try {
8199 if (resultCallback != null) {
8200 resultCallback.accept(false);
8201 }
8202 } catch (RemoteException e) {
8203 // ignore
8204 }
8205 return;
8206 }
8207 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8208 Pair.create(specifiers, (x) -> {
8209 try {
8210 if (resultCallback != null) {
8211 resultCallback.accept(x);
8212 }
8213 } catch (RemoteException e) {
8214 // ignore
8215 }
8216 });
8217 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8218 } finally {
8219 Binder.restoreCallingIdentity(token);
8220 }
8221 }
8222
8223 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008224 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008225 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008226 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8227 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8228 if (iccRecords == null) {
8229 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8230 return false;
8231 }
8232 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8233 }
8234
8235 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008236 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008237 if (callingPackage == null) {
8238 callingPackage = getCurrentPackageName();
8239 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008240 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8241 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8242 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8243 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8244 }
8245 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8246 Intent intent = new Intent();
8247 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8248 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8249 // Bring up choose default SMS subscription dialog right now
8250 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8251 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8252 mApp.startActivity(intent);
8253 }
chen xud5ca2d52019-05-28 15:20:57 -07008254
8255 @Override
8256 public String getMmsUAProfUrl(int subId) {
8257 //TODO investigate if this API should require proper permission check in R b/133791609
8258 final long identity = Binder.clearCallingIdentity();
8259 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008260 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8261 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
8265 }
8266
8267 @Override
8268 public String getMmsUserAgent(int subId) {
8269 //TODO investigate if this API should require proper permission check in R b/133791609
8270 final long identity = Binder.clearCallingIdentity();
8271 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008272 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8273 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008274 } finally {
8275 Binder.restoreCallingIdentity(identity);
8276 }
8277 }
Jack Yub07d4972019-05-28 16:12:25 -07008278
8279 @Override
8280 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8281 enforceModifyPermission();
8282
8283 // Now that all security checks passes, perform the operation as ourselves.
8284 final long identity = Binder.clearCallingIdentity();
8285 try {
8286 Phone phone = getPhone(subId);
8287 if (phone == null) return false;
8288
8289 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
8293 }
8294
8295 @Override
8296 public boolean isDataAllowedInVoiceCall(int subId) {
8297 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8298
8299 // Now that all security checks passes, perform the operation as ourselves.
8300 final long identity = Binder.clearCallingIdentity();
8301 try {
8302 Phone phone = getPhone(subId);
8303 if (phone == null) return false;
8304
8305 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
8308 }
8309 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008310
changbettyd5c246e2019-12-24 15:40:37 +08008311 @Override
8312 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8313 enforceModifyPermission();
8314
8315 // Now that all security checks passes, perform the operation as ourselves.
8316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 Phone phone = getPhone(subId);
8319 if (phone == null) return false;
8320
8321 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
8324 }
8325 }
8326
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008327 /**
8328 * Updates whether conference event pacakge handling is enabled.
8329 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8330 * otherwise.
8331 */
8332 @Override
8333 public void setCepEnabled(boolean isCepEnabled) {
8334 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8335
8336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8339 for (Phone phone : PhoneFactory.getPhones()) {
8340 Phone defaultPhone = phone.getImsPhone();
8341 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8342 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8343 ImsPhoneCallTracker imsPhoneCallTracker =
8344 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8345 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8346 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8347 + imsPhone.getMsisdn());
8348 }
8349 }
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
allenwtsu46dcc572020-01-08 18:24:03 +08008354
8355 /**
8356 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8357 *
8358 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8359 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8360 * before being read.
8361 */
8362 @Override
8363 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8364 isCompressed) {
8365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8366 mApp, subId, "notifyRcsAutoConfigurationReceived");
8367 try {
8368 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8369 if (configBinder == null) {
8370 Rlog.e(LOG_TAG, "null result for getImsConfig");
8371 } else {
8372 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8373 }
8374 } catch (RemoteException e) {
8375 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8376 }
8377 }
zoey chene02881a2019-12-30 16:11:23 +08008378
8379 @Override
8380 public boolean isIccLockEnabled(int subId) {
8381 enforceReadPrivilegedPermission("isIccLockEnabled");
8382
8383 // Now that all security checks passes, perform the operation as ourselves.
8384 final long identity = Binder.clearCallingIdentity();
8385 try {
8386 Phone phone = getPhone(subId);
8387 if (phone != null && phone.getIccCard() != null) {
8388 return phone.getIccCard().getIccLockEnabled();
8389 } else {
8390 return false;
8391 }
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
8395 }
8396
8397 /**
8398 * Set the ICC pin lock enabled or disabled.
8399 *
8400 * @return an integer representing the status of IccLock enabled or disabled in the following
8401 * three cases:
8402 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8403 * successfully.
8404 * - Positive number and zero for remaining password attempts.
8405 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8406 *
8407 */
8408 @Override
8409 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8410 enforceModifyPermission();
8411
8412 Phone phone = getPhone(subId);
8413 if (phone == null) {
8414 return 0;
8415 }
8416 // Now that all security checks passes, perform the operation as ourselves.
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8420 new Pair<Boolean, String>(enabled, password), phone, null);
8421 return attemptsRemaining;
8422
8423 } catch (Exception e) {
8424 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
8428 return 0;
8429 }
8430
8431 /**
8432 * Change the ICC password used in ICC pin lock.
8433 *
8434 * @return an integer representing the status of IccLock changed in the following three cases:
8435 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8436 * - Positive number and zero for remaining password attempts.
8437 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8438 *
8439 */
8440 @Override
8441 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8442 enforceModifyPermission();
8443
8444 Phone phone = getPhone(subId);
8445 if (phone == null) {
8446 return 0;
8447 }
8448 // Now that all security checks passes, perform the operation as ourselves.
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8452 new Pair<String, String>(oldPassword, newPassword), phone, null);
8453 return attemptsRemaining;
8454
8455 } catch (Exception e) {
8456 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
8460 return 0;
8461 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008462
8463 /**
8464 * Request for receiving user activity notification
8465 */
8466 @Override
8467 public void requestUserActivityNotification() {
8468 if (!mNotifyUserActivity.get()
8469 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8470 mNotifyUserActivity.set(true);
8471 }
8472 }
8473
8474 /**
8475 * Called when userActivity is signalled in the power manager.
8476 * This is safe to call from any thread, with any window manager locks held or not.
8477 */
8478 @Override
8479 public void userActivity() {
8480 // ***************************************
8481 // * Inherited from PhoneWindowManager *
8482 // ***************************************
8483 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8484 // WITH ITS LOCKS HELD.
8485 //
8486 // This code must be VERY careful about the locks
8487 // it acquires.
8488 // In fact, the current code acquires way too many,
8489 // and probably has lurking deadlocks.
8490
8491 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8492 throw new SecurityException("Only the OS may call notifyUserActivity()");
8493 }
8494
8495 if (mNotifyUserActivity.getAndSet(false)) {
8496 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8497 USER_ACTIVITY_NOTIFICATION_DELAY);
8498 }
8499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008500}